[wp-trac] [WordPress Trac] #51427: wp_publish_post function does not check for unique postname in database
WordPress Trac
noreply at wordpress.org
Thu Oct 15 13:12:40 UTC 2020
#51427: wp_publish_post function does not check for unique postname in database
-------------------------------+-----------------------------
Reporter: mihirgosai | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Posts, Post Types | Version: 5.5.1
Severity: major | Resolution: duplicate
Keywords: | Focuses: administration
-------------------------------+-----------------------------
Changes (by SergeyBiryukov):
* keywords: dev-feedback =>
* status: new => closed
* resolution: => duplicate
* milestone: Awaiting Review =>
Old description:
> If we use wp_publish_post function to change status of post, it does not
> check for unique postname (slug) from database. It can end up having two
> or more posts with same postname (slug).
>
> Solution is to use code as below in wp-includes/post.php:
> (function name: wp_publish_post)
>
> $post->post_name = wp_unique_post_slug($post->post_name, $post->ID,
> 'publish', $post->post_type, $post->post_parent);
>
> $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish',
> 'post_name' => $post->post_name), array( 'ID' => $post->ID ) );
New description:
If we use wp_publish_post function to change status of post, it does not
check for unique postname (slug) from database. It can end up having two
or more posts with same postname (slug).
Solution is to use code as below in wp-includes/post.php:
(function name: wp_publish_post)
{{{
$post->post_name = wp_unique_post_slug($post->post_name, $post->ID,
'publish', $post->post_type, $post->post_parent);
$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish',
'post_name' => $post->post_name), array( 'ID' => $post->ID ) );
}}}
--
Comment:
Hi there, welcome to WordPress Trac!
Thanks for the report, we're already tracking this issue in #50447.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51427#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list