Make WordPress Core

Opened 11 years ago

Last modified 8 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.

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 11 years ago.
35209.2.patch​ (1.3 KB ) - added by Asgaros 11 years ago.

Download all attachments as: .zip

Change History (6)

#1 @Asgaros
11 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. :)

#2 @Asgaros
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! :)

#3 @Asif2BD
11 years ago

  • Keywords needs-testing dev-feedback added

#4 @gaisma22
8 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

  1. Created a new page titled "Test 1". Slug was auto-generated as "test-1".
  2. Changed the slug from "test-1" to "test", then published the page. Page is now live at /test/.
  3. Created a new page titled "Test 2". Slug was auto-generated as "test-2".
  4. Changed the slug of "Test 2" from "test-2" to "test". WordPress kept "test" in the slug field without immediately correcting it.
  5. Clicked "Save Draft". WordPress automatically corrected the slug to "test-2" upon saving.
  6. Navigated to Pages list and opened "Test 1".
  7. Slug on "Test 1" still showed "test" - unchanged.
  8. 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

  1. Tested first in a clean environment with no plugins active.
  2. Environment was reset and the test was repeated with Hello Dolly 1.7.2 active.
  3. 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.
  4. Both runs produced the same result.
  5. Removing needs-testing as the bug does not reproduce in WordPress 7.0-beta3-61849-src. Adding close - the issue appears fixed in a previous release. Leaving open in case another tester wants to run a second test.

Screenshots/Screencast with results

https://i.ibb.co/8gGqmn04/02-test1-published-at-test.png

https://i.ibb.co/6Jsvw3vN/03-test2-slug-set-to-test.png

https://i.ibb.co/SWzpvm6/04-test2-draft-saved-slug-corrected-to-test2.png

Note: See TracTickets for help on using tickets.