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

Links to the editor don't work for template and template parts revisions in the revisions screen #48065

Closed
draganescu opened this issue Feb 14, 2023 · 14 comments · Fixed by #50563
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended

Comments

@draganescu
Copy link
Contributor

In #45215 the template and template part editors gained a button that links to the revisions screen for the edited template and template part.

The problem is that in the revisions screen there are two links that should link back to the editor which don't work (one with the template name and another one with the text "go to editor").

Screenshot 2023-02-14 at 12 17 19

In the post editor (block editor) going to the revisions screen will set these links to a shape of:

/wp-admin/post.php?post=3594&action=edit

In the template editor going to the revisions screen will set these links to a shape of:

/wp-admin/revision.php?revision=4068&gutenberg=true, which is the URI of the revisions screen itself.

This is a blocker for https://core.trac.wordpress.org/ticket/57704
There is a corresponding core ticket at https://core.trac.wordpress.org/ticket/57709

@draganescu draganescu added [Type] Bug An existing feature does not function as intended [Feature] Template Editing Mode Related to the template editor available in the Block Editor labels Feb 14, 2023
@tomdevisser
Copy link
Member

@draganescu Sorry, newbie question maybe, but where do I even find the revision screen for template parts? I tried to recreate this issue on my end with both the Gutenberg plugin activated and deactivated, but I can't seem to find the revision screen for templates or template parts.

@draganescu
Copy link
Contributor Author

@thomasdevisser

  • running trunk
  • open a template and do an edit, save
  • refresh the page do another edit, save
  • refresh the page and open the settings sidebar
  • notice the revisions button (should say 2 revisions)
  • click it
  • you'll end up in the revision screen
how-to-get-to-revisions.mp4

@tomdevisser
Copy link
Member

Thank you @draganescu. It looks like the issue is that the entire href is missing on both these anchor tags. That's why you're seeing the URI of the screen you're already on.

Screenshot 2023-02-14 at 3 10 11 PM

@tomdevisser
Copy link
Member

On further inspection, in core, get_edit_post_link() in wp-admin/revision.php returns an empty string. I will try to find a fix for this.

@tomdevisser
Copy link
Member

tomdevisser commented Feb 14, 2023

In the WP_Post_Type object of templates, it seems the _edit_link property is set to an empty string. The reason for this is found in wp-includes/class-wp-post-type.php:

// If there's no specified edit link and no UI, remove the edit link.
if ( ! $args['show_ui'] && ! $has_edit_link ) {
	$args['_edit_link'] = '';
}

The actual edit URI should be /wp-admin/site-editor.php?postId=twentytwentythree%2F%2Fcomments&canvas=edit&path=%2Ftemplate-parts%2Fsingle&postType=wp_template_part.

So to fix this issue we could go in two directions:

  • We could add an extra check in wp-includes/link-template.php, to see if the post type is wp_template_part, and if so, set the correct _edit_link. I couldn't find a way to retrieve the values for the postId and path URL params, but this could solve the issue. I don't know if it's the best solution, though.
    /wp-includes/link-template.php:get_edit_post_link
if ( $post_type_object->_edit_link ) {
    $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
} elseif ( 'wp_template_part' === $post_type_object->name ) {
    $link = '/wp-admin/site-editor.php?postType=wp_template_part&canvas=edit&';
    // postId = twentytwentythree%2F%2Fcomments
    // path = %2Ftemplate-parts%2Fsingle
} else {
    $link = '';
}
  • We could add the _edit_link explicitly during the creation of a new wp_template_part post. In this case however, if the link changes, every template post has the link hardcoded as a "custom" edit link so I would suggest the first solution.

This should therefore probably be moved to the wordpress-develop GitHub, but I'm not sure as I'm also new here. 🙂

@draganescu
Copy link
Contributor Author

@thomasdevisser you are right it would be easier to patch core directly for this and to try a PR in the wordpress-develop GitHub.

Also thank you for investigating, yes I as well believe we need to:

  • add the _edit_link explicitly during the creation of a new wp_template_part and wp_template CPTs, just like post and page CPTs have
  • update /wp-includes/link-template.php:get_edit_post_link to parse the format of _edit_link and put in the correct slug, id etc.

@ramonjd
Copy link
Member

ramonjd commented Apr 13, 2023

I'm looking at global styles revisions and have come across this and the first revision bug as well.

I've been looking at the suggestion above and I've nearly got it working:

Just checking if there's been any progress. If not I can carry on 😄

I also wondered whether it might be a decent fallback to send the edit link in the URL params, given that Gutenberg site-editor.php links could change ?

ramonjd added a commit to ramonjd/wordpress-develop that referenced this issue Apr 13, 2023
@annezazu annezazu added the [Priority] High Used to indicate top priority items that need quick attention label Apr 17, 2023
@annezazu
Copy link
Contributor

This entirely breaks the experience. Noting this as high priority to fix and adding to the phase 2 board. Can someone indicate whether they will be taking this on to resolve?

ramonjd added a commit to ramonjd/wordpress-develop that referenced this issue Apr 17, 2023
@ramonjd
Copy link
Member

ramonjd commented Apr 18, 2023

Looks like there's an existing fix at WordPress/wordpress-develop#4229

@dsas
Copy link
Contributor

dsas commented May 11, 2023

The existing fix got merged upstream @ramonjd. Given 6.3 won't be released until August will GB get patched to fix the broken revisions screen before then?

@draganescu
Copy link
Contributor Author

I think it should be yes, but not sure how.

@annezazu
Copy link
Contributor

@hellofromtonya is this something you can help with?

@ramonjd
Copy link
Member

ramonjd commented May 11, 2023

It should be doable using a combo of register_post_type_args and get_edit_post_link filters - I can take a crack today if I get time. Will report back if I don't 😄

@ramonjd
Copy link
Member

ramonjd commented May 12, 2023

Backport here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants