Ticket #13459: 13459.diff
| File 13459.diff, 3.2 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/post.php
3678 3678 * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 3679 3679 */ 3680 3680 function 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 ) ) { 3682 3682 return $slug; 3683 } 3683 3684 3684 3685 global $wpdb, $wp_rewrite; 3685 3686 3686 3687 $original_slug = $slug; 3687 3688 3688 3689 $feeds = $wp_rewrite->feeds; 3689 if ( ! is_array( $feeds ) ) 3690 if ( ! is_array( $feeds ) ) { 3690 3691 $feeds = array(); 3692 } 3691 3693 3692 3694 if ( 'attachment' == $post_type ) { 3693 3695 // Attachment slugs must be unique across all types. … … 3712 3714 $slug = $alt_post_name; 3713 3715 } 3714 3716 } elseif ( is_post_type_hierarchical( $post_type ) ) { 3715 if ( 'nav_menu_item' == $post_type ) 3717 if ( 'nav_menu_item' == $post_type ) { 3716 3718 return $slug; 3719 } 3717 3720 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 } 3724 3728 3725 3729 /** 3726 3730 * Filter whether the post slug would make a bad hierarchical post slug. … … 3746 3750 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3747 3751 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 3748 3752 3753 if ( ! $post_name_check && '/%postname%/' == $wp_rewrite->permalink_structure ) { 3754 $post_name_check = get_page_by_path( $slug ); 3755 } 3756 3749 3757 /** 3750 3758 * Filter whether the post slug would be bad as a flat slug. 3751 3759 * … … 3760 3768 do { 3761 3769 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3762 3770 $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 3763 3776 $suffix++; 3764 3777 } while ( $post_name_check ); 3765 3778 $slug = $alt_post_name;