WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 10 months ago

#35209 new defect (bug)

Permalinks of published pages get changed when creating new pages as a draft

Reported by: Asgaros Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Permalinks Keywords: needs-testing dev-feedback
Focuses: administration Cc:

Description

While looking over ticket #35197 I found some other strange behavior where a permalink of a published page will be overwritten by a newly created draft page.

Here are the steps to reproduce it (4.4/trunk):

Step 1

Add a new page with the title "Test 1". When switching to the editor, a permalink is generated:
http://your-site.com/test-1/

Step 2

Click the Edit button next to the generated permalink, change the permalink from "test-1" to "test", click OK and click the Publish button to publish the newly created page.

Step 3

Add a new page with the title "Test 2". When switching to the editor, a permalink is generated:
http://your-site.com/test-2/

Step 4

Click the Edit button next to the generated permalink, change the permalink from "test-2" to "test" and click OK. The permalink gets changed back to test-2 correctly because the already published Test 1 page is using test as a permalink.

Step 5

Click the Save Draft button to save the Test 2 page as a draft. Do NOT publish it!

Step 6

Switch to the "All pages" area and open the Test 1 edit page.

Step 7

SURPRISE! The permalink of the already published page Test 1 changed from "test" to "test-2".

Curiously when you hover the permalink it still uses the correct "test" permalink.

http://fs5.directupload.net/images/151223/r6gqvcph.png

Step 8

Okay, now lets change something at the site. Add some text for example and click the Update button.

After Step 8 the permalink of the Test 1 page gets changed to "test-2" while the Test 2 page is using the "test" permalink now.

There should be a patch for this because permalinks of already published pages can easily get changed when you are not aware of this problem. The main issue is that in this case all incoming links from third-party websites will not link to the correct page anymore.

Attachments (2)

35209.1.patch (457 bytes) - added by Asgaros 4 years ago.
35209.2.patch (1.3 KB) - added by Asgaros 4 years ago.

Download all attachments as: .zip

Change History (5)

@Asgaros
4 years ago

#1 @Asgaros
4 years ago

I think I found a first solution for this.

In Step 4 after clicking the OK button, the permalink gets changed back to test-2 correctly because the already published Test 1 page is using test as a permalink. BUT the Slug input field (ID: #post_name) is not set to the correct value:

http://fs5.directupload.net/images/151224/wxdhg7pd.png

So when you save the page as a draft, the permalink gets incorrectly saved as test in the database.

I have uploaded a first patch (35209.1.patch) which will set the Slug input field to the correct value when doing the actions described in step 4.

But it is still possible to set the value of the Slug input field to the value "test" manually. When you save the page as a draft after it, the value will not changed to a correct "test-2" value, so we still need a little bit more work for a good solution to this problem. :)

@Asgaros
4 years ago

#2 @Asgaros
4 years ago

I extended the patch a little bit to make sure that the post slug for drafts/pending posts will be unique too.

There are already some similar approaches in:

  • wp-admin\includes\ajax-actions.php (around line 1651 in trunk)
  • wp-admin\includes\post.php (around line 1218 in trunk)

Some testing would be greatly appreciated! :)

#3 @Asif2BD
4 years ago

  • Keywords needs-testing dev-feedback added
Note: See TracTickets for help on using tickets.