Customize: Harden assignment of Customizer settings transports for selective refreshable widgets

Theme support for `customize-selective-refresh-widgets` can be added _after_ the logic for registering the settings for incoming widgets that have been changed. This is due to themes adding the theme support in `after_setup_theme` which is also the action where `WP_Customize_Widgets::register_settings()` is called. If these both happen at priority 10, which one is called first depends on which one was added first. The other issue is that at the time that `WP_Customize_Widgets::register_settings()` is called at `after_setup_theme`, it is called before `widgets_init` and thus no widgets are yet registered. This means that any settings registered at this point will always have a `refresh` transport even if the theme supports `customize-selective-refresh-widgets`, since the `WP_Widget` instance is not visible yet to see if it supports selective refresh.

The fix: Defer `WP_Customize_Widgets::register_settings()` from `after_setup_theme` to `widgets_init` at priority 95 when the widget objects have all been registered. Also, ensure that the preview filter for `sidebars_widgets` is added before the sidebars are iterated for adding the controls.

Props westonruter.
Fixes #36389.
Built from https://develop.svn.wordpress.org/trunk@37166


git-svn-id: http://core.svn.wordpress.org/trunk@37133 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-04-07 20:59:29 +00:00
parent cfab9716e3
commit 9363b592e3
3 changed files with 17 additions and 4 deletions

View File

@ -206,6 +206,19 @@ class WP_Customize_Setting {
}
}
/**
* Reset `$aggregated_multidimensionals` static variable.
*
* This is intended only for use by unit tests.
*
* @since 4.5.0
* @access public
* @ignore
*/
static public function reset_aggregated_multidimensionals() {
self::$aggregated_multidimensionals = array();
}
/**
* The ID for the current site when the preview() method was called.
*

View File

@ -99,7 +99,7 @@ final class WP_Customize_Widgets {
}
add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 );
add_action( 'after_setup_theme', array( $this, 'register_settings' ) );
add_action( 'widgets_init', array( $this, 'register_settings' ), 95 );
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_register', array( $this, 'schedule_customize_register' ), 1 );
@ -376,6 +376,8 @@ final class WP_Customize_Widgets {
public function customize_register() {
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars;
add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );
$sidebars_widgets = array_merge(
array( 'wp_inactive_widgets' => array() ),
array_fill_keys( array_keys( $wp_registered_sidebars ), array() ),
@ -509,8 +511,6 @@ final class WP_Customize_Widgets {
$this->manager->get_setting( $new_setting_id )->preview();
}
}
add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-RC1-37165';
$wp_version = '4.5-RC1-37166';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.