Ticket #27767: 27767-11.patch
File 27767-11.patch, 10.8 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/customize-widgets.js
diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js index 48ba335..f2782b9 100644
942 942 params.action = 'update-widget'; 943 943 params.wp_customize = 'on'; 944 944 params.nonce = api.Widgets.data.nonce; 945 params.theme = api.settings.theme.stylesheet; 945 946 946 947 data = $.param( params ); 947 948 $inputs = this._getInputs( $widgetContent ); … … 1614 1615 widgetNumber = widget.get( 'multi_number' ); 1615 1616 } 1616 1617 1617 controlHtml = $ ( '#widget-tpl-' + widget.get( 'id' ) ).html();1618 controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() ); 1618 1619 if ( widget.get( 'is_multi' ) ) { 1619 1620 controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) { 1620 1621 return m.replace( /__i__|%i%/g, widgetNumber ); -
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index 18a1d76..8ed4e69 100644
final class WP_Customize_Manager { 575 575 // to operate properly. 576 576 $this->stop_previewing_theme(); 577 577 switch_theme( $this->get_stylesheet() ); 578 update_option( 'theme_switched_via_customizer', true ); 578 579 $this->start_previewing_theme(); 579 580 } 580 581 -
src/wp-includes/class-wp-customize-widgets.php
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php index 72ff397..42e00e9 100644
final class WP_Customize_Widgets { 61 61 protected $rendered_widgets = array(); 62 62 63 63 /** 64 * @since 3.9.0 65 * @access protected 66 * @var array 67 */ 68 protected $old_sidebars_widgets = array(); 69 70 /** 64 71 * Initial loader. 65 72 * 66 73 * @since 3.9.0 … … final class WP_Customize_Widgets { 72 79 $this->manager = $manager; 73 80 74 81 add_action( 'after_setup_theme', array( $this, 'setup_widget_addition_previews' ) ); 82 add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) ); 75 83 add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) ); 76 84 add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 ); 77 85 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); … … final class WP_Customize_Widgets { 115 123 * @since 3.9.0 116 124 * 117 125 * @access public 118 * @global WP_Customize_Manager $wp_customize Customizer instance.119 126 */ 120 127 public function setup_widget_addition_previews() { 121 128 $is_customize_preview = false; … … final class WP_Customize_Widgets { 125 132 } 126 133 127 134 $is_ajax_widget_update = false; 128 if ( defined( 'DOING_AJAX' ) && DOING_AJAX&& 'update-widget' === $this->get_post_value( 'action' ) ) {135 if ( $this->manager->doing_ajax() && 'update-widget' === $this->get_post_value( 'action' ) ) { 129 136 $is_ajax_widget_update = check_ajax_referer( 'update-widget', 'nonce', false ); 130 137 } 131 138 132 139 $is_ajax_customize_save = false; 133 if ( defined( 'DOING_AJAX' ) && DOING_AJAX&& 'customize_save' === $this->get_post_value( 'action' ) ) {140 if ( $this->manager->doing_ajax() && 'customize_save' === $this->get_post_value( 'action' ) ) { 134 141 $is_ajax_customize_save = check_ajax_referer( 'save-customize_' . $this->manager->get_stylesheet(), 'nonce', false ); 135 142 } 136 143 … … final class WP_Customize_Widgets { 279 286 } 280 287 281 288 /** 289 * Override sidebars_widgets for theme switch. 290 * 291 * When switching a theme via the customizer, supply any previously-configured 292 * sidebars_widgets from the target theme as the initial sidebars_widgets 293 * setting. Also store the old theme's existing settings so that they can 294 * be passed along for storing in the sidebars_widgets theme_mod when the 295 * theme gets switched. 296 * 297 * @since 3.9.0 298 * @access public 299 */ 300 public function override_sidebars_widgets_for_theme_switch() { 301 if ( $this->manager->doing_ajax() || $this->manager->is_theme_active() ) { 302 return; 303 } 304 305 $this->old_sidebars_widgets = wp_get_sidebars_widgets(); 306 add_filter( 'customize_value_old_sidebars_widgets_data', array( $this, 'filter_customize_value_old_sidebars_widgets_data' ) ); 307 308 $GLOBALS['sidebars_widgets'] = $this->old_sidebars_widgets; // retrieve_widgets() looks at the global $sidebars_widgets 309 $GLOBALS['sidebars_widgets'] = retrieve_widgets( true, false ); 310 add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 ); 311 } 312 313 /** 314 * Filter old_sidebars_widgets_data customizer setting. 315 * 316 * When switching themes, filter the Customizer setting 317 * old_sidebars_widgets_data to supply initial $sidebars_widgets before they 318 * were overridden by retrieve_widgets(). The value for 319 * old_sidebars_widgets_data gets set in the old theme's sidebars_widgets 320 * theme_mod. 321 * 322 * @see WP_Customize_Widgets::handle_theme_switch() 323 * @since 3.9.0 324 * @access public 325 * 326 * @param array $sidebars_widgets 327 */ 328 public function filter_customize_value_old_sidebars_widgets_data( $old_sidebars_widgets ) { 329 $old_sidebars_widgets = $this->old_sidebars_widgets; 330 return $old_sidebars_widgets; 331 } 332 333 /** 334 * Filter sidebars_widgets option for theme switch. 335 * 336 * When switching themes, the retrieve_widgets() function is run when the 337 * Customizer initializes, and then the new sidebars_widgets here get 338 * supplied as the default value for the sidebars_widgets option. 339 * 340 * @see WP_Customize_Widgets::handle_theme_switch() 341 * @since 3.9.0 342 * @access public 343 * 344 * @param array $sidebars_widgets 345 */ 346 public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) { 347 $sidebars_widgets = $GLOBALS['sidebars_widgets']; 348 $sidebars_widgets['array_version'] = 3; 349 return $sidebars_widgets; 350 } 351 352 /** 282 353 * Make sure all widgets get loaded into the Customizer. 283 354 * 284 355 * Note: these actions are also fired in wp_ajax_update_widget(). … … final class WP_Customize_Widgets { 349 420 $new_setting_ids[] = $setting_id; 350 421 } 351 422 423 /* 424 * Add a setting which will be supplied for the theme's sidebars_widgets 425 * theme_mod when the the theme is switched. 426 */ 427 if ( ! $this->manager->is_theme_active() ) { 428 $setting_id = 'old_sidebars_widgets_data'; 429 $setting_args = $this->get_setting_args( $setting_id, array( 430 'type' => 'global_variable', 431 ) ); 432 $this->manager->add_setting( $setting_id, $setting_args ); 433 } 434 352 435 foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) { 353 436 if ( empty( $sidebar_widget_ids ) ) { 354 437 $sidebar_widget_ids = array(); -
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index f66fd95..39ffc6d 100644
function preview_theme_ob_filter_callback( $matches ) { 752 752 * @param string $stylesheet Stylesheet name 753 753 */ 754 754 function switch_theme( $stylesheet ) { 755 global $wp_theme_directories, $ sidebars_widgets;755 global $wp_theme_directories, $wp_customize, $sidebars_widgets; 756 756 757 if ( is_array( $sidebars_widgets ) ) 758 set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) ); 757 $_sidebars_widgets = null; 758 if ( current_action() === 'wp_ajax_customize_save' ) { 759 $_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) ); 760 } else if ( is_array( $sidebars_widgets ) ) { 761 $_sidebars_widgets = $sidebars_widgets; 762 } 763 if ( is_array( $_sidebars_widgets ) ) { 764 set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); 765 } 759 766 760 767 $old_theme = wp_get_theme(); 761 768 $new_theme = wp_get_theme( $stylesheet ); … … function switch_theme( $stylesheet ) { 785 792 if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { 786 793 $default_theme_mods = (array) get_option( 'mods_' . $new_name ); 787 794 add_option( "theme_mods_$stylesheet", $default_theme_mods ); 795 } else { 796 // Since retrieve_widgets() is called when initializing the customizer theme, we need to remove the theme mods to avoid overwriting changes made via the widget customizer when accessing /wp-admin/widgets.php 797 if ( current_action() === 'wp_ajax_customize_save' ) { 798 remove_theme_mod( 'sidebars_widgets' ); 799 } 788 800 } 789 801 790 802 update_option( 'theme_switched', $old_theme->get_stylesheet() ); … … function check_theme_switched() { 1791 1803 if ( $stylesheet = get_option( 'theme_switched' ) ) { 1792 1804 $old_theme = wp_get_theme( $stylesheet ); 1793 1805 1806 // Prevent retrieve_widgets() from running since Customizer already called it up front 1807 if ( get_option( 'theme_switched_via_customizer' ) ) { 1808 remove_action( 'after_switch_theme', '_wp_sidebars_changed' ); 1809 update_option( 'theme_switched_via_customizer', false ); 1810 } 1811 1794 1812 if ( $old_theme->exists() ) { 1795 1813 /** 1796 1814 * Fires on the first WP load after a theme switch if the old theme still exists. … … function wp_customize_support_script() { 1918 1936 }()); 1919 1937 </script> 1920 1938 <?php 1921 } 1922 No newline at end of file 1939 } -
src/wp-includes/widgets.php
diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php index b911fde..b042199 100644
function _wp_sidebars_changed() { 1401 1401 retrieve_widgets(true); 1402 1402 } 1403 1403 1404 // look for "lost" widgets, this has to run at least on each theme change 1405 function retrieve_widgets($theme_changed = false) { 1404 /** 1405 * Look for "lost" widgets, this has to run at least on each theme change. 1406 * 1407 * @since 2.8.0 1408 * 1409 * @param bool $theme_changed Whether the theme was changed. 1410 * @param bool $update Whether to update the theme_mods. False is used for deferred update in Customizer. 1411 * 1412 * @return array 1413 */ 1414 function retrieve_widgets( $theme_changed = false, $update = true ) { 1406 1415 global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 1407 1416 1408 1417 $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); … … function retrieve_widgets($theme_changed = false) { 1412 1421 if ( is_array( $old_sidebars_widgets ) ) { 1413 1422 // time() that sidebars were stored is in $old_sidebars_widgets['time'] 1414 1423 $_sidebars_widgets = $old_sidebars_widgets['data']; 1415 remove_theme_mod( 'sidebars_widgets' ); 1424 1425 if ( $update ) { 1426 remove_theme_mod( 'sidebars_widgets' ); 1427 } 1416 1428 1417 1429 foreach ( $_sidebars_widgets as $sidebar => $widgets ) { 1418 1430 if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) … … function retrieve_widgets($theme_changed = false) { 1495 1507 } 1496 1508 1497 1509 $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); 1498 wp_set_sidebars_widgets($sidebars_widgets); 1510 if ( $update ) { 1511 wp_set_sidebars_widgets( $sidebars_widgets ); 1512 } 1499 1513 1500 1514 return $sidebars_widgets; 1501 1515 }