WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#32954 closed defect (bug) (fixed)

"View post" link should not change when sample permalink changes

Reported by: johnbillion Owned by: johnbillion
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.2
Component: Posts, Post Types Keywords: has-patch
Focuses: administration Cc:

Description

This is a follow-up to #16477 which was fixed in 3.9 but has re-appeared.

To reproduce:

  • Go to edit a post
  • Change the permalink
  • Click on "View post" and you get a 404 because the href has been changed to the new sample permalink but the post hasn't been updated yet

The "View post" link should always point to the permalink of the currently saved post.

r27508 was the initial fix. Need to find out where the regression occurred.

Attachments (1)

32954.diff (1.7 KB) - added by boonebgorges 6 years ago.

Download all attachments as: .zip

Change History (5)

#2 @boonebgorges
6 years ago

  • Keywords has-patch added; needs-patch removed

The reasoning behind [32002] was to make View Post point to a pretty permalink for scheduled posts; get_permalink() only returns a pretty permalink for posts with post_status=publish. The error in that changeset was to trust the $post_name variable, which is the *updated* post slug, rather than the one stored in the database. As you suggest, the saved slug should always be used.

See 32954.diff, where I suggest using $post->post_name rather than $post_name in the str_replace() that generates the pretty permalink. I put in a special case if ( 'publish' === $post->post_status ) { $pretty_permalink = get_permalink( $post ); }; I'm pretty sure this is equivalent to the str_replace() in the else clause, but perhaps it makes it a bit clearer what's going on.

@johnbillion Does this seem right to you?

@boonebgorges
6 years ago

#3 @johnbillion
5 years ago

  • Milestone changed from Awaiting Review to 4.4

#4 @johnbillion
5 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 33773:

Don't change the View Post button permalink in the sample permalink HTML when updating the slug on a published or future post.

Fixes #32954
Props boonebgorges, johnbillion

Note: See TracTickets for help on using tickets.