WordPress.org

Make WordPress Core

Ticket #9539: 9539.diff

File 9539.diff, 3.2 KB (added by Denis-de-Bernardy, 9 years ago)

full patch, including fix for #9726

  • wp-includes/post.php

     
    17171717                        $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";
    17181718                        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
    17191719                }
    1720 
     1720               
    17211721                if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
    17221722                        $suffix = 2;
    17231723                        do {
     
    24152415        else
    24162416                $post_name = sanitize_title($post_name);
    24172417
    2418         // expected_slashed ($post_name)
    2419         $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));
     2418        $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
    24202419
    2421         if ($post_name_check) {
    2422                 $suffix = 2;
    2423                 while ($post_name_check) {
    2424                         $alt_post_name = $post_name . "-$suffix";
    2425                         // expected_slashed ($alt_post_name, $post_name)
    2426                         $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, $post_parent));
    2427                         $suffix++;
    2428                 }
    2429                 $post_name = $alt_post_name;
    2430         }
    2431 
    24322420        if ( empty($post_date) )
    24332421                $post_date = current_time('mysql');
    24342422        if ( empty($post_date_gmt) )
  • wp-includes/version.php

     
    1515 *
    1616 * @global int $wp_db_version
    1717 */
    18 $wp_db_version = 10850;
     18$wp_db_version = 11200;
    1919
    2020?>
  • wp-admin/includes/upgrade.php

     
    340340        if ( $wp_current_db_version < 8989 )
    341341                upgrade_270();
    342342
    343         if ( $wp_current_db_version < 10360 )
     343        if ( $wp_current_db_version < 11200 )
    344344                upgrade_280();
    345345
    346346        maybe_disable_automattic_widgets();
     
    980980
    981981        if ( $wp_current_db_version < 10360 )
    982982                populate_roles_280();
     983       
     984        if ( $wp_current_db_version < 11200 )
     985                fix_attachment_slug_conflicts();
    983986}
    984987
    985988
  • wp-admin/includes/schema.php

     
    576576        }
    577577}
    578578
    579 ?>
     579/**
     580 * Fix duplicate slugs in hierarchical data
     581 * See http://core.trac.wordpress.org/ticket/9539
     582 *
     583 * @since 2.8.0
     584 **/
     585
     586function fix_attachment_slug_conflicts() {
     587        global $wpdb;
     588       
     589        $attachments = $wpdb->get_results("
     590                SELECT attachment.*
     591                FROM $wpdb->posts as attachment
     592                JOIN $wpdb->posts as page
     593                ON attachment.post_name = page.post_name
     594                WHERE attachment.post_type = 'attachment'
     595                AND page.post_type = 'page'
     596                AND attachment.post_parent = page.post_parent
     597                AND attachment.post_name <> ''
     598                ");
     599       
     600        while ( $attachment = array_pop($attachments) )
     601                wp_update_post($attachment);
     602} # fix_attachment_slug_conflicts()
     603?>
     604 No newline at end of file