Ticket #27767: 27767-09.patch
File 27767-09.patch, 9.9 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..df92a4a 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 { 71 78 public function __construct( $manager ) { 72 79 $this->manager = $manager; 73 80 81 add_action( 'widgets_init', array( $this, 'handle_theme_switch' ), 10000 ); 74 82 add_action( 'after_setup_theme', array( $this, 'setup_widget_addition_previews' ) ); 75 83 add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) ); 76 84 add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 ); … … 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 { 279 286 } 280 287 281 288 /** 289 * Handle 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 handle_theme_switch() { 301 if ( 'customize.php' === $GLOBALS['pagenow'] && ! $this->manager->is_theme_active() ) { 302 $this->old_sidebars_widgets = wp_get_sidebars_widgets(); 303 add_filter( 'customize_value_old_sidebars_widgets_data', array( $this, 'filter_customize_value_old_sidebars_widgets_data' ) ); 304 305 $GLOBALS['sidebars_widgets'] = $this->old_sidebars_widgets; // retrieve_widgets() looks at the global $sidebars_widgets 306 $GLOBALS['sidebars_widgets'] = retrieve_widgets( true, false ); 307 add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 ); 308 } 309 } 310 311 /** 312 * Filter old_sidebars_widgets_data customizer setting. 313 * 314 * When switching themes, filter the Customizer setting 315 * old_sidebars_widgets_data to supply initial $sidebars_widgets before they 316 * were overridden by retrieve_widgets(). The value for 317 * old_sidebars_widgets_data gets set in the old theme's sidebars_widgets 318 * theme_mod. 319 * 320 * @see WP_Customize_Widgets::handle_theme_switch() 321 * @since 3.9.0 322 * @access public 323 * 324 * @param array $sidebars_widgets 325 */ 326 public function filter_customize_value_old_sidebars_widgets_data( $old_sidebars_widgets ) { 327 $old_sidebars_widgets = $this->old_sidebars_widgets; 328 return $old_sidebars_widgets; 329 } 330 331 /** 332 * Filter sidebars_widgets option for theme switch. 333 * 334 * When switching themes, the retrieve_widgets() function is run when the 335 * Customizer initializes, and then the new sidebars_widgets here get 336 * supplied as the default value for the sidebars_widgets option. 337 * 338 * @see WP_Customize_Widgets::handle_theme_switch() 339 * @since 3.9.0 340 * @access public 341 * 342 * @param array $sidebars_widgets 343 */ 344 public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) { 345 $sidebars_widgets = $GLOBALS['sidebars_widgets']; 346 $sidebars_widgets['array_version'] = 3; 347 return $sidebars_widgets; 348 } 349 350 /** 282 351 * Make sure all widgets get loaded into the Customizer. 283 352 * 284 353 * Note: these actions are also fired in wp_ajax_update_widget(). … … final class WP_Customize_Widgets { 349 418 $new_setting_ids[] = $setting_id; 350 419 } 351 420 421 /* 422 * Add a setting which will be supplied for the theme's sidebars_widgets 423 * theme_mod when the the theme is switched. 424 */ 425 if ( ! $this->manager->is_theme_active() ) { 426 $setting_id = 'old_sidebars_widgets_data'; 427 $setting_args = $this->get_setting_args( $setting_id, array( 428 'type' => 'global_variable', 429 ) ); 430 $this->manager->add_setting( $setting_id, $setting_args ); 431 } 432 352 433 foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) { 353 434 if ( empty( $sidebar_widget_ids ) ) { 354 435 $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 }