From 5a90a574aa9e5c7c8e64b3ad542cf40c9c8ff428 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 23 Nov 2020 09:00:14 +0200 Subject: [PATCH] Replace adminbar customize link with site-editor in FSE themes (#27135) * Remove the adminbad Customizer link * add FSE condition * rename function * Add site-editor link * Change wording * Check if user can edit_theme_options --- lib/full-site-editing.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/full-site-editing.php b/lib/full-site-editing.php index ddd835cd5b44f..059b39ccb971f 100644 --- a/lib/full-site-editing.php +++ b/lib/full-site-editing.php @@ -57,6 +57,38 @@ function gutenberg_remove_legacy_pages() { add_action( 'admin_menu', 'gutenberg_remove_legacy_pages' ); +/** + * Removes legacy adminbar items from FSE themes. + * + * @param WP_Admin_Bar $wp_admin_bar The admin-bar instance. + */ +function gutenberg_adminbar_items( $wp_admin_bar ) { + + // Early exit if not an FSE theme. + if ( ! gutenberg_is_fse_theme() ) { + 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' ); + + // Add site-editor link. + if ( ! is_admin() && current_user_can( 'edit_theme_options' ) ) { + $wp_admin_bar->add_node( + array( + 'id' => 'site-editor', + 'title' => __( 'Edit site', 'gutenberg' ), + 'href' => admin_url( 'admin.php?page=gutenberg-edit-site' ), + ) + ); + } +} + +add_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 ); + /** * Activates the 'menu_order' filter and then hooks into 'menu_order' */