Opened 9 years ago
Last modified 8 days ago
#40588 new defect (bug)
Trashing and restoring a draft post replaces the slug
| Reported by: | TJNowell | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Posts, Post Types | Version: | 4.5 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Using the latest version of WordPress, if you create a draft post with a slug, lets say 'test-post', then trash it and restore it, the slug becomes
__trashed-xxx, where xxx is a number
Related to https://core.trac.wordpress.org/ticket/11863
Attachments (2)
Change History (11)
#3
@
9 years ago
I could reproduce the issue in 4.7.4. I created two posts entitled "40588 Test" and "40588 Test 2" and saved them both as Draft. After trashing and restoring the permalinks changed to "__trashed" and "__trashed-2" respectively. Means this holds true for 4.7.4 as well and not specific to version 4.5.
However, there is always a chance of WordPress replacing slugs of trashed posts after restoration because it has to check whether the same permalink (which the restored post originally had) is already present with other posts. For a huge database it would be resource consuming to search the entire WP_Posts table and then come up with a relevant permalink based on its title. It is always a better option for the admin to edit the permalink once it is restored.
Nevertheless, the permalink could be replaced in a better fashion after restoration like post_id-restored (e.g. 786-restored) if suggesting one is not the best option.
When trashed WordPress is actually replacing the permalink to __trashed-xx, so it would not be very unlikely that when it is restored WordPress does the same thing for one more time to make it like I mentioned.
#6
@
10 months ago
Still present in 6.9. Had not seen it myself for 9 years, but my editors on 2 different sites started complaining about this recently.
I'm no developer, the only help I can offer is testing.
This ticket was mentioned in PR #13814 on WordPress/wordpress-develop by @sawf1y.
8 days ago
#7
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
Fixed bug when posts with slugs like "trashed-X" left with these slugs after recovering/untrashing. Covered with tests
Trac ticket: 40588
@sawf1y commented on PR #13814:
8 days ago
#8
Unnecessary files ended up in the branch.
This ticket was mentioned in PR #13815 on WordPress/wordpress-develop by @sawf1y.
8 days ago
#9
Fixed bug with trashed-X slug
Trac ticket: 40588
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I was able to recreate the issue. It seems to happen with drafts that were never published before. I think that it might come from the fact that when the post is trashed the actual slug is saved in a meta '_wp_desired_post_slug' so it gets restored after. However if the post was never published, the slug isn't set and an empty string is saved in '_wp_desired_post_slug'. Then when restoring, we have the following:
With an empty string being saved in '_wp_desired_post_slug' the condition never evaluates to true and restores the slug.