Make WordPress Core

Ticket #9726: 9726.3.diff

File 9726.3.diff, 4.2 KB (added by Denis-de-Bernardy, 17 years ago)
  • wp-includes/post.php

     
    17371737 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
    17381738 */
    17391739function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
     1740        if ( in_array( $post_status, array( 'draft', 'pending' ) ) )
     1741                return $slug;
     1742       
    17401743        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));
     1744        $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page'));
     1745        if ( $post_status == 'inherit' ) {
     1746                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1";
     1747                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID));
     1748               
     1749                if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
     1750                        $suffix = 2;
     1751                        do {
     1752                                $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";
     1753                                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID));
     1754                                $suffix++;
     1755                        } while ($post_name_check);
     1756                        $slug = $alt_post_name;
    17491757                }
    1750 
     1758        } elseif ( in_array($post_type, $hierarchical_post_types) ) {
     1759                $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";
     1760                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent));
     1761               
    17511762                if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
    17521763                        $suffix = 2;
    17531764                        do {
    17541765                                $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));
     1766                                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent));
    17561767                                $suffix++;
    17571768                        } while ($post_name_check);
    17581769                        $slug = $alt_post_name;
    17591770                }
     1771        } else {
     1772                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
     1773                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID));
     1774               
     1775                if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
     1776                        $suffix = 2;
     1777                        do {
     1778                                $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";
     1779                                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID));
     1780                                $suffix++;
     1781                        } while ($post_name_check);
     1782                        $slug = $alt_post_name;
     1783                }
    17601784        }
     1785
    17611786        return $slug;
    17621787}
    17631788
     
    24532478                $post_name = sanitize_title($post_name);
    24542479
    24552480        // 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 ) );
     2481        $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
    24572482
    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 
    24692483        if ( empty($post_date) )
    24702484                $post_date = current_time('mysql');
    24712485        if ( empty($post_date_gmt) )