Update WP and plugins
This commit is contained in:
parent
10a4713229
commit
1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions
|
@ -100,32 +100,32 @@ final class WP_Customize_Widgets {
|
|||
$this->manager = $manager;
|
||||
|
||||
// See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L420-L449
|
||||
add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 );
|
||||
add_action( 'widgets_init', array( $this, 'register_settings' ), 95 );
|
||||
add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 );
|
||||
add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 );
|
||||
add_action( 'widgets_init', array( $this, 'register_settings' ), 95 );
|
||||
add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 );
|
||||
|
||||
// Skip remaining hooks when the user can't manage widgets anyway.
|
||||
if ( ! current_user_can( 'edit_theme_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) );
|
||||
add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) );
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( 'customize_controls_print_styles', array( $this, 'print_styles' ) );
|
||||
add_action( 'customize_controls_print_scripts', array( $this, 'print_scripts' ) );
|
||||
add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) );
|
||||
add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) );
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( 'customize_controls_print_styles', array( $this, 'print_styles' ) );
|
||||
add_action( 'customize_controls_print_scripts', array( $this, 'print_scripts' ) );
|
||||
add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_footer_scripts' ) );
|
||||
add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) );
|
||||
add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
|
||||
add_filter( 'customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
|
||||
add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
|
||||
add_filter( 'customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
|
||||
|
||||
add_action( 'dynamic_sidebar', array( $this, 'tally_rendered_widgets' ) );
|
||||
add_filter( 'is_active_sidebar', array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
|
||||
add_filter( 'dynamic_sidebar_has_widgets', array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 );
|
||||
add_action( 'dynamic_sidebar', array( $this, 'tally_rendered_widgets' ) );
|
||||
add_filter( 'is_active_sidebar', array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
|
||||
add_filter( 'dynamic_sidebar_has_widgets', array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 );
|
||||
|
||||
// Selective Refresh.
|
||||
add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 );
|
||||
add_action( 'customize_preview_init', array( $this, 'selective_refresh_init' ) );
|
||||
add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 );
|
||||
add_action( 'customize_preview_init', array( $this, 'selective_refresh_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ final class WP_Customize_Widgets {
|
|||
* @since 4.2.0
|
||||
*/
|
||||
public function register_settings() {
|
||||
$widget_setting_ids = array();
|
||||
$widget_setting_ids = array();
|
||||
$incoming_setting_ids = array_keys( $this->manager->unsanitized_post_values() );
|
||||
foreach ( $incoming_setting_ids as $setting_id ) {
|
||||
if ( ! is_null( $this->get_setting_type( $setting_id ) ) ) {
|
||||
|
@ -319,7 +319,7 @@ final class WP_Customize_Widgets {
|
|||
* @return array
|
||||
*/
|
||||
public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) {
|
||||
$sidebars_widgets = $GLOBALS['sidebars_widgets'];
|
||||
$sidebars_widgets = $GLOBALS['sidebars_widgets'];
|
||||
$sidebars_widgets['array_version'] = 3;
|
||||
return $sidebars_widgets;
|
||||
}
|
||||
|
@ -399,22 +399,28 @@ final class WP_Customize_Widgets {
|
|||
* theme_mod when the theme is switched.
|
||||
*/
|
||||
if ( ! $this->manager->is_theme_active() ) {
|
||||
$setting_id = 'old_sidebars_widgets_data';
|
||||
$setting_args = $this->get_setting_args( $setting_id, array(
|
||||
'type' => 'global_variable',
|
||||
'dirty' => true,
|
||||
) );
|
||||
$setting_id = 'old_sidebars_widgets_data';
|
||||
$setting_args = $this->get_setting_args(
|
||||
$setting_id,
|
||||
array(
|
||||
'type' => 'global_variable',
|
||||
'dirty' => true,
|
||||
)
|
||||
);
|
||||
$this->manager->add_setting( $setting_id, $setting_args );
|
||||
}
|
||||
|
||||
$this->manager->add_panel( 'widgets', array(
|
||||
'type' => 'widgets',
|
||||
'title' => __( 'Widgets' ),
|
||||
'description' => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ),
|
||||
'priority' => 110,
|
||||
'active_callback' => array( $this, 'is_panel_active' ),
|
||||
'auto_expand_sole_section' => true,
|
||||
) );
|
||||
$this->manager->add_panel(
|
||||
'widgets',
|
||||
array(
|
||||
'type' => 'widgets',
|
||||
'title' => __( 'Widgets' ),
|
||||
'description' => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ),
|
||||
'priority' => 110,
|
||||
'active_callback' => array( $this, 'is_panel_active' ),
|
||||
'auto_expand_sole_section' => true,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) {
|
||||
if ( empty( $sidebar_widget_ids ) ) {
|
||||
|
@ -442,11 +448,11 @@ final class WP_Customize_Widgets {
|
|||
if ( $is_active_sidebar ) {
|
||||
|
||||
$section_args = array(
|
||||
'title' => $wp_registered_sidebars[ $sidebar_id ]['name'],
|
||||
'title' => $wp_registered_sidebars[ $sidebar_id ]['name'],
|
||||
'description' => $wp_registered_sidebars[ $sidebar_id ]['description'],
|
||||
'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
|
||||
'panel' => 'widgets',
|
||||
'sidebar_id' => $sidebar_id,
|
||||
'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
|
||||
'panel' => 'widgets',
|
||||
'sidebar_id' => $sidebar_id,
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -463,11 +469,15 @@ final class WP_Customize_Widgets {
|
|||
$section = new WP_Customize_Sidebar_Section( $this->manager, $section_id, $section_args );
|
||||
$this->manager->add_section( $section );
|
||||
|
||||
$control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array(
|
||||
'section' => $section_id,
|
||||
'sidebar_id' => $sidebar_id,
|
||||
'priority' => count( $sidebar_widget_ids ), // place 'Add Widget' and 'Reorder' buttons at end.
|
||||
) );
|
||||
$control = new WP_Widget_Area_Customize_Control(
|
||||
$this->manager,
|
||||
$setting_id,
|
||||
array(
|
||||
'section' => $section_id,
|
||||
'sidebar_id' => $sidebar_id,
|
||||
'priority' => count( $sidebar_widget_ids ), // place 'Add Widget' and 'Reorder' buttons at end.
|
||||
)
|
||||
);
|
||||
$new_setting_ids[] = $setting_id;
|
||||
|
||||
$this->manager->add_control( $control );
|
||||
|
@ -478,25 +488,29 @@ final class WP_Customize_Widgets {
|
|||
foreach ( $sidebar_widget_ids as $i => $widget_id ) {
|
||||
|
||||
// Skip widgets that may have gone away due to a plugin being deactivated.
|
||||
if ( ! $is_active_sidebar || ! isset( $wp_registered_widgets[$widget_id] ) ) {
|
||||
if ( ! $is_active_sidebar || ! isset( $wp_registered_widgets[ $widget_id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$registered_widget = $wp_registered_widgets[$widget_id];
|
||||
$registered_widget = $wp_registered_widgets[ $widget_id ];
|
||||
$setting_id = $this->get_setting_id( $widget_id );
|
||||
$id_base = $wp_registered_widget_controls[$widget_id]['id_base'];
|
||||
$id_base = $wp_registered_widget_controls[ $widget_id ]['id_base'];
|
||||
|
||||
$control = new WP_Widget_Form_Customize_Control( $this->manager, $setting_id, array(
|
||||
'label' => $registered_widget['name'],
|
||||
'section' => $section_id,
|
||||
'sidebar_id' => $sidebar_id,
|
||||
'widget_id' => $widget_id,
|
||||
'widget_id_base' => $id_base,
|
||||
'priority' => $i,
|
||||
'width' => $wp_registered_widget_controls[$widget_id]['width'],
|
||||
'height' => $wp_registered_widget_controls[$widget_id]['height'],
|
||||
'is_wide' => $this->is_wide_widget( $widget_id ),
|
||||
) );
|
||||
$control = new WP_Widget_Form_Customize_Control(
|
||||
$this->manager,
|
||||
$setting_id,
|
||||
array(
|
||||
'label' => $registered_widget['name'],
|
||||
'section' => $section_id,
|
||||
'sidebar_id' => $sidebar_id,
|
||||
'widget_id' => $widget_id,
|
||||
'widget_id_base' => $id_base,
|
||||
'priority' => $i,
|
||||
'width' => $wp_registered_widget_controls[ $widget_id ]['width'],
|
||||
'height' => $wp_registered_widget_controls[ $widget_id ]['height'],
|
||||
'is_wide' => $this->is_wide_widget( $widget_id ),
|
||||
)
|
||||
);
|
||||
$this->manager->add_control( $control );
|
||||
}
|
||||
}
|
||||
|
@ -562,7 +576,7 @@ final class WP_Customize_Widgets {
|
|||
global $wp_registered_widget_controls;
|
||||
|
||||
$parsed_widget_id = $this->parse_widget_id( $widget_id );
|
||||
$width = $wp_registered_widget_controls[$widget_id]['width'];
|
||||
$width = $wp_registered_widget_controls[ $widget_id ]['width'];
|
||||
$is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases );
|
||||
$is_wide = ( $width > 250 && ! $is_core );
|
||||
|
||||
|
@ -587,7 +601,7 @@ final class WP_Customize_Widgets {
|
|||
*/
|
||||
public function parse_widget_id( $widget_id ) {
|
||||
$parsed = array(
|
||||
'number' => null,
|
||||
'number' => null,
|
||||
'id_base' => null,
|
||||
);
|
||||
|
||||
|
@ -708,46 +722,58 @@ final class WP_Customize_Widgets {
|
|||
* Gather all strings in PHP that may be needed by JS on the client.
|
||||
* Once JS i18n is implemented (in #20491), this can be removed.
|
||||
*/
|
||||
$some_non_rendered_areas_messages = array();
|
||||
$some_non_rendered_areas_messages = array();
|
||||
$some_non_rendered_areas_messages[1] = html_entity_decode(
|
||||
__( 'Your theme has 1 other widget area, but this particular page doesn’t display it.' ),
|
||||
ENT_QUOTES,
|
||||
get_bloginfo( 'charset' )
|
||||
);
|
||||
$registered_sidebar_count = count( $wp_registered_sidebars );
|
||||
$registered_sidebar_count = count( $wp_registered_sidebars );
|
||||
for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) {
|
||||
$some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode( sprintf(
|
||||
/* translators: %s: the number of other widget areas registered but not rendered */
|
||||
_n(
|
||||
'Your theme has %s other widget area, but this particular page doesn’t display it.',
|
||||
'Your theme has %s other widget areas, but this particular page doesn’t display them.',
|
||||
$non_rendered_count
|
||||
$some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode(
|
||||
sprintf(
|
||||
/* translators: %s: the number of other widget areas registered but not rendered */
|
||||
_n(
|
||||
'Your theme has %s other widget area, but this particular page doesn’t display it.',
|
||||
'Your theme has %s other widget areas, but this particular page doesn’t display them.',
|
||||
$non_rendered_count
|
||||
),
|
||||
number_format_i18n( $non_rendered_count )
|
||||
),
|
||||
number_format_i18n( $non_rendered_count )
|
||||
), ENT_QUOTES, get_bloginfo( 'charset' ) );
|
||||
ENT_QUOTES,
|
||||
get_bloginfo( 'charset' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 1 === $registered_sidebar_count ) {
|
||||
$no_areas_shown_message = html_entity_decode( sprintf(
|
||||
__( 'Your theme has 1 widget area, but this particular page doesn’t display it.' )
|
||||
), ENT_QUOTES, get_bloginfo( 'charset' ) );
|
||||
} else {
|
||||
$no_areas_shown_message = html_entity_decode( sprintf(
|
||||
/* translators: %s: the total number of widget areas registered */
|
||||
_n(
|
||||
'Your theme has %s widget area, but this particular page doesn’t display it.',
|
||||
'Your theme has %s widget areas, but this particular page doesn’t display them.',
|
||||
$registered_sidebar_count
|
||||
$no_areas_shown_message = html_entity_decode(
|
||||
sprintf(
|
||||
__( 'Your theme has 1 widget area, but this particular page doesn’t display it.' )
|
||||
),
|
||||
number_format_i18n( $registered_sidebar_count )
|
||||
), ENT_QUOTES, get_bloginfo( 'charset' ) );
|
||||
ENT_QUOTES,
|
||||
get_bloginfo( 'charset' )
|
||||
);
|
||||
} else {
|
||||
$no_areas_shown_message = html_entity_decode(
|
||||
sprintf(
|
||||
/* translators: %s: the total number of widget areas registered */
|
||||
_n(
|
||||
'Your theme has %s widget area, but this particular page doesn’t display it.',
|
||||
'Your theme has %s widget areas, but this particular page doesn’t display them.',
|
||||
$registered_sidebar_count
|
||||
),
|
||||
number_format_i18n( $registered_sidebar_count )
|
||||
),
|
||||
ENT_QUOTES,
|
||||
get_bloginfo( 'charset' )
|
||||
);
|
||||
}
|
||||
|
||||
$settings = array(
|
||||
'registeredSidebars' => array_values( $wp_registered_sidebars ),
|
||||
'registeredWidgets' => $wp_registered_widgets,
|
||||
'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets
|
||||
'l10n' => array(
|
||||
'registeredSidebars' => array_values( $wp_registered_sidebars ),
|
||||
'registeredWidgets' => $wp_registered_widgets,
|
||||
'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets
|
||||
'l10n' => array(
|
||||
'saveBtnLabel' => __( 'Apply' ),
|
||||
'saveBtnTooltip' => __( 'Save and preview changes before publishing them.' ),
|
||||
'removeBtnLabel' => __( 'Remove' ),
|
||||
|
@ -765,7 +791,7 @@ final class WP_Customize_Widgets {
|
|||
'widgetsFound' => __( 'Number of widgets found: %d' ),
|
||||
'noWidgetsFound' => __( 'No widgets found.' ),
|
||||
),
|
||||
'tpl' => array(
|
||||
'tpl' => array(
|
||||
'widgetReorderNav' => $widget_reorder_nav_tpl,
|
||||
'moveWidgetArea' => $move_widget_area_tpl,
|
||||
),
|
||||
|
@ -797,23 +823,25 @@ final class WP_Customize_Widgets {
|
|||
<span class="screen-reader-text"><?php _e( 'Back' ); ?></span>
|
||||
</button>
|
||||
<h3>
|
||||
<span class="customize-action"><?php
|
||||
<span class="customize-action">
|
||||
<?php
|
||||
/* translators: ▸ is the unicode right-pointing triangle, and %s is the section title in the Customizer */
|
||||
echo sprintf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( 'widgets' )->title ) );
|
||||
?></span>
|
||||
?>
|
||||
</span>
|
||||
<?php _e( 'Add a Widget' ); ?>
|
||||
</h3>
|
||||
</div>
|
||||
<div id="available-widgets-filter">
|
||||
<label class="screen-reader-text" for="widgets-search"><?php _e( 'Search Widgets' ); ?></label>
|
||||
<input type="text" id="widgets-search" placeholder="<?php esc_attr_e( 'Search widgets…' ) ?>" aria-describedby="widgets-search-desc" />
|
||||
<input type="text" id="widgets-search" placeholder="<?php esc_attr_e( 'Search widgets…' ); ?>" aria-describedby="widgets-search-desc" />
|
||||
<div class="search-icon" aria-hidden="true"></div>
|
||||
<button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button>
|
||||
<p class="screen-reader-text" id="widgets-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p>
|
||||
</div>
|
||||
<div id="available-widgets-list">
|
||||
<?php foreach ( $this->get_available_widgets() as $available_widget ): ?>
|
||||
<div id="widget-tpl-<?php echo esc_attr( $available_widget['id'] ) ?>" data-widget-id="<?php echo esc_attr( $available_widget['id'] ) ?>" class="widget-tpl <?php echo esc_attr( $available_widget['id'] ) ?>" tabindex="0">
|
||||
<?php foreach ( $this->get_available_widgets() as $available_widget ) : ?>
|
||||
<div id="widget-tpl-<?php echo esc_attr( $available_widget['id'] ); ?>" data-widget-id="<?php echo esc_attr( $available_widget['id'] ); ?>" class="widget-tpl <?php echo esc_attr( $available_widget['id'] ); ?>" tabindex="0">
|
||||
<?php echo $available_widget['control_tpl']; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
@ -858,13 +886,13 @@ final class WP_Customize_Widgets {
|
|||
);
|
||||
|
||||
if ( preg_match( $this->setting_id_patterns['sidebar_widgets'], $id, $matches ) ) {
|
||||
$args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' );
|
||||
$args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' );
|
||||
$args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' );
|
||||
$args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh';
|
||||
$args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh';
|
||||
} elseif ( preg_match( $this->setting_id_patterns['widget_instance'], $id, $matches ) ) {
|
||||
$args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' );
|
||||
$args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' );
|
||||
$args['sanitize_js_callback'] = array( $this, 'sanitize_widget_js_instance' );
|
||||
$args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh';
|
||||
$args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh';
|
||||
}
|
||||
|
||||
$args = array_merge( $args, $overrides );
|
||||
|
@ -889,11 +917,11 @@ final class WP_Customize_Widgets {
|
|||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param array $widget_ids Array of widget IDs.
|
||||
* @return array Array of sanitized widget IDs.
|
||||
* @param string[] $widget_ids Array of widget IDs.
|
||||
* @return string[] Array of sanitized widget IDs.
|
||||
*/
|
||||
public function sanitize_sidebar_widgets( $widget_ids ) {
|
||||
$widget_ids = array_map( 'strval', (array) $widget_ids );
|
||||
$widget_ids = array_map( 'strval', (array) $widget_ids );
|
||||
$sanitized_widget_ids = array();
|
||||
foreach ( $widget_ids as $widget_id ) {
|
||||
$sanitized_widget_ids[] = preg_replace( '/[^a-z0-9_\-]/', '', $widget_id );
|
||||
|
@ -949,9 +977,9 @@ final class WP_Customize_Widgets {
|
|||
);
|
||||
|
||||
$is_disabled = false;
|
||||
$is_multi_widget = ( isset( $wp_registered_widget_controls[$widget['id']]['id_base'] ) && isset( $widget['params'][0]['number'] ) );
|
||||
$is_multi_widget = ( isset( $wp_registered_widget_controls[ $widget['id'] ]['id_base'] ) && isset( $widget['params'][0]['number'] ) );
|
||||
if ( $is_multi_widget ) {
|
||||
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
||||
$id_base = $wp_registered_widget_controls[ $widget['id'] ]['id_base'];
|
||||
$args['_temp_id'] = "$id_base-__i__";
|
||||
$args['_multi_num'] = next_widget_id_number( $id_base );
|
||||
$args['_add'] = 'multi';
|
||||
|
@ -964,22 +992,30 @@ final class WP_Customize_Widgets {
|
|||
$id_base = $widget['id'];
|
||||
}
|
||||
|
||||
$list_widget_controls_args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
||||
$control_tpl = $this->get_widget_control( $list_widget_controls_args );
|
||||
$list_widget_controls_args = wp_list_widget_controls_dynamic_sidebar(
|
||||
array(
|
||||
0 => $args,
|
||||
1 => $widget['params'][0],
|
||||
)
|
||||
);
|
||||
$control_tpl = $this->get_widget_control( $list_widget_controls_args );
|
||||
|
||||
// The properties here are mapped to the Backbone Widget model.
|
||||
$available_widget = array_merge( $available_widget, array(
|
||||
'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null,
|
||||
'is_multi' => $is_multi_widget,
|
||||
'control_tpl' => $control_tpl,
|
||||
'multi_number' => ( $args['_add'] === 'multi' ) ? $args['_multi_num'] : false,
|
||||
'is_disabled' => $is_disabled,
|
||||
'id_base' => $id_base,
|
||||
'transport' => $this->is_widget_selective_refreshable( $id_base ) ? 'postMessage' : 'refresh',
|
||||
'width' => $wp_registered_widget_controls[$widget['id']]['width'],
|
||||
'height' => $wp_registered_widget_controls[$widget['id']]['height'],
|
||||
'is_wide' => $this->is_wide_widget( $widget['id'] ),
|
||||
) );
|
||||
$available_widget = array_merge(
|
||||
$available_widget,
|
||||
array(
|
||||
'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null,
|
||||
'is_multi' => $is_multi_widget,
|
||||
'control_tpl' => $control_tpl,
|
||||
'multi_number' => ( $args['_add'] === 'multi' ) ? $args['_multi_num'] : false,
|
||||
'is_disabled' => $is_disabled,
|
||||
'id_base' => $id_base,
|
||||
'transport' => $this->is_widget_selective_refreshable( $id_base ) ? 'postMessage' : 'refresh',
|
||||
'width' => $wp_registered_widget_controls[ $widget['id'] ]['width'],
|
||||
'height' => $wp_registered_widget_controls[ $widget['id'] ]['height'],
|
||||
'is_wide' => $this->is_wide_widget( $widget['id'] ),
|
||||
)
|
||||
);
|
||||
|
||||
$available_widgets[] = $available_widget;
|
||||
}
|
||||
|
@ -1009,10 +1045,10 @@ final class WP_Customize_Widgets {
|
|||
* @return string Widget control form HTML markup.
|
||||
*/
|
||||
public function get_widget_control( $args ) {
|
||||
$args[0]['before_form'] = '<div class="form">';
|
||||
$args[0]['after_form'] = '</div><!-- .form -->';
|
||||
$args[0]['before_form'] = '<div class="form">';
|
||||
$args[0]['after_form'] = '</div><!-- .form -->';
|
||||
$args[0]['before_widget_content'] = '<div class="widget-content">';
|
||||
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
|
||||
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
|
||||
ob_start();
|
||||
call_user_func_array( 'wp_widget_control', $args );
|
||||
$control_tpl = ob_get_clean();
|
||||
|
@ -1032,19 +1068,21 @@ final class WP_Customize_Widgets {
|
|||
*/
|
||||
public function get_widget_control_parts( $args ) {
|
||||
$args[0]['before_widget_content'] = '<div class="widget-content">';
|
||||
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
|
||||
$control_markup = $this->get_widget_control( $args );
|
||||
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
|
||||
$control_markup = $this->get_widget_control( $args );
|
||||
|
||||
$content_start_pos = strpos( $control_markup, $args[0]['before_widget_content'] );
|
||||
$content_end_pos = strrpos( $control_markup, $args[0]['after_widget_content'] );
|
||||
$content_end_pos = strrpos( $control_markup, $args[0]['after_widget_content'] );
|
||||
|
||||
$control = substr( $control_markup, 0, $content_start_pos + strlen( $args[0]['before_widget_content'] ) );
|
||||
$control = substr( $control_markup, 0, $content_start_pos + strlen( $args[0]['before_widget_content'] ) );
|
||||
$control .= substr( $control_markup, $content_end_pos );
|
||||
$content = trim( substr(
|
||||
$control_markup,
|
||||
$content_start_pos + strlen( $args[0]['before_widget_content'] ),
|
||||
$content_end_pos - $content_start_pos - strlen( $args[0]['before_widget_content'] )
|
||||
) );
|
||||
$content = trim(
|
||||
substr(
|
||||
$control_markup,
|
||||
$content_start_pos + strlen( $args[0]['before_widget_content'] ),
|
||||
$content_end_pos - $content_start_pos - strlen( $args[0]['before_widget_content'] )
|
||||
)
|
||||
);
|
||||
|
||||
return compact( 'control', 'content' );
|
||||
}
|
||||
|
@ -1056,8 +1094,8 @@ final class WP_Customize_Widgets {
|
|||
*/
|
||||
public function customize_preview_init() {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue' ) );
|
||||
add_action( 'wp_print_styles', array( $this, 'print_preview_css' ), 1 );
|
||||
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 20 );
|
||||
add_action( 'wp_print_styles', array( $this, 'print_preview_css' ), 1 );
|
||||
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 20 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1127,7 +1165,7 @@ final class WP_Customize_Widgets {
|
|||
* and at the very end of the wp_footer,
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
*
|
||||
* @global array $wp_registered_sidebars
|
||||
* @global array $wp_registered_widgets
|
||||
*/
|
||||
|
@ -1135,8 +1173,8 @@ final class WP_Customize_Widgets {
|
|||
global $wp_registered_sidebars, $wp_registered_widgets;
|
||||
|
||||
$switched_locale = switch_to_locale( get_user_locale() );
|
||||
$l10n = array(
|
||||
'widgetTooltip' => __( 'Shift-click to edit this widget.' ),
|
||||
$l10n = array(
|
||||
'widgetTooltip' => __( 'Shift-click to edit this widget.' ),
|
||||
);
|
||||
if ( $switched_locale ) {
|
||||
restore_previous_locale();
|
||||
|
@ -1144,11 +1182,11 @@ final class WP_Customize_Widgets {
|
|||
|
||||
// Prepare Customizer settings to pass to JavaScript.
|
||||
$settings = array(
|
||||
'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
|
||||
'renderedWidgets' => array_fill_keys( array_keys( $this->rendered_widgets ), true ),
|
||||
'registeredSidebars' => array_values( $wp_registered_sidebars ),
|
||||
'registeredWidgets' => $wp_registered_widgets,
|
||||
'l10n' => $l10n,
|
||||
'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
|
||||
'renderedWidgets' => array_fill_keys( array_keys( $this->rendered_widgets ), true ),
|
||||
'registeredSidebars' => array_values( $wp_registered_sidebars ),
|
||||
'registeredWidgets' => $wp_registered_widgets,
|
||||
'l10n' => $l10n,
|
||||
'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(),
|
||||
);
|
||||
foreach ( $settings['registeredWidgets'] as &$registered_widget ) {
|
||||
|
@ -1281,8 +1319,7 @@ final class WP_Customize_Widgets {
|
|||
|
||||
if ( empty( $value['is_widget_customizer_js_value'] )
|
||||
|| empty( $value['instance_hash_key'] )
|
||||
|| empty( $value['encoded_serialized_instance'] ) )
|
||||
{
|
||||
|| empty( $value['encoded_serialized_instance'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1398,14 +1435,14 @@ final class WP_Customize_Widgets {
|
|||
}
|
||||
|
||||
if ( ! is_null( $parsed_id['number'] ) ) {
|
||||
$value = array();
|
||||
$value[$parsed_id['number']] = $instance;
|
||||
$key = 'widget-' . $parsed_id['id_base'];
|
||||
$_REQUEST[$key] = $_POST[$key] = wp_slash( $value );
|
||||
$added_input_vars[] = $key;
|
||||
$value = array();
|
||||
$value[ $parsed_id['number'] ] = $instance;
|
||||
$key = 'widget-' . $parsed_id['id_base'];
|
||||
$_REQUEST[ $key ] = $_POST[ $key ] = wp_slash( $value );
|
||||
$added_input_vars[] = $key;
|
||||
} else {
|
||||
foreach ( $instance as $key => $value ) {
|
||||
$_REQUEST[$key] = $_POST[$key] = wp_slash( $value );
|
||||
$_REQUEST[ $key ] = $_POST[ $key ] = wp_slash( $value );
|
||||
$added_input_vars[] = $key;
|
||||
}
|
||||
}
|
||||
|
@ -1509,7 +1546,7 @@ final class WP_Customize_Widgets {
|
|||
|
||||
$widget_id = $this->get_post_value( 'widget-id' );
|
||||
$parsed_id = $this->parse_widget_id( $widget_id );
|
||||
$id_base = $parsed_id['id_base'];
|
||||
$id_base = $parsed_id['id_base'];
|
||||
|
||||
$is_updating_widget_template = (
|
||||
isset( $_POST[ 'widget-' . $id_base ] )
|
||||
|
@ -1527,7 +1564,7 @@ final class WP_Customize_Widgets {
|
|||
wp_send_json_error( $updated_widget->get_error_code() );
|
||||
}
|
||||
|
||||
$form = $updated_widget['form'];
|
||||
$form = $updated_widget['form'];
|
||||
$instance = $this->sanitize_widget_js_instance( $updated_widget['instance'] );
|
||||
|
||||
wp_send_json_success( compact( 'form', 'instance' ) );
|
||||
|
@ -1588,13 +1625,15 @@ final class WP_Customize_Widgets {
|
|||
/**
|
||||
* Inject selective refresh data attributes into widget container elements.
|
||||
*
|
||||
* @since 4.5.0
|
||||
*
|
||||
* @param array $params {
|
||||
* Dynamic sidebar params.
|
||||
*
|
||||
* @type array $args Sidebar args.
|
||||
* @type array $widget_args Widget args.
|
||||
* }
|
||||
* @see WP_Customize_Nav_Menus_Partial_Refresh::filter_wp_nav_menu_args()
|
||||
* @see WP_Customize_Nav_Menus::filter_wp_nav_menu_args()
|
||||
*
|
||||
* @return array Params.
|
||||
*/
|
||||
|
@ -1602,13 +1641,13 @@ final class WP_Customize_Widgets {
|
|||
$sidebar_args = array_merge(
|
||||
array(
|
||||
'before_widget' => '',
|
||||
'after_widget' => '',
|
||||
'after_widget' => '',
|
||||
),
|
||||
$params[0]
|
||||
);
|
||||
|
||||
// Skip widgets not in a registered sidebar or ones which lack a proper wrapper element to attach the data-* attributes to.
|
||||
$matches = array();
|
||||
$matches = array();
|
||||
$is_valid = (
|
||||
isset( $sidebar_args['id'] )
|
||||
&&
|
||||
|
@ -1628,14 +1667,14 @@ final class WP_Customize_Widgets {
|
|||
);
|
||||
if ( isset( $this->context_sidebar_instance_number ) ) {
|
||||
$context['sidebar_instance_number'] = $this->context_sidebar_instance_number;
|
||||
} else if ( isset( $sidebar_args['id'] ) && isset( $this->sidebar_instance_count[ $sidebar_args['id'] ] ) ) {
|
||||
} elseif ( isset( $sidebar_args['id'] ) && isset( $this->sidebar_instance_count[ $sidebar_args['id'] ] ) ) {
|
||||
$context['sidebar_instance_number'] = $this->sidebar_instance_count[ $sidebar_args['id'] ];
|
||||
}
|
||||
|
||||
$attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'widget[' . $sidebar_args['widget_id'] . ']' ) );
|
||||
$attributes .= ' data-customize-partial-type="widget"';
|
||||
$attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $context ) ) );
|
||||
$attributes .= sprintf( ' data-customize-widget-id="%s"', esc_attr( $sidebar_args['widget_id'] ) );
|
||||
$attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'widget[' . $sidebar_args['widget_id'] . ']' ) );
|
||||
$attributes .= ' data-customize-partial-type="widget"';
|
||||
$attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $context ) ) );
|
||||
$attributes .= sprintf( ' data-customize-widget-id="%s"', esc_attr( $sidebar_args['widget_id'] ) );
|
||||
$sidebar_args['before_widget'] = preg_replace( '#^(<\w+)#', '$1 ' . $attributes, $sidebar_args['before_widget'] );
|
||||
|
||||
$params[0] = $sidebar_args;
|
||||
|
@ -1670,13 +1709,16 @@ final class WP_Customize_Widgets {
|
|||
}
|
||||
$allowed_html[ $tag_name ] = array_merge(
|
||||
$allowed_html[ $tag_name ],
|
||||
array_fill_keys( array(
|
||||
'data-customize-partial-id',
|
||||
'data-customize-partial-type',
|
||||
'data-customize-partial-placement-context',
|
||||
'data-customize-partial-widget-id',
|
||||
'data-customize-partial-options',
|
||||
), true )
|
||||
array_fill_keys(
|
||||
array(
|
||||
'data-customize-partial-id',
|
||||
'data-customize-partial-type',
|
||||
'data-customize-partial-placement-context',
|
||||
'data-customize-partial-widget-id',
|
||||
'data-customize-partial-options',
|
||||
),
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
return $allowed_html;
|
||||
|
@ -1815,14 +1857,14 @@ final class WP_Customize_Widgets {
|
|||
// Render the widget.
|
||||
ob_start();
|
||||
dynamic_sidebar( $this->rendering_sidebar_id = $context['sidebar_id'] );
|
||||
$container = ob_get_clean();
|
||||
$container = ob_get_clean();
|
||||
|
||||
// Reset variables for next partial render.
|
||||
remove_filter( 'sidebars_widgets', $filter_callback, 1000 );
|
||||
|
||||
$this->context_sidebar_instance_number = null;
|
||||
$this->rendering_sidebar_id = null;
|
||||
$this->rendering_widget_id = null;
|
||||
$this->rendering_sidebar_id = null;
|
||||
$this->rendering_widget_id = null;
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
@ -1975,7 +2017,7 @@ final class WP_Customize_Widgets {
|
|||
remove_filter( "pre_option_{$option_name}", array( $this, 'capture_filter_pre_get_option' ) );
|
||||
}
|
||||
|
||||
$this->_captured_options = array();
|
||||
$this->_captured_options = array();
|
||||
$this->_is_capturing_option_updates = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue