Skip to content

Commit

Permalink
Toolbar: Make the 'Edit site' link aware of the current template
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 7, 2023
1 parent d113821 commit f723f97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/wp-includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
*/
function wp_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;
Expand All @@ -436,7 +438,7 @@ function wp_admin_bar_edit_site_menu( $wp_admin_bar ) {
array(
'id' => 'site-editor',
'title' => __( 'Edit site' ),
'href' => admin_url( 'site-editor.php' ),
'href' => add_query_arg( array( 'postType' => 'wp_template', 'postId' => $_wp_current_template_id ), admin_url( 'site-editor.php' ) ),
)
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function _add_template_loader_filters() {
* @return string The path to the Site Editor template canvas file, or the fallback PHP template.
*/
function locate_block_template( $template, $type, array $templates ) {
global $_wp_current_template_content;
global $_wp_current_template_content, $_wp_current_template_id;

if ( ! current_theme_supports( 'block-templates' ) ) {
return $template;
Expand Down Expand Up @@ -64,6 +64,8 @@ function locate_block_template( $template, $type, array $templates ) {
$block_template = resolve_block_template( $type, $templates, $template );

if ( $block_template ) {
$_wp_current_template_id = $block_template->id;

if ( empty( $block_template->content ) && is_user_logged_in() ) {
$_wp_current_template_content =
sprintf(
Expand Down

0 comments on commit f723f97

Please sign in to comment.