WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 7 weeks 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 needs-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 (1)

patch.diff (1.2 KB) - added by hughie.molloy 6 months ago.
git patch file to fix the issue

Download all attachments as: .zip

Change History (5)

@hughie.molloy
6 months ago

git patch file to fix the issue

#1 @SergeyBiryukov
5 months ago

  • Component changed from Canonical to Posts, Post Types

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


5 months ago

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
7 weeks ago

#51427 was marked as a duplicate.

#4 @SergeyBiryukov
7 weeks ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
Note: See TracTickets for help on using tickets.