Changeset 37040 for trunk/src/wp-includes/class-wp-customize-widgets.php
- Timestamp:
- 03/21/2016 09:58:02 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-widgets.php
r36842 r37040 63 63 64 64 /** 65 * Mapping of widget ID base to whether it supports selective refresh. 66 * 67 * @since 4.5.0 68 * @access protected 69 * @var array 70 */ 71 protected $selective_refreshable_widgets; 72 73 /** 65 74 * Mapping of setting type to setting ID pattern. 66 75 * … … 70 79 */ 71 80 protected $setting_id_patterns = array( 72 'widget_instance' => '/^ (widget_.+?)(?:\[(\d+)\])?$/',73 'sidebar_widgets' => '/^sidebars_widgets\[( .+?)\]$/',81 'widget_instance' => '/^widget_(?P<id_base>.+?)(?:\[(?P<widget_number>\d+)\])?$/', 82 'sidebar_widgets' => '/^sidebars_widgets\[(?P<sidebar_id>.+?)\]$/', 74 83 ); 75 84 … … 113 122 114 123 /** 124 * List whether each registered widget can be use selective refresh. 125 * 126 * If the theme does not support the customize-selective-refresh-widgets feature, 127 * then this will always return an empty array. 128 * 129 * @since 4.5.0 130 * @access public 131 * 132 * @return array Mapping of id_base to support. If theme doesn't support 133 * selective refresh, an empty array is returned. 134 */ 135 public function get_selective_refreshable_widgets() { 136 global $wp_widget_factory; 137 if ( ! current_theme_supports( 'customize-selective-refresh-widgets' ) ) { 138 return array(); 139 } 140 if ( ! isset( $this->selective_refreshable_widgets ) ) { 141 $this->selective_refreshable_widgets = array(); 142 foreach ( $wp_widget_factory->widgets as $wp_widget ) { 143 $this->selective_refreshable_widgets[ $wp_widget->id_base ] = ! empty( $wp_widget->widget_options['customize_selective_refresh'] ); 144 } 145 } 146 return $this->selective_refreshable_widgets; 147 } 148 149 /** 150 * Determines if a widget supports selective refresh. 151 * 152 * @since 4.5.0 153 * @access public 154 * 155 * @param string $id_base Widget ID Base. 156 * @return bool Whether the widget can be selective refreshed. 157 */ 158 public function is_widget_selective_refreshable( $id_base ) { 159 $selective_refreshable_widgets = $this->get_selective_refreshable_widgets(); 160 return ! empty( $selective_refreshable_widgets[ $id_base ] ); 161 } 162 163 /** 115 164 * Retrieves the widget setting type given a setting ID. 116 165 * … … 120 169 * @staticvar array $cache 121 170 * 122 * @param $setting_id Setting ID.171 * @param string $setting_id Setting ID. 123 172 * @return string|void Setting type. 124 173 */ … … 691 740 'moveWidgetArea' => $move_widget_area_tpl, 692 741 ), 693 'selectiveRefresh ' => isset( $this->manager->selective_refresh),742 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), 694 743 ); 695 744 … … 772 821 'type' => 'option', 773 822 'capability' => 'edit_theme_options', 774 'transport' => isset( $this->manager->selective_refresh ) ? 'postMessage' : 'refresh',775 823 'default' => array(), 776 824 ); … … 779 827 $args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' ); 780 828 $args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' ); 829 $args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh'; 781 830 } elseif ( preg_match( $this->setting_id_patterns['widget_instance'], $id, $matches ) ) { 782 831 $args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' ); 783 832 $args['sanitize_js_callback'] = array( $this, 'sanitize_widget_js_instance' ); 833 $args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh'; 784 834 } 785 835 … … 894 944 'is_disabled' => $is_disabled, 895 945 'id_base' => $id_base, 896 'transport' => isset( $this->manager->selective_refresh) ? 'postMessage' : 'refresh',946 'transport' => $this->is_widget_selective_refreshable( $id_base ) ? 'postMessage' : 'refresh', 897 947 'width' => $wp_registered_widget_controls[$widget['id']]['width'], 898 948 'height' => $wp_registered_widget_controls[$widget['id']]['height'], … … 1026 1076 public function customize_preview_enqueue() { 1027 1077 wp_enqueue_script( 'customize-preview-widgets' ); 1078 wp_enqueue_style( 'customize-preview' ); 1028 1079 } 1029 1080 … … 1061 1112 public function export_preview_data() { 1062 1113 global $wp_registered_sidebars, $wp_registered_widgets; 1114 1063 1115 // Prepare Customizer settings to pass to JavaScript. 1064 1116 $settings = array( … … 1070 1122 'widgetTooltip' => __( 'Shift-click to edit this widget.' ), 1071 1123 ), 1072 'selectiveRefresh ' => isset( $this->manager->selective_refresh),1124 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), 1073 1125 ); 1074 1126 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { … … 1480 1532 */ 1481 1533 public function customize_dynamic_partial_args( $partial_args, $partial_id ) { 1534 if ( ! current_theme_supports( 'customize-selective-refresh-widgets' ) ) { 1535 return $partial_args; 1536 } 1482 1537 1483 1538 if ( preg_match( '/^widget\[(?P<widget_id>.+)\]$/', $partial_id, $matches ) ) { … … 1507 1562 */ 1508 1563 public function selective_refresh_init() { 1509 if ( ! isset( $this->manager->selective_refresh) ) {1564 if ( ! current_theme_supports( 'customize-selective-refresh-widgets' ) ) { 1510 1565 return; 1511 1566 } 1512 1513 add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue_deps' ) );1514 1567 add_filter( 'dynamic_sidebar_params', array( $this, 'filter_dynamic_sidebar_params' ) ); 1515 1568 add_filter( 'wp_kses_allowed_html', array( $this, 'filter_wp_kses_allowed_data_attributes' ) ); 1516 1569 add_action( 'dynamic_sidebar_before', array( $this, 'start_dynamic_sidebar' ) ); 1517 1570 add_action( 'dynamic_sidebar_after', array( $this, 'end_dynamic_sidebar' ) ); 1518 }1519 1520 /**1521 * Enqueues scripts for the Customizer preview.1522 *1523 * @since 4.5.01524 * @access public1525 */1526 public function customize_preview_enqueue_deps() {1527 if ( isset( $this->manager->selective_refresh ) ) {1528 $script = wp_scripts()->registered['customize-preview-widgets'];1529 $script->deps[] = 'customize-selective-refresh';1530 }1531 1532 wp_enqueue_script( 'customize-preview-widgets' );1533 wp_enqueue_style( 'customize-preview' );1534 1571 } 1535 1572
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)