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

Toolbar: Make the 'Edit site' link aware of the current template #4810

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion src/wp-includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,13 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
*
* @since 5.9.0
*
* @global string _wp_current_template_id
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
*
* @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;
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

// Don't show if a block theme is not activated.
if ( ! wp_is_block_theme() ) {
return;
Expand All @@ -436,7 +440,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' )
),
)
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/wp-includes/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ function _add_template_loader_filters() {
* @since 5.8.0
*
* @global string $_wp_current_template_content
* @global string _wp_current_template_id
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
*
* @param string $template Path to the template. See locate_template().
* @param string $type Sanitized filename without extension.
* @param string[] $templates A list of template candidates, in descending order of priority.
* @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;
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

if ( ! current_theme_supports( 'block-templates' ) ) {
return $template;
Expand Down Expand Up @@ -64,6 +65,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