Make WordPress Core

Changeset 52621


Ignore:
Timestamp:
01/24/2022 05:32:28 AM (5 years ago)
Author:
noisysocks
Message:

Customizer: Remove Menus panel when a theme does not support menus

By overriding check_capabilities(), we can ensure that the Menus panel
is removed if a theme does not have support for 'menus' nor 'widgets'.

This ensures that the Menus panel does not appear when using a block
theme, which is confusing to users.

See #54888.
Props hellofromTonya, costdev, peterwilsoncc.

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

Legend:

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

    r52355 r52621  
    233233         *
    234234         * @since 4.0.0
     235         * @since 5.9.0 Method was marked non-final.
    235236         *
    236237         * @return bool False if theme doesn't support the panel or the user doesn't have the capability.
    237238         */
    238         final public function check_capabilities() {
     239        public function check_capabilities() {
    239240                if ( $this->capability && ! current_user_can( $this->capability ) ) {
    240241                        return false;
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menus-panel.php

    r45932 r52621  
    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        }
    101124}
Note: See TracChangeset for help on using the changeset viewer.