/** * Action for displaying the widget preview. */ function siteorigin_widget_preview_widget_action() { if (empty($_POST['class'])) { exit; } if (empty($_REQUEST['_widgets_nonce']) || !wp_verify_nonce($_REQUEST['_widgets_nonce'], 'widgets_action')) { return; } // Get the widget from the widget factory global $wp_widget_factory; $widget = !empty($wp_widget_factory->widgets[$_POST['class']]) ? $wp_widget_factory->widgets[$_POST['class']] : false; if (!is_a($widget, 'SiteOrigin_Widget')) { exit; } $instance = json_decode(stripslashes_deep($_POST['data']), true); /* @var $widget SiteOrigin_Widget */ $instance = $widget->update($instance, $instance); $instance['is_preview'] = true; // The theme stylesheet will change how the button looks wp_enqueue_style('theme-css', get_stylesheet_uri(), array(), rand(0, 65536)); wp_enqueue_style('so-widget-preview', plugin_dir_url(__FILE__) . '../css/preview.css', array(), rand(0, 65536)); ob_start(); $widget->widget(array('before_widget' => '', 'after_widget' => '', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'), $instance); $widget_html = ob_get_clean(); // Print all the scripts and styles ?> <html> <head> <title><?php _e('Widget Preview', 'so-widgets-bundle'); ?> </title> <?php wp_print_scripts(); wp_print_styles(); siteorigin_widget_print_styles(); ?> </head> <body> <?php // A lot of themes use entry-content as their main content wrapper ?> <div class="entry-content"> <?php echo $widget_html; ?> </div> </body> </html> <?php exit; }
function siteorigin_widget_preview_widget_action() { if (!class_exists($_POST['class'])) { exit; } $widget = new $_POST['class'](); if (!is_a($widget, 'SiteOrigin_Widget')) { exit; } $instance = json_decode(stripslashes_deep($_POST['data']), true); $instance['is_preview'] = true; // The theme stylesheet will change how the button looks wp_enqueue_style('theme-css', get_stylesheet_uri(), array(), rand(0, 65536)); wp_enqueue_style('so-widget-preview', plugin_dir_url(__FILE__) . '/css/preview.css', array(), rand(0, 65536)); $widget->widget(array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''), $instance); // Print all the scripts and styles wp_print_scripts(); wp_print_styles(); siteorigin_widget_print_styles(); ?> <script type="text/javascript"> if( typeof jQuery != 'undefined' ) { // So that the widget still has access to the document ready event. jQuery(document).ready(); } </script> <?php exit; }
<html> <head> <title><?php _e('Widget Preview'); ?> </title> <meta id="Viewport" name="viewport" width="width=960, initial-scale=0.25"> </head> <body> <?php the_widget($class, $instance, array('before_widget' => '<div class="widget-preview-wrapper">', 'after_widget' => '</div>')); siteorigin_widget_print_styles(); ?> </body> </html>
/** * Action for displaying the widget preview. */ function siteorigin_widget_preview_widget_action() { if (!class_exists($_POST['class'])) { exit; } $widget = new $_POST['class'](); if (!is_a($widget, 'SiteOrigin_Widget')) { exit; } $instance = json_decode(stripslashes_deep($_POST['data']), true); $instance = $widget->sanitize($instance); $instance['is_preview'] = true; // The theme stylesheet will change how the button looks wp_enqueue_style('theme-css', get_stylesheet_uri(), array(), rand(0, 65536)); wp_enqueue_style('so-widget-preview', plugin_dir_url(__FILE__) . '/css/preview.css', array(), rand(0, 65536)); ob_start(); $widget->widget(array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''), $instance); $widget_html = ob_get_clean(); // Print all the scripts and styles ?> <html> <head> <title><?php _e('Widget Preview', 'siteorigin-widgets'); ?> </title> <?php wp_print_scripts(); wp_print_styles(); siteorigin_widget_print_styles(); ?> </head> <body> <?php // A lot of themes use entry-content as their main content wrapper ?> <div class="entry-content"> <?php echo $widget_html; ?> </div> </body> </html> <?php exit; }