Skip to content

Commit

Permalink
Fix the site editor Admin Bar menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 22, 2024
1 parent c70633d commit 4800258
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lib/compat/wordpress-6.6/admin-bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Changes to the WordPress admin bar.
*
* @package gutenberg
*/

/**
* Adds the "Site Editor" link to the Toolbar.
*
* @since 5.9.0
* @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar.
* @since 6.6.0 Added the canvas argument to the url.
*
* @global string $_wp_current_template_id
*
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
*/
function gutenberg_admin_bar_edit_site_menu( $wp_admin_bar ) {
global $_wp_current_template_id;

// Don't show if a block theme is not activated.
if ( ! wp_is_block_theme() ) {
return;
}

// Don't show for users who can't edit theme options or when in the admin.
if ( ! current_user_can( 'edit_theme_options' ) || is_admin() ) {
return;
}

$wp_admin_bar->remove_node( 'site-editor' );
$wp_admin_bar->add_node(
array(
'id' => 'site-editor',
'title' => __( 'Site Editor' ),
'href' => add_query_arg(
array(
'postType' => 'wp_template',
'postId' => $_wp_current_template_id,
'canvas' => 'edit',
),
admin_url( 'site-editor.php' )
),
)
);
}

add_action( 'admin_bar_menu', 'gutenberg_admin_bar_edit_site_menu', 41 );

Check failure on line 49 in lib/compat/wordpress-6.6/admin-bar.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 newline at end of file; 0 found
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.5/script-loader.php';

// WordPress 6.6 compat.
require __DIR__ . '/compat/wordpress-6.6/admin-bar.php';
require __DIR__ . '/compat/wordpress-6.6/compat.php';
require __DIR__ . '/compat/wordpress-6.6/resolve-patterns.php';
require __DIR__ . '/compat/wordpress-6.6/block-bindings/pattern-overrides.php';
Expand Down

0 comments on commit 4800258

Please sign in to comment.