WordPress.org

Make WordPress Core

Ticket #9726: 9726.2.diff

File 9726.2.diff, 3.3 KB (added by ryan, 4 years ago)
  • wp-includes/post.php

     
    17361736 * @param integer $post_parent 
    17371737 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 
    17381738 */ 
    1739 function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) { 
     1739function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type = '', $post_parent = '') { 
    17401740        global $wpdb, $wp_rewrite; 
    1741         if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) { 
    1742                 $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page', 'attachment')); 
    1743                 if ( in_array($post_type, $hierarchical_post_types) ) { 
    1744                         $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode("', '", $wpdb->escape($hierarchical_post_types)) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 
    1745                         $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); 
    1746                 } else { 
    1747                         $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1"; 
    1748                         $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent)); 
    1749                 } 
    17501741 
    1751                 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 
    1752                         $suffix = 2; 
    1753                         do { 
    1754                                 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 
    1755                                 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent)); 
    1756                                 $suffix++; 
    1757                         } while ($post_name_check); 
    1758                         $slug = $alt_post_name; 
    1759                 } 
     1742        if ( in_array( $post_status, array( 'draft', 'pending' ) ) ) 
     1743                return $slug; 
     1744         
     1745        $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type != 'revision' AND post_status != 'draft' AND ID != %d LIMIT 1"; 
     1746        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); 
     1747 
     1748        if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 
     1749                $suffix = 2; 
     1750                do { 
     1751                        $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 
     1752                        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); 
     1753                        $suffix++; 
     1754                } while ($post_name_check); 
     1755                $slug = $alt_post_name; 
    17601756        } 
     1757 
    17611758        return $slug; 
    17621759} 
    17631760 
     
    24522449        else 
    24532450                $post_name = sanitize_title($post_name); 
    24542451 
    2455         // expected_slashed ($post_name) 
    2456         $post_name_check = $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1", $post_name, $post_ID ) ); 
     2452        $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); 
    24572453 
    2458         if ( $post_name_check ) { 
    2459                 $suffix = 2; 
    2460                 while ( $post_name_check ) { 
    2461                         $alt_post_name = $post_name . "-$suffix"; 
    2462                         // expected_slashed ($alt_post_name, $post_name) 
    2463                         $post_name_check = $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1", $alt_post_name, $post_ID ) ); 
    2464                         $suffix++; 
    2465                 } 
    2466                 $post_name = $alt_post_name; 
    2467         } 
    2468  
    24692454        if ( empty($post_date) ) 
    24702455                $post_date = current_time('mysql'); 
    24712456        if ( empty($post_date_gmt) ) 
     
    37763761 
    37773762                add_filter('the_preview', '_set_preview'); 
    37783763        } 
    3779 } 
     3764} 
     3765 No newline at end of file