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.
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)
Change History (5)
#2
@
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! :)
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:
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. :)