Make WordPress Core


Ignore:
Timestamp:
07/04/2020 07:33:06 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Customize: Correct the check for rendered widgets in WP_Customize_Widgets::is_widget_rendered().

Make the structure of ::$rendered_sidebars and ::$rendered_widgets properties consistent.

This resolves an issue with every widget being marked as inactive by default on the Widgets panel.

Props dlh, afercia, SergeyBiryukov.
Fixes #50508.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r48121 r48299  
    11711171
    11721172        $switched_locale = switch_to_locale( get_user_locale() );
    1173         $l10n            = array(
     1173
     1174        $l10n = array(
    11741175            'widgetTooltip' => __( 'Shift-click to edit this widget.' ),
    11751176        );
     1177
    11761178        if ( $switched_locale ) {
    11771179            restore_previous_locale();
    11781180        }
    11791181
     1182        $rendered_sidebars = array_filter( $this->rendered_sidebars );
     1183        $rendered_widgets  = array_filter( $this->rendered_widgets );
     1184
    11801185        // Prepare Customizer settings to pass to JavaScript.
    11811186        $settings = array(
    1182             'renderedSidebars'            => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
    1183             'renderedWidgets'             => array_fill_keys( array_keys( $this->rendered_widgets ), true ),
     1187            'renderedSidebars'            => array_fill_keys( array_keys( $rendered_sidebars ), true ),
     1188            'renderedWidgets'             => array_fill_keys( array_keys( $rendered_widgets ), true ),
    11841189            'registeredSidebars'          => array_values( $wp_registered_sidebars ),
    11851190            'registeredWidgets'           => $wp_registered_widgets,
     
    11871192            'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(),
    11881193        );
     1194
    11891195        foreach ( $settings['registeredWidgets'] as &$registered_widget ) {
    11901196            unset( $registered_widget['callback'] ); // May not be JSON-serializeable.
     
    12181224     */
    12191225    public function is_widget_rendered( $widget_id ) {
    1220         return in_array( $widget_id, $this->rendered_widgets, true );
     1226        return ! empty( $this->rendered_widgets[ $widget_id ] );
    12211227    }
    12221228
     
    12301236     */
    12311237    public function is_sidebar_rendered( $sidebar_id ) {
    1232         return in_array( $sidebar_id, $this->rendered_sidebars, true );
     1238        return ! empty( $this->rendered_sidebars[ $sidebar_id ] );
    12331239    }
    12341240
     
    12481254    public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
    12491255        if ( is_registered_sidebar( $sidebar_id ) ) {
    1250             $this->rendered_sidebars[] = $sidebar_id;
    1251         }
     1256            $this->rendered_sidebars[ $sidebar_id ] = true;
     1257        }
     1258
    12521259        /*
    12531260         * We may need to force this to true, and also force-true the value
     
    12731280    public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
    12741281        if ( is_registered_sidebar( $sidebar_id ) ) {
    1275             $this->rendered_sidebars[] = $sidebar_id;
     1282            $this->rendered_sidebars[ $sidebar_id ] = true;
    12761283        }
    12771284
Note: See TracChangeset for help on using the changeset viewer.