WordPress.org

Make WordPress Core

Opened 7 weeks 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: Awaiting Review Priority: normal
Severity: major Version: trunk
Component: Posts, Post Types Keywords: has-patch
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 7 weeks ago.
git patch file to fix the issue

Download all attachments as: .zip

Change History (3)

@hughie.molloy
7 weeks ago

git patch file to fix the issue

#1 @SergeyBiryukov
7 weeks ago

  • Component changed from Canonical to Posts, Post Types

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


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

Note: See TracTickets for help on using tickets.