Opened 5 years ago
Last modified 2 years ago
#50447 new defect (bug)
wp_publish_post not checking for unique post slugs
Reported by: | hughie.molloy | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | major | Version: | 5.5 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
When published a post using wp_publish_post no check is done to see if the slug / post_name is unique. This leads to problems with the permalink.
I have attached a patch file to the ticket as I could not make a PR to the github
Steps to reproduce:
Make and publish an article titled 'test'. ID 1
Make and set to draft a second article titled ' test'. ID 2
call wp_publish_post(2)
the post name of articles 1 and 2 are both set to test.
This can be worked around by calling the following code instead:
<?php $post = [ 'ID' => 2, 'post_status' => 'publish', ]; wp_update_post($post);
Attachments (3)
Change History (8)
This ticket was mentioned in PR #355 on WordPress/wordpress-develop by hughiemolloy.
5 years ago
#2
Making sure post name is unique when publishing article with wp_publish_post
When wp_publish_post is called there is no check to see if the slug (post_name) or the post is unique. This leads to multiple posts having the same URL.
Added a call to wp_unique_post_slug and setting the new slug on DB update to publish
Trac ticket: https://core.trac.wordpress.org/ticket/50447
#4
@
4 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
This ticket was mentioned in PR #3480 on WordPress/wordpress-develop by nirav7707.
2 years ago
#5
- Keywords has-unit-tests added; needs-unit-tests removed
- A draft post which have identical title and slug to already publish post, testcase ensure that after changing post status to publish of draft post with wo_publish_post function the slug will be unique with the all available slug in posts table.
Trac ticket: https://core.trac.wordpress.org/ticket/50447
git patch file to fix the issue