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.

Built from https://develop.svn.wordpress.org/trunk@52621


git-svn-id: http://core.svn.wordpress.org/trunk@52209 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
noisysocks 2022-01-24 05:34:04 +00:00
parent 997f8b9921
commit 4aaa1803ec
3 changed files with 26 additions and 2 deletions

View File

@ -232,10 +232,11 @@ class WP_Customize_Panel {
* feature support required by the panel.
*
* @since 4.0.0
* @since 5.9.0 Method was marked non-final.
*
* @return bool False if theme doesn't support the panel or the user doesn't have the capability.
*/
final public function check_capabilities() {
public function check_capabilities() {
if ( $this->capability && ! current_user_can( $this->capability ) ) {
return false;
}

View File

@ -98,4 +98,27 @@ class WP_Customize_Nav_Menus_Panel extends WP_Customize_Panel {
<li class="customize-control-title customize-section-title-nav_menus-heading"><?php _e( 'Menus' ); ?></li>
<?php
}
/**
* Checks required user capabilities and whether the theme has the
* feature support required by the panel.
*
* @since 5.9.0
*
* @return bool False if theme doesn't support the panel or the user doesn't have the capability.
*/
public function check_capabilities() {
/*
* WP_Customize_Panel::$theme_supports only supports checking one
* theme_supports, so instead we override check_capabilities().
*/
if (
! current_theme_supports( 'menus' ) &&
! current_theme_supports( 'widgets' )
) {
return false;
}
return parent::check_capabilities();
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52620';
$wp_version = '6.0-alpha-52621';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.