Make WordPress Core

Changeset 54419


Ignore:
Timestamp:
10/07/2022 08:46:39 PM (2 years ago)
Author:
westonruter
Message:

Customize: Prevent PHP notice in Customizer when using block theme.

Use the customize_panel_active filter to deactivate the Menus panel instead of overriding the check_capabilities method. This ensures the panel remains registered but is still hidden.

See #54888.
Fixes #54905.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menus-panel.php

    r52621 r54419  
    9999        <?php
    100100    }
    101 
    102     /**
    103      * Checks required user capabilities and whether the theme has the
    104      * feature support required by the panel.
    105      *
    106      * @since 5.9.0
    107      *
    108      * @return bool False if theme doesn't support the panel or the user doesn't have the capability.
    109      */
    110     public function check_capabilities() {
    111         /*
    112          * WP_Customize_Panel::$theme_supports only supports checking one
    113          * theme_supports, so instead we override check_capabilities().
    114          */
    115         if (
    116             ! current_theme_supports( 'menus' ) &&
    117             ! current_theme_supports( 'widgets' )
    118         ) {
    119             return false;
    120         }
    121 
    122         return parent::check_capabilities();
    123     }
    124101}
  • trunk/src/wp-includes/theme.php

    r54176 r54419  
    42584258
    42594259    add_filter( 'should_load_separate_core_block_assets', '__return_true' );
    4260 }
     4260
     4261    /*
     4262     * Remove the Customizer's Menus panel when block theme is active.
     4263     */
     4264    add_filter(
     4265        'customize_panel_active',
     4266        static function ( $active, WP_Customize_Panel $panel ) {
     4267            if (
     4268                'nav_menus' === $panel->id &&
     4269                ! current_theme_supports( 'menus' ) &&
     4270                ! current_theme_supports( 'widgets' )
     4271            ) {
     4272                $active = false;
     4273            }
     4274            return $active;
     4275        },
     4276        10,
     4277        2
     4278    );
     4279}
Note: See TracChangeset for help on using the changeset viewer.