From 6fc3060a4ed29cf8666c5c1243eb3968ee11d401 Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Tue, 11 Jul 2023 11:33:27 +0000 Subject: [PATCH] Toolbar: Make the 'Edit site' link open the editor with the current template. Adds a global, `$_wp_current_template_id`, to allow the 'Edit site' link in the admin bar to be aware of the current template and pass it to the Site Editor, so it can load the appropriate one directly. See https://github.com/WordPress/gutenberg/issues/37850 for further discussion. Props Mamaduka, poena, abitofmind, audrasjb, mikinc860, alexstine, annezazu, beckej, jameskoster, bacoords, clubkert, paaljoachim, get_dave, priethor, skorasaurus. Fixes #58746. Built from https://develop.svn.wordpress.org/trunk@56209 git-svn-id: http://core.svn.wordpress.org/trunk@55721 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 13 ++++++++++++- wp-includes/block-template.php | 6 +++++- wp-includes/version.php | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index ee0a88cb8e..4ab5302fd9 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -419,9 +419,14 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) { * * @since 5.9.0 * + * @global string $_wp_current_template_id + * @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the 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; @@ -436,7 +441,13 @@ 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' ) + ), ) ); } diff --git a/wp-includes/block-template.php b/wp-includes/block-template.php index 728523e586..794aec9120 100644 --- a/wp-includes/block-template.php +++ b/wp-includes/block-template.php @@ -23,8 +23,10 @@ function _add_template_loader_filters() { * Internally, this communicates the block content that needs to be used by the template canvas through a global variable. * * @since 5.8.0 + * @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar. * * @global string $_wp_current_template_content + * @global string $_wp_current_template_id * * @param string $template Path to the template. See locate_template(). * @param string $type Sanitized filename without extension. @@ -32,7 +34,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; @@ -64,6 +66,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( diff --git a/wp-includes/version.php b/wp-includes/version.php index 8cdf256d1b..3fe41ed651 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-beta3-56208'; +$wp_version = '6.3-beta3-56209'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.