Opened 11 years ago
Last modified 4 months ago
#35209 new defect (bug)
Permalinks of published pages get changed when creating new pages as a draft
| Reported by: | Asgaros | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Permalinks | Version: | 4.4 |
| Severity: | normal | Keywords: | dev-feedback close has-screenshots |
| Cc: | Focuses: | administration |
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 (6)
#2
@
11 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! :)
#4
@
4 months ago
- Keywords close has-screenshots added; needs-testing removed
Reproduction Report
Environment
- WordPress: 7.0-beta3-61849-src
- PHP: 8.3.30
- Server: nginx/1.29.5
- Database: MySQL 8.4.8
- Browser: Brave
- OS: Ubuntu
- Theme: Twenty Twenty-Five (twentytwentyfive)
- MU Plugins: None
- Plugins: None (first test), Hello Dolly 1.7.2 (second test)
Steps taken
- Created a new page titled "Test 1". Slug was auto-generated as "test-1".
- Changed the slug from "test-1" to "test", then published the page. Page is now live at /test/.
- Created a new page titled "Test 2". Slug was auto-generated as "test-2".
- Changed the slug of "Test 2" from "test-2" to "test". WordPress kept "test" in the slug field without immediately correcting it.
- Clicked "Save Draft". WordPress automatically corrected the slug to "test-2" upon saving.
- Navigated to Pages list and opened "Test 1".
- Slug on "Test 1" still showed "test" - unchanged.
- Added content to "Test 1" and clicked Save/Update. Slug remained "test" after updating.
Result: ❌ Bug is not occurring
Expected behavior
Based on the ticket description, saving "Test 2" as a draft with slug "test"
should have caused "Test 1's" slug to silently change from "test" to "test-2",
stealing the slug from the already published page.
Additional Notes
- Tested first in a clean environment with no plugins active.
- Environment was reset and the test was repeated with Hello Dolly 1.7.2 active.
- In WP 7.0, the slug correction happens at save time - when "test" was typed as the slug for Test 2 and Save Draft was clicked, WordPress saved it as "test-2" in the database, protecting Test 1's slug throughout.
- Both runs produced the same result.
- Removing
needs-testingas the bug does not reproduce in WordPress 7.0-beta3-61849-src. Addingclose- the issue appears fixed in a previous release. Leaving open in case another tester wants to run a second test.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)




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. :)