Make WordPress Core

Opened 16 months ago

Closed 14 months ago

Last modified 14 months ago

#57709 closed defect (bug) (fixed)

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

Reported by: andraganescu's profile andraganescu Owned by: davidbaumwald's profile davidbaumwald
Milestone: 6.3 Priority: normal
Severity: blocker Version:
Component: Revisions Keywords: has-patch dev-reviewed commit
Focuses: ui Cc:


In 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").

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


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.

I've put this for 6.2 since it is a blocker for #57704

Change History (27)

#1 @audrasjb
16 months ago

  • Keywords needs-patch added

Hello @andraganescu, if we want to fix this issue in 6.2, we'll have to get a patch ready in the next few hours, because #57704 is an enhancement and should even be in the milestone anymore (we're one week pas beta 1).

#2 @andraganescu
16 months ago

  • Milestone changed from 6.2 to 6.3

Hi @audrasjb

I’ve looked into this and:

  • the links are wrong because template and template part CPTs do not have the internal _edit_link set when they get registered
  • the shape of an _edit_link is completely different from that of posts or pages - for example site-editor.php?postId=twentytwentythree//header&action=edit&canvas=edit&path=/template-parts/single&postType=wp_template_part
  • get_edit_post_link needs some multiple lines to accommodate this

This is hardly justified to rush and has the potential to break WP admin :)

This ticket was mentioned in PR #4212 on WordPress/wordpress-develop by @andraganescu.

16 months ago

  • Keywords has-patch added; needs-patch removed

@ocean90 commented on PR #4212:

16 months ago

@draganescu You have to use a fork since branches get auto-deleted on each sync.

@andraganescu commented on PR #4212:

16 months ago

Ooops I missed that part! Thank you @ocean90

@andraganescu commented on PR #4229:

16 months ago

Thanks for the review @spacedmonkey I've committed all your suggestions, will check to see how it works now.

@andraganescu commented on PR #4229:

15 months ago

Applied @anton-vlasenko 's feedback as well. @azaozz had some concerns over how we're using slugs initially. In light of #49164 I don't know if this fix should land or some new way of solving the problem with posts existing on disk 1st should be thought of? cc @youknowriad

@youknowriad commented on PR #4229:

15 months ago

Personally, I think a fix like this PR or similar is the way to go. Reverting to using auto-drafts and all for template and template parts is way too impactful and it's not clear how it would solve the initial issues we had with that approach.

@andraganescu commented on PR #4229:

15 months ago

I fixed the failing tests, let me know if there is anything else needed for this patch to land 🙏🏻

#11 @andraganescu
15 months ago

  • Focuses ui added
  • Keywords dev-reviewed added

#12 @antonvlasenko
15 months ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested:


  • WordPress: 6.3-alpha-55505-src
  • PHP: 8.0.27
  • Server: Apache/2.4.55 (Unix) PHP/8.0.27
  • Database: mysqli (Server: 5.7.38 / Client: mysqlnd 8.0.27)
  • Browser: Safari 16.4 (macOS)
  • Theme: Twenty Twenty-Two - 1.2
  • MU-Plugins: None activated
  • Plugins:
    • Gutenberg 15.5.1

Steps to Reproduce

  1. Enable Gutenberg.
  2. Go to the Editor, create your own template part.
  3. Modify your template by adding a paragraph block, then add another paragraph block, and save it multiple times.
  4. Open the "Template" tab, click on the "X Revisions" link as shown in the screenshot below:

  1. In the header, click on the links in the header (as shown below):

Expected Results

  1. ✅ The links should take you back to the "Edit template" page.

Actual Results

  1. ❌ The links don't work. Nothing happens when I click on them.

After applying the patch

  1. ✅ The links take you back to the Edit template page.

Additional Notes

  • I have only tested the template parts functionality.

@ramonopoly commented on PR #4229:

14 months ago

Thanks for working on this bug. I started without seeing this one.

We could probably add some tests as well.

I have some here: if you want to pull them across.

#14 @ramonopoly
14 months ago

Might be worth adding tests for get_edit_post_link()

I couldn't find any. I added some to cover the expected functionality over in if you want to pull them across.

#15 @ramonopoly
14 months ago


  • WordPress 6.3-alpha-55505-src
  • Gutenberg Version 15.6.0-rc.1

Can confirm the edit links work for template and template parts

Post and page edit links work as before.

@andraganescu commented on PR #4229:

14 months ago

@ramonjd I included the tests you added 👏🏻 , the edit link for the global styles post type and the comment update. I didn;t understand what you asked about context and encoding ampersand.

@anton-vlasenko not sure if these additions require new testing if the tests pass 🙏🏻

@andraganescu commented on PR #4229:

14 months ago

The tests don't pass :)) will check them out.

@andraganescu commented on PR #4229:

14 months ago

Hmm. Still not fixed the new tests. Will loop back on this.

#19 @andraganescu
14 months ago

  • Keywords commit added

@antonvlasenko said:

Thanks for working on this, @draganescu.
The code looks good to me.

Not sure why Trac didn't pick it up :P

#20 @ironprogrammer
14 months ago

Adding additional test results as a confidence check re: comment:16 👍🏻

Test Report

Patch tested:


  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 13.3.1
  • Browser: Safari 16.4
  • Server: nginx/1.23.4
  • PHP: 7.4.33
  • WordPress: 6.3-alpha-55505-src
  • Theme: twentytwentythree v1.1
  • Active Plugins:
    • gutenberg v15.6.0-rc.2

Actual Results

  • ✅ The "Go to editor" and template links on revisions page navigate back to the editor screen.
  • ✅ PHPunit tests pass (see comment:18).

Supplemental Artifacts

Before Patch After Patch

annezazu commented on PR #4229:

14 months ago

Where are we at here? It's holding up my ability to test this more broadly in the FSE Outreach Program and, with all of the work on revisions, I want to ensure we get some solid feedback!

@andraganescu commented on PR #4229:

14 months ago

I think it just needs someone to commit it.

annezazu commented on PR #4229:

14 months ago

@ironprogrammer could you perhaps help here?

#24 @davidbaumwald
14 months ago

  • Owner set to davidbaumwald
  • Status changed from new to reviewing

#25 @davidbaumwald
14 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 55743:

Revisions: Add edit link functionality for the wp_template and wp_template_part post types.

In preparation for viewing revisions of templates and template parts in the editor, this set changes adds the _edit_link argument when registering the wp_template and wp_template_part post types. This commit also updates get_edit_post_link to account for the unique edit URLs for these post types.

Finally, this commit also adds new unit tests for the get_edit_post_link function, including tests for the post, wp_template, and wp_template_part post types.

Fixes #57709.
Props andraganescu, spacedmonkey, antonvlasenko, youknowriad, ramonopoly, ironprogrammer, annezazu.

@andraganescu commented on PR #4229:

14 months ago

Thank you @dream-encode !

Note: See TracTickets for help on using tickets.