Make WordPress Core

Ticket #13459: 13459.diff

File 13459.diff, 3.2 KB (added by MikeHansenMe, 11 years ago)
  • src/wp-includes/post.php

     
    36783678 * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
    36793679 */
    36803680function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    3681         if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) )
     3681        if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) {
    36823682                return $slug;
     3683        }
    36833684
    36843685        global $wpdb, $wp_rewrite;
    36853686
    36863687        $original_slug = $slug;
    36873688
    36883689        $feeds = $wp_rewrite->feeds;
    3689         if ( ! is_array( $feeds ) )
     3690        if ( ! is_array( $feeds ) ) {
    36903691                $feeds = array();
     3692        }
    36913693
    36923694        if ( 'attachment' == $post_type ) {
    36933695                // Attachment slugs must be unique across all types.
     
    37123714                        $slug = $alt_post_name;
    37133715                }
    37143716        } elseif ( is_post_type_hierarchical( $post_type ) ) {
    3715                 if ( 'nav_menu_item' == $post_type )
     3717                if ( 'nav_menu_item' == $post_type ) {
    37163718                        return $slug;
     3719                }
    37173720
    3718                 /*
    3719                  * Page slugs must be unique within their own trees. Pages are in a separate
    3720                  * namespace than posts so page slugs are allowed to overlap post slugs.
    3721                  */
    3722                 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
    3723                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
     3721                if( '/%postname%/' == $wp_rewrite->permalink_structure && $post_parent === 0 ) {
     3722                        $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d AND post_parent = %d LIMIT 1";
     3723                        $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) );
     3724                } else {
     3725                        $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
     3726                        $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
     3727                }
    37243728
    37253729                /**
    37263730                 * Filter whether the post slug would make a bad hierarchical post slug.
     
    37463750                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
    37473751                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
    37483752
     3753                if ( ! $post_name_check && '/%postname%/' == $wp_rewrite->permalink_structure ) {
     3754                        $post_name_check = get_page_by_path( $slug );
     3755                }
     3756
    37493757                /**
    37503758                 * Filter whether the post slug would be bad as a flat slug.
    37513759                 *
     
    37603768                        do {
    37613769                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    37623770                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
     3771                               
     3772                                if ( ! $post_name_check && '/%postname%/' == $wp_rewrite->permalink_structure ) {
     3773                                        $post_name_check = get_page_by_path( $alt_post_name );
     3774                                }
     3775
    37633776                                $suffix++;
    37643777                        } while ( $post_name_check );
    37653778                        $slug = $alt_post_name;