Make WordPress Core

Ticket #6437: 6437.diff

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

     
    17091709function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
    17101710        global $wpdb, $wp_rewrite;
    17111711        if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) {
    1712                 $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $slug, $post_type, $post_ID, $post_parent));
     1712                $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page', 'attachment'));
     1713                if ( in_array($post_type, $hierarchical_post_types) ) {
     1714                        $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, " . implode(',', add_magic_quotes($hierarchical_post_types)) . ") AND ID != %d AND post_parent = %d LIMIT 1";
     1715                } else {
     1716                        $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";
     1717                }
     1718                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
    17131719
    17141720                if ($post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
    17151721                        $suffix = 2;
    17161722                        do {
    17171723                                $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";
    1718                                 $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
     1724                                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent));
    17191725                                $suffix++;
    17201726                        } while ($post_name_check);
    17211727                        $slug = $alt_post_name;