Make WordPress Core

Opened 4 years ago

Last modified 19 months ago

#50447 new defect (bug)

wp_publish_post not checking for unique post slugs

Reported by: hughiemolloy's profile 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)

patch.diff (1.2 KB) - added by hughie.molloy 4 years ago.
git patch file to fix the issue
post.php.patch (1.9 KB) - added by niravsherasiya7707 2 years ago.
50447.patch (2.0 KB) - added by niravsherasiya7707 2 years ago.
phpunit test for the patch file submitted by hughie.molloy

Download all attachments as: .zip

Change History (8)

@hughie.molloy
4 years ago

git patch file to fix the issue

#1 @SergeyBiryukov
4 years ago

  • Component changed from Canonical to Posts, Post Types

This ticket was mentioned in PR #355 on WordPress/wordpress-develop by hughiemolloy.


4 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

#3 @SergeyBiryukov
4 years ago

#51427 was marked as a duplicate.

#4 @SergeyBiryukov
4 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

@niravsherasiya7707
2 years ago

phpunit test for the patch file submitted by hughie.molloy

This ticket was mentioned in PR #3480 on WordPress/wordpress-develop by nirav7707.


19 months 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

Note: See TracTickets for help on using tickets.