Changeset 27653 for trunk/src/wp-includes/class-wp-customize-widgets.php
- Timestamp:
- 03/22/2014 09:03:18 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-widgets.php
r27652 r27653 697 697 static function customize_preview_init() { 698 698 add_filter( 'sidebars_widgets', array( __CLASS__, 'preview_sidebars_widgets' ), 1 ); 699 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue_deps' ) ); 700 add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 9999 ); 699 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue' ) ); 700 add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 ); 701 add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 20 ); 701 702 } 702 703 … … 720 721 * @action wp_enqueue_scripts 721 722 */ 722 static function customize_preview_enqueue _deps() {723 static function customize_preview_enqueue() { 723 724 wp_enqueue_script( 'customize-preview-widgets' ); 724 725 add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 ); 726 727 // Why not wp_localize_script? Because we're not localizing, and it forces values into strings 728 global $wp_scripts; 729 $exports = array( 730 'registered_sidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ), 731 'registered_widgets' => $GLOBALS['wp_registered_widgets'], 732 'i18n' => array( 733 'widget_tooltip' => ( 'Shift-click to edit this widget.' ), 734 ), 735 ); 736 foreach ( $exports['registered_widgets'] as &$registered_widget ) { 737 unset( $registered_widget['callback'] ); // may not be JSON-serializeable 738 } 739 $wp_scripts->add_data( 740 'customize-preview-widgets', 741 'data', 742 sprintf( 'var WidgetCustomizerPreview_exports = %s;', json_encode( $exports ) ) 743 ); 744 } 725 } 745 726 746 727 /** … … 768 749 */ 769 750 static function export_preview_data() { 770 wp_print_scripts( array( 'customize-preview-widgets' ) ); 751 // Prepare customizer settings to pass to Javascript. 752 $settings = array( 753 'renderedSidebars' => array_fill_keys( array_unique( self::$rendered_sidebars ), true ), 754 'renderedWidgets' => array_fill_keys( array_keys( self::$rendered_widgets ), true ), 755 'registeredSidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ), 756 'registeredWidgets' => $GLOBALS['wp_registered_widgets'], 757 'l10n' => array( 758 'widgetTooltip' => ( 'Shift-click to edit this widget.' ), 759 ), 760 ); 761 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { 762 unset( $registered_widget['callback'] ); // may not be JSON-serializeable 763 } 764 771 765 ?> 772 <script> 773 (function () { 774 /*global WidgetCustomizerPreview */ 775 WidgetCustomizerPreview.rendered_sidebars = <?php echo json_encode( array_fill_keys( array_unique( self::$rendered_sidebars ), true ) ) ?>; 776 WidgetCustomizerPreview.rendered_widgets = <?php echo json_encode( array_fill_keys( array_keys( self::$rendered_widgets ), true ) ); ?>; 777 }()); 766 <script type="text/javascript"> 767 var _wpWidgetCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>; 778 768 </script> 779 769 <?php
Note: See TracChangeset
for help on using the changeset viewer.