Make WordPress Core

Ticket #27767: 27767-02.patch

File 27767-02.patch, 4.3 KB (added by gcorne, 11 years ago)
  • 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 { 
    575575                        // to operate properly.
    576576                        $this->stop_previewing_theme();
    577577                        switch_theme( $this->get_stylesheet() );
     578                        update_option( 'theme_switched_via_customizer', true );
    578579                        $this->start_previewing_theme();
    579580                }
    580581
  • 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..a28b6e0 100644
    final class WP_Customize_Widgets { 
    315315                }
    316316        }
    317317
     318        public function get_sidebars_widgets() {
     319                global $sidebars_widgets;
     320
     321                $sidebars_widgets = get_option( 'sidebars_widgets' );
     322                if ( ! $this->manager->is_theme_active() &&
     323                        ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) ||
     324                        // Only override with widgets from theme_mods when loading the initial iframe
     325                        ( isset( $_POST['customize_messenger_channel'] ) && $_POST['customize_messenger_channel'] === 'preview-0' ) ) ) {
     326
     327                        $sidebars_widgets = retrieve_widgets( true, false );
     328                }
     329
     330                unset( $sidebars_widgets['array_version'] );
     331
     332                return $sidebars_widgets;
     333        }
     334
    318335        /**
    319336         * Register customizer settings and controls for all sidebars and widgets.
    320337         *
    final class WP_Customize_Widgets { 
    327344                $sidebars_widgets = array_merge(
    328345                        array( 'wp_inactive_widgets' => array() ),
    329346                        array_fill_keys( array_keys( $GLOBALS['wp_registered_sidebars'] ), array() ),
    330                         wp_get_sidebars_widgets()
     347                        $this->get_sidebars_widgets()
    331348                );
    332349
    333350                $new_setting_ids = array();
    final class WP_Customize_Widgets { 
    891908         * @param array $sidebars_widgets List of widgets for the current sidebar.
    892909         */
    893910        public function preview_sidebars_widgets( $sidebars_widgets ) {
    894                 $sidebars_widgets = get_option( 'sidebars_widgets' );
     911                $sidebars_widgets = $this->get_sidebars_widgets();
    895912
    896                 unset( $sidebars_widgets['array_version'] );
    897913                return $sidebars_widgets;
    898914        }
    899915
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index f66fd95..9bb1a1f 100644
    function check_theme_switched() { 
    17911791        if ( $stylesheet = get_option( 'theme_switched' ) ) {
    17921792                $old_theme = wp_get_theme( $stylesheet );
    17931793
     1794                if ( get_option( 'theme_switched_via_customizer' ) ) {
     1795                        remove_filter( 'after_switch_theme', '_wp_sidebars_changed' );
     1796                        update_option( 'theme_switched_via_customizer', false );
     1797                }
     1798
    17941799                if ( $old_theme->exists() ) {
    17951800                        /**
    17961801                         * Fires on the first WP load after a theme switch if the old theme still exists.
    function wp_customize_support_script() { 
    19181923                }());
    19191924        </script>
    19201925        <?php
    1921 }
    1922  No newline at end of file
     1926}
  • src/wp-includes/widgets.php

    diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
    index b911fde..1f60a55 100644
    function _wp_sidebars_changed() { 
    14021402}
    14031403
    14041404// look for "lost" widgets, this has to run at least on each theme change
    1405 function retrieve_widgets($theme_changed = false) {
     1405function retrieve_widgets($theme_changed = false, $update = true ) {
    14061406        global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
    14071407
    14081408        $registered_sidebar_keys = array_keys( $wp_registered_sidebars );
    function retrieve_widgets($theme_changed = false) { 
    14121412        if ( is_array( $old_sidebars_widgets ) ) {
    14131413                // time() that sidebars were stored is in $old_sidebars_widgets['time']
    14141414                $_sidebars_widgets = $old_sidebars_widgets['data'];
    1415                 remove_theme_mod( 'sidebars_widgets' );
     1415
     1416                if ( $update ) {
     1417                        remove_theme_mod( 'sidebars_widgets' );
     1418                }
    14161419
    14171420                foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
    14181421                        if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
    function retrieve_widgets($theme_changed = false) { 
    14951498        }
    14961499
    14971500        $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
    1498         wp_set_sidebars_widgets($sidebars_widgets);
     1501        if ( $update ) {
     1502                wp_set_sidebars_widgets($sidebars_widgets);
     1503        }
    14991504
    15001505        return $sidebars_widgets;
    15011506}