Below, you’ll find a detailed guide on how to add the PanoPress Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the PanoPress Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the PanoPress Plugin and the shortcodes it provides:
"PanoPress is a versatile WordPress plugin that enables seamless integration of 360-degree panoramas and virtual tours into your website. Enhance your user experience with immersive visuals."
- []
PanoPress [pamo] Shortcode
The Panopress shortcode is a powerful tool for embedding panoramic images or videos into your WordPress site. It uses the shortcode [pano] to handle attributes like file, width, height, alt, title, preview, panobox, and play button. The shortcode first checks and cleans the attributes, then combines them with the default settings. It then checks if the file name was set and identifies the file type. If the file or preview is not a full URL, it creates a local URL. For XML files, it parses the XML, identifies the viewer name, and handles any errors. Finally, it calls the pp_select function with the settings array. This shortcode provides a flexible way to add panoramic content to your WordPress site.
Shortcode: [pano]
Parameters
Here is a list of all possible null shortcode parameters and attributes:
f
– Specifies the file name or URL of the panorama.w
– Sets the width of the panorama display.h
– Sets the height of the panorama display.a
– Provides alternative text for the panorama.t
– Sets the title for the panorama.p
– Specifies the preview image for the panorama.b
– Enables or disables the panobox feature.n
– Controls the display of the play button.
Examples and Usage
Basic example – Displays a panorama using the short key ‘f’ for file.
[pano f="my_panorama.jpg" /]
Advanced examples
Displaying a panorama with specific width and height using short keys ‘w’ and ‘h’. The panorama will be displayed with a width of 800px and a height of 600px.
[pano f="my_panorama.jpg" w=800 h=600 /]
Displaying a panorama with an alternate text and title using short keys ‘a’ and ‘t’. If the panorama cannot be displayed, the alternate text will be shown. The title will be displayed as a tooltip when the mouse is hovered over the panorama.
[pano f="my_panorama.jpg" a="Alternate text" t="Title of the panorama" /]
Displaying a panorama with a preview image using the short key ‘p’. The preview image will be displayed while the panorama is loading.
[pano f="my_panorama.jpg" p="preview.jpg" /]
Displaying a panorama with a play button using the short key ‘n’. If set to true, a play button will be displayed over the panorama.
[pano f="my_panorama.jpg" n=true /]
Displaying a panorama within a lightbox using the short key ‘b’. If set to true, the panorama will be displayed within a lightbox when clicked.
[pano f="my_panorama.jpg" b=true /]
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'pano', 'pp_sohrtcode_handler' );
Shortcode PHP function:
function pp_sohrtcode_handler( $attributes ) {
global $pp_settings;
/* user can use short keys, eg. 'w' for 'width' etc.
only items in this array allowed to pass into settings */
$att = array(
'f' => PP_SETTINGS_FILE,
'w' => PP_SETTINGS_WIDTH,
'h' => PP_SETTINGS_HEIGHT,
'a' => PP_SETTINGS_ALT,
't' => PP_SETTINGS_TITLE,
'p' => PP_SETTINGS_PREVIEW,
'b' => PP_SETTINGS_PANOBOX,
'n' => PP_SETTINGS_PLAY_BUTTON
);
// clean attributes and use short keys
$clean = array();
foreach( $att as $key => $val ) {
if ( array_key_exists( $val, $attributes ) ) $clean[$val] = $attributes[$val]; /* test for full length key first */
elseif ( array_key_exists( $key, $attributes ) ) $clean[$val] = $attributes[$key]; /* test for short key */
}
// check play button
if ( isset( $clean[PP_SETTINGS_PLAY_BUTTON] ) ) {
$clean[PP_SETTINGS_PLAY_BUTTON] = pp_bool( $clean[PP_SETTINGS_PLAY_BUTTON] );
}
// check panobox
if ( isset( $clean[PP_SETTINGS_PANOBOX] ) ) {
$clean[PP_SETTINGS_PANOBOX_ACTIVE] = pp_bool( $clean[PP_SETTINGS_PANOBOX] );
unset( $clean[PP_SETTINGS_PANOBOX] );
}
// combine the shortcode attribute with default settings
$settings = array_merge( $pp_settings, $clean );
// check if the file name was set
if ( ! $settings[PP_SETTINGS_FILE] ) {
return pp_error( pp__( 'Please enter file name or URL' ) );
}
// set type by file ext
$filestr = strtolower( $settings[PP_SETTINGS_FILE] );
if( strstr( $filestr, '?' ) ){
$filestr = substr ($filestr, 0, strpos( $filestr, '?') );
}
$file_name = substr( $filestr, strrpos( $filestr, '/' ) );
$settings[PP_SETTINGS_TYPE] = substr ( $file_name, strrpos( $file_name, '.' ) + 1 );//substr ( $filestr, strrpos( $filestr, '.') + 1 );
// if file is not full url, craete a local url
if ( strtolower( substr( $settings[PP_SETTINGS_FILE], 0, 4 ) ) != 'http' )
$settings[PP_SETTINGS_FILE] = site_url( '/' . $pp_settings[PP_SETTINGS_UPLOAD_DIR] . '/' . $settings[PP_SETTINGS_FILE] );
// if poster is not full url, craete a local url
if ( strlen( $settings[PP_SETTINGS_PREVIEW]) > 0 && strtolower( substr( $settings[PP_SETTINGS_PREVIEW], 0, 4 ) ) != 'http' )
$settings[PP_SETTINGS_PREVIEW] = site_url( '/' . $pp_settings[PP_SETTINGS_UPLOAD_DIR] . '/' . $settings[PP_SETTINGS_PREVIEW] );
// replace spaces in url with %20
$settings[PP_SETTINGS_PREVIEW] = str_replace ( ' ' , '%20' , $settings[PP_SETTINGS_PREVIEW] );
$settings[PP_SETTINGS_FILE] = str_replace ( ' ' , '%20' , $settings[PP_SETTINGS_FILE] );
// parse xml
if ( $settings[PP_SETTINGS_TYPE] == PP_FILE_TYPE_XML ) {
$got_name = pp_get_viewr_name ( $settings[ PP_SETTINGS_FILE ] );
if ( $got_name[ 'status' ] == 1 ) {
$settings[ PP_SETTINGS_VIEWER_NAME ] = $got_name[ 'content' ];
} elseif ( is_user_logged_in() ) {
return pp_error ( $got_name[ 'content' ] );
}
// error report (admin only)
libxml_use_internal_errors( is_user_logged_in() );
// test allow_url_fopen
if( ini_get( 'allow_url_fopen' ) == 1 ){
$xml = is_user_logged_in() ? simplexml_load_file( $settings[PP_SETTINGS_FILE] ) : @ simplexml_load_file( $settings[PP_SETTINGS_FILE] );
}
// try curl
else if ( function_exists('curl_init') ) {
//1.1
$results = pp_get_url( $settings[PP_SETTINGS_FILE] );
if ( $results['status'] == 200 ) {
$xml = simplexml_load_string( $results['content'] );
} elseif ( is_user_logged_in() ) {
return pp_error ( pp__( 'Can\'t find XML file' ) . ' ' . $settings[PP_SETTINGS_FILE] );
}
}
// TODO: ask input from user (admin only)
elseif ( is_user_logged_in() ) {
return pp_error( '<p>' . pp__( '"allow_url_fopen" option is not enabled in the php.ini file on this server & cURL is not installed.' ) . '.</p>');
}
// xml errors (admin only)
if ( $xml === false && is_user_logged_in() ) {
$err = '';
foreach( libxml_get_errors() as $error )
$err .= $error->message . '(line ' . $error->line . ' in ' . $error->file . ')<br />';
return pp_error( '<p>' . $err . '</p>' );
}
elseif ( $xml ) {
if ( $xml -> getName() == 'krpano' )
$settings[PP_SETTINGS_VIEWER_NAME] = PP_VIEWER_NAME_KRPANO; // krpano xml
elseif ( $xml -> getName() == 'panorama' ) {
$settings[PP_SETTINGS_VIEWER_NAME] = PP_VIEWER_NAME_PANO2VR; // pano2vr xml
foreach ( $xml -> children() as $second )
if ( $second-> getName() == 'parameters' )
$settings[PP_SETTINGS_VIEWER_NAME] = PP_VIEWER_NAME_FPP; // fpp xml
}
}
else
return $settings[PP_SETTINGS_ALT];
}
// call select with settings array
return pp_select( $settings );
}
Code file location:
panopress/panopress/panopress.php
Conclusion
Now that you’ve learned how to embed the PanoPress Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply