Make WordPress Core

Opened 8 months ago

Last modified 6 months ago

#59419 new feature request

Revisions page: how to support varying "Go to editor" link templates

Reported by: ramonopoly's profile ramonopoly Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Revisions Keywords:
Focuses: Cc:

Description

For various post types, the Block Editor redirects to admin/revision.php.

The page admin/revision.php has a couple of "Go to editor" links, which open the the current post in the editor.

admin/revision.php builds the link by calling get_edit_post_link(), which uses the link template from post_object->_edit_link.

For most post types, including pages and posts, the _edit_link template looks something like this: post.php?post=%d.

get_edit_post_link() replaces the placeholder %d with the correct post id to build the edit post link.

Each page under Site Editor sidebar contains a link to admin/revision.php for page revisions.

However since the "Go to editor" links are constructed using page_object->_edit_link, they will always link to post editor.

I would expect the links to return me to the editor from which I last came.

The upshot is that we want the _edit_link template to vary depending on the origin of the referring URL. For pages, that means if we're coming from the Site Editor, the return template should be something similar to what the wp_template post object uses, which is site-editor.php?postType=%s&postId=%d&canvas=edit.

The question is "what would be the best way to do this?"

Challenges:

  1. admin/revision.php does not know where the revision is coming from, that is Post Editor vs Site Editor, but we could use some sort of $_GET query param on revisions.php to solve that. E.g., let's call it editor: revision.php?revision=150&editor=site. That is very specific and might be too narrow.
  2. If 1, what then? Whether we grab the query param on the revision page and pass it to get_edit_post_link (thereby changing the function signature), or modify get_edit_post_link to do the lot internally, we'd still have to build the link accordingly to some pattern.
  3. If 2, where would we store that pattern? _edit_link is taken. Maybe a new property on the post object? _edit_site_link or something.

It can be done I think without great fuss using the get_edit_post_link filter. With it we can return whatever we want.

We would just have to come up with migration approach for Core and I'm not sure what the best option would be.

Thank you for considering this issue!

For discussion and context see: https://github.com/WordPress/gutenberg/issues/51343#issuecomment-1724580879

Change History (3)

#1 @ramonopoly
8 months ago

I would expect the links to return me to the editor from which I last came.

Or, as the following Gutenberg issue raises, "return me to the place from which I last came"

https://github.com/WordPress/gutenberg/issues/55082

Maybe there's scope to have a choice to return to some referring URL?

#2 @adamsilverstein
6 months ago

It can be done I think without great fuss using the get_edit_post_link filter. With it we can return whatever we want.

Have you tried this approach?

#3 @ramonopoly
6 months ago

It can be done I think without great fuss using the get_edit_post_link filter. With it we can return whatever we want.

Have you tried this approach?

Thanks for looking at this issue!

I tested it out in Gutenberg, but I wanted to inquire about a path to Core migration before committing to any one approach. Specifically, whether the _edit_link remit needs to be widened.

If folks think that hooking into get_edit_post_link would be also fine to go into Core then I'll move ahead.

Here's how I was testing it in Gutenberg.

function gutenberg_update_get_edit_post_link_page_from_site_editor( $link, $post_id ) {
	$post = get_post( $post_id );

	if ( 'page' === $post->post_type && 'revision' === get_current_screen()->base && isset( $_GET['editor'] ) ) {
		if ( 'site' === sanitize_text_field( $_GET['editor'] ) ) {
			$post_edit_link = 'site-editor.php?' . build_query(
					array(
						'postType' => '%s',
						'postId'   => '%s',
						'canvas'   => 'edit',
					)
				);
			return admin_url( sprintf( $post_edit_link, $post->post_type, $post_id ) );;
		}
	}

	return $link;
}
add_filter( 'get_edit_post_link', 'gutenberg_update_get_edit_post_link_page_from_site_editor', 10, 2 );

Source: https://github.com/WordPress/gutenberg/issues/51343#issuecomment-1709513348

Note: See TracTickets for help on using tickets.