WordPress.org

Make WordPress Core

Ticket #39087: 39087.experiment.diff

File 39087.experiment.diff, 1.8 KB (added by westonruter, 3 years ago)
  • 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 0cd2359d56..7223a262ba 100644
    final class WP_Customize_Widgets { 
    115115
    116116                add_action( 'dynamic_sidebar',                         array( $this, 'tally_rendered_widgets' ) );
    117117                add_filter( 'is_active_sidebar',                       array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
     118                add_filter( 'body_class',                              array( $this, 'flag_did_filter_body_classes' ), 1000 );
    118119                add_filter( 'dynamic_sidebar_has_widgets',             array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 );
    119120
    120121                // Selective Refresh.
    final class WP_Customize_Widgets { 
    122123                add_action( 'customize_preview_init',                  array( $this, 'selective_refresh_init' ) );
    123124        }
    124125
     126        protected $did_filter_body_classes = false;
     127
     128        /**
     129         * Capture the "action" for when the body classes have already been computed and thus the last time that is_active_sidebar is likely to be called until dynamic_sidebar() calls.
     130         *
     131         * @param array $classes Body classes.
     132         * @return array Body classes/
     133         */
     134        function flag_did_filter_body_classes( $classes ) {
     135                $this->did_filter_body_classes = true;
     136                return $classes;
     137        }
     138
    125139        /**
    126140         * List whether each registered widget can be use selective refresh.
    127141         *
    final class WP_Customize_Widgets { 
    12031217         * @return bool Whether the sidebar is active.
    12041218         */
    12051219        public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
    1206                 if ( is_registered_sidebar( $sidebar_id ) ) {
     1220                if ( $this->did_filter_body_classes && is_registered_sidebar( $sidebar_id ) ) {
    12071221                        $this->rendered_sidebars[] = $sidebar_id;
    12081222                }
    12091223                /*