Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback handling for plugins or themes using the Customizer #35877

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions lib/full-site-editing/full-site-editing.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ function gutenberg_remove_legacy_pages() {
if ( isset( $submenu['themes.php'] ) ) {
$indexes_to_remove = array();
foreach ( $submenu['themes.php'] as $index => $menu_item ) {
if (
false !== strpos( $menu_item[2], 'customize.php' ) ||
false !== strpos( $menu_item[2], 'gutenberg-widgets' )
) {
if ( false !== strpos( $menu_item[2], 'customize.php' ) && ! gutenberg_site_requires_customizer() ) {
$indexes_to_remove[] = $index;
}

if ( false !== strpos( $menu_item[2], 'gutenberg-widgets' ) ) {
$indexes_to_remove[] = $index;
}
}
Expand All @@ -63,11 +64,13 @@ function gutenberg_adminbar_items( $wp_admin_bar ) {
return;
}

// Remove customizer link.
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'customize-background' );
$wp_admin_bar->remove_node( 'customize-header' );
$wp_admin_bar->remove_node( 'widgets' );
// Remove customizer link, if this site does not rely on them for plugins or theme options.
if ( ! gutenberg_site_requires_customizer() ) {
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'customize-background' );
$wp_admin_bar->remove_node( 'customize-header' );
$wp_admin_bar->remove_node( 'widgets' );
}

// Add site-editor link.
if ( ! is_admin() && current_user_can( 'edit_theme_options' ) ) {
Expand All @@ -83,6 +86,19 @@ function gutenberg_adminbar_items( $wp_admin_bar ) {

add_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 );

/**
* Check if any plugin, or theme features, are using the Customizer.
*
* @return bool A boolean value indicating if Customizer support is needed.
*/
function gutenberg_site_requires_customizer() {
if ( has_action( 'customize_register' ) ) {
return true;
}

return false;
}

/**
* Tells the script loader to load the scripts and styles of custom block on site editor screen.
*
Expand Down