Ticket #27767: 27767-07.patch
File 27767-07.patch, 8.6 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..3b4db65 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() { 128 129 130 121 131 $is_customize_preview = false; 122 132 123 133 if ( ! empty( $this->manager ) && ! is_admin() && 'on' === $this->get_post_value( 'wp_customize' ) ) { … … final class WP_Customize_Widgets { 279 289 } 280 290 281 291 /** 292 * Handle theme switch 293 * 294 * When switching a theme via the customizer, supply any previously-configured 295 * sidebars_widgets from the target theme as the initial sidebars_widgets 296 * setting. Also store the old theme's existing settings so that they can 297 * be passed along for storing in the sidebars_widgets theme_mod when the 298 * theme gets switched. 299 * 300 * @since 3.9.0 301 * @access public 302 */ 303 public function handle_theme_switch() { 304 if ( 'customize.php' === $GLOBALS['pagenow'] && ! $this->manager->is_theme_active() ) { 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 /** 315 * 316 * @see WP_Customize_Widgets::handle_theme_switch() 317 * @since 3.9.0 318 * @access public 319 * 320 * @param array $sidebars_widgets 321 */ 322 public function filter_customize_value_old_sidebars_widgets_data( $old_sidebars_widgets ) { 323 $old_sidebars_widgets = $this->old_sidebars_widgets; 324 return $old_sidebars_widgets; 325 } 326 327 /** 328 * 329 * @see WP_Customize_Widgets::handle_theme_switch() 330 * @since 3.9.0 331 * @access public 332 * 333 * @param array $sidebars_widgets 334 */ 335 public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) { 336 $sidebars_widgets = $GLOBALS['sidebars_widgets']; 337 $sidebars_widgets['array_version'] = 3; 338 return $sidebars_widgets; 339 } 340 341 /** 282 342 * Make sure all widgets get loaded into the Customizer. 283 343 * 284 344 * Note: these actions are also fired in wp_ajax_update_widget(). … … final class WP_Customize_Widgets { 349 409 $new_setting_ids[] = $setting_id; 350 410 } 351 411 412 /** 413 * Add a setting which will be supplied for the theme's sidebars_widgets 414 * theme_mod when the the theme is switched. 415 */ 416 if ( ! $this->manager->is_theme_active() ) { 417 $setting_id = 'old_sidebars_widgets_data'; 418 $setting_args = $this->get_setting_args( $setting_id, array( 419 'type' => 'global_variable', 420 ) ); 421 $this->manager->add_setting( $setting_id, $setting_args ); 422 } 423 352 424 foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) { 353 425 if ( empty( $sidebar_widget_ids ) ) { 354 426 $sidebar_widget_ids = array(); -
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index f66fd95..2d09dcf 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 check_theme_switched() { 1791 1798 if ( $stylesheet = get_option( 'theme_switched' ) ) { 1792 1799 $old_theme = wp_get_theme( $stylesheet ); 1793 1800 1801 /** 1802 * Prevent retrieve_widgets() from running since Customizer already called it up front 1803 */ 1804 if ( get_option( 'theme_switched_via_customizer' ) ) { 1805 remove_action( 'after_switch_theme', '_wp_sidebars_changed' ); 1806 update_option( 'theme_switched_via_customizer', false ); 1807 } 1808 1794 1809 if ( $old_theme->exists() ) { 1795 1810 /** 1796 1811 * Fires on the first WP load after a theme switch if the old theme still exists. … … function wp_customize_support_script() { 1918 1933 }()); 1919 1934 </script> 1920 1935 <?php 1921 } 1922 No newline at end of file 1936 } -
src/wp-includes/widgets.php
diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php index b911fde..aad8870 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 * @param bool $theme_changed 1408 * @param bool $update 1409 * 1410 * @return array 1411 */ 1412 function retrieve_widgets( $theme_changed = false, $update = true ) { 1406 1413 global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 1407 1414 1408 1415 $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); … … function retrieve_widgets($theme_changed = false) { 1412 1419 if ( is_array( $old_sidebars_widgets ) ) { 1413 1420 // time() that sidebars were stored is in $old_sidebars_widgets['time'] 1414 1421 $_sidebars_widgets = $old_sidebars_widgets['data']; 1415 remove_theme_mod( 'sidebars_widgets' ); 1422 1423 if ( $update ) { 1424 remove_theme_mod( 'sidebars_widgets' ); 1425 } 1416 1426 1417 1427 foreach ( $_sidebars_widgets as $sidebar => $widgets ) { 1418 1428 if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) … … function retrieve_widgets($theme_changed = false) { 1495 1505 } 1496 1506 1497 1507 $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); 1498 wp_set_sidebars_widgets($sidebars_widgets); 1508 if ( $update ) { 1509 wp_set_sidebars_widgets( $sidebars_widgets ); 1510 } 1499 1511 1500 1512 return $sidebars_widgets; 1501 1513 }