Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Minor adjustments
  • Loading branch information
Mamaduka committed Nov 8, 2021
commit 21656838ab186acef34363369cdaf721a62b36a0
8 changes: 4 additions & 4 deletions lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ function gutenberg_resolve_template_for_new_post( $wp_query ) {
function gutenberg_get_edit_template_link( $link, $post_id ) {
$post = get_post( $post_id );

if ( 'wp_template' !== $post->post_type && 'wp_template_part' !== $post->post_type ) {
if ( ! in_array( $post->post_type, array( 'wp_template', 'wp_template_part' ), true ) ) {
return $link;
}

$template = _build_block_template_result_from_post( $post );

if ( ! $template ) {
if ( is_wp_error( $template ) ) {
return $link;
}

$id = urlencode( $template->id );
$edit_link = 'themes.php?page=gutenberg-edit-site&postId=%1$s&postType=%2$s';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use build_query to build $edit_link?
cc @Mamaduka

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a simple enough query that there's no need to use build_query or add_query_arg.

P.S. In the future, this path can be a part of a post type of object via the _edit_link argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a library function for building queries, and it feels like we are inventing the wheel here.
But I'm not going to insist we need to change it because we encode the request parameters (as it should be).


return "themes.php?page=gutenberg-edit-site&postId=$id&postType=$template->type";
return admin_url( sprintf( $edit_link, urlencode( $template->id ), $template->type ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core function uses admin_url as well instead of the path - https://developer.wordpress.org/reference/functions/get_edit_post_link/

}
add_filter( 'get_edit_post_link', 'gutenberg_get_edit_template_link', 10, 2 );