WordPress.org

Make WordPress Core

Ticket #16843: 16843.3.diff

File 16843.3.diff, 3.0 KB (added by wonderboymusic, 18 months ago)
  • wp-includes/post.php

     
    30993099        if ( 'attachment' == $post_type ) { 
    31003100                // Attachment slugs must be unique across all types. 
    31013101                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 
    3102                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 
     3102                $post_name_check = in_array( $slug, $feeds ) 
     3103                        || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) 
     3104                        || $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 
    31033105 
    3104                 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { 
     3106                if ( $post_name_check ) { 
    31053107                        $suffix = 2; 
    31063108                        do { 
    31073109                                $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 
     
    31163118                // Page slugs must be unique within their own trees. Pages are in a separate 
    31173119                // namespace than posts so page slugs are allowed to overlap post slugs. 
    31183120                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 
    3119                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); 
     3121                $post_name_check = in_array( $slug, $feeds ) 
     3122                        || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) 
     3123                        || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) 
     3124                        || $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); 
    31203125 
    3121                 if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { 
     3126                if ( $post_name_check ) { 
    31223127                        $suffix = 2; 
    31233128                        do { 
    31243129                                $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 
     
    31303135        } else { 
    31313136                // Post slugs must be unique across all posts. 
    31323137                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 
    3133                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 
     3138                $post_type_obj = get_post_type_object( $post_type ); 
    31343139 
    3135                 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { 
     3140                $post_name_check = in_array( $slug, $feeds ) 
     3141                        || ( $post_type_obj->has_archive && $wp_rewrite->pagination_base == $slug ) 
     3142                        || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) 
     3143                        || $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 
     3144 
     3145                if ( $post_name_check ) { 
    31363146                        $suffix = 2; 
    31373147                        do { 
    31383148                                $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";