Make WordPress Core

Ticket #27767: 27767-04.patch

File 27767-04.patch, 5.5 KB (added by gcorne, 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..448b13d 100644
     
    16141614                                widgetNumber = widget.get( 'multi_number' );
    16151615                        }
    16161616
    1617                         controlHtml = $( '#widget-tpl-' + widget.get( 'id' ) ).html();
     1617                        controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() );
    16181618                        if ( widget.get( 'is_multi' ) ) {
    16191619                                controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) {
    16201620                                        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 { 
    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..0504df4 100644
    final class WP_Customize_Widgets { 
    316316        }
    317317
    318318        /**
     319         * Get sidebar configuration
     320         *
     321         * Fetch the sidebar configuration directly from the option so that any preview filters are applied and
     322         * when the customizer is loaded with a theme that is not active override the initial sidebar in the configuration
     323         * that would be applied if the theme was activated instead of being previewed.
     324         *
     325         * @since 3.9
     326         * @access public
     327         */
     328        public function get_sidebars_widgets() {
     329                global $sidebars_widgets;
     330
     331                $sidebars_widgets = get_option( 'sidebars_widgets', array() );
     332
     333                if ( ! $this->manager->is_preview() &&
     334                        ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) ||
     335                        // Only override with widgets from theme_mods when loading the initial iframe
     336                        ( isset( $_POST['customize_messenger_channel'] ) && $_POST['customize_messenger_channel'] === 'preview-0' ) ) ) {
     337
     338                        if ( ! isset( $this->sidebars_widgets ) ) {
     339                                // Cache the modified version to avoid manipulating the set of widgets a second time
     340                                $this->sidebars_widgets = retrieve_widgets( true, false );
     341                        }
     342
     343                        // Override the widgets as fetched from the option
     344                        $sidebars_widgets = $this->sidebars_widgets;
     345                }
     346
     347                unset( $sidebars_widgets['array_version'] );
     348
     349                return $sidebars_widgets;
     350        }
     351
     352        /**
    319353         * Register customizer settings and controls for all sidebars and widgets.
    320354         *
    321355         * @since 3.9.0
    final class WP_Customize_Widgets { 
    327361                $sidebars_widgets = array_merge(
    328362                        array( 'wp_inactive_widgets' => array() ),
    329363                        array_fill_keys( array_keys( $GLOBALS['wp_registered_sidebars'] ), array() ),
    330                         wp_get_sidebars_widgets()
     364                        $this->get_sidebars_widgets()
    331365                );
    332366
    333367                $new_setting_ids = array();
    final class WP_Customize_Widgets { 
    891925         * @param array $sidebars_widgets List of widgets for the current sidebar.
    892926         */
    893927        public function preview_sidebars_widgets( $sidebars_widgets ) {
    894                 $sidebars_widgets = get_option( 'sidebars_widgets' );
     928                $sidebars_widgets = $this->get_sidebars_widgets();
    895929
    896                 unset( $sidebars_widgets['array_version'] );
    897930                return $sidebars_widgets;
    898931        }
    899932
  • 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}