WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #38928, comment 3


Ignore:
Timestamp:
11/30/2016 07:49:24 AM (5 years ago)
Author:
westonruter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #38928, comment 3

    initial v1  
    2121There are two fixes we can consider here, which aren't mutually exclusive:
    2222
    23 For one, the logic for `wp_unique_post_slug()` can be changed to explicitly ignore `auto-draft` posts when it is doing the lookup to see if a slug is already being used. This seems like a no-brainer:
    24 
    25 {{{#!diff
    26 --- src/wp-includes/post.php
    27 +++ src/wp-includes/post.php
    28 @@ -3673,7 +3673,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
    29  
    30         if ( 'attachment' == $post_type ) {
    31                 // Attachment slugs must be unique across all types.
    32 -               $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
    33 +               $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' post_name = %s AND ID != %d LIMIT 1";
    34                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
    35  
    36                 /**
    37 }}}
     23For one, the logic for `wp_unique_post_slug()` can be changed to explicitly ignore `auto-draft` posts when it is doing the lookup to see if a slug is already being used. This seems like a no-brainer: [attachment:38928.2.diff]
    3824
    3925The second fix would be specifically to account for when we allow starter content to be applied on existing sites. Namely, when we do our lookup to see if there are existing auto-draft posts in the current customized state that have the given slugs… we could expand this to see if there are any non-auto-draft posts _outside_ the customized state which already have those slugs, and then re-use them instead of inserting new auto-drafts.