From e631b2d34150efb7239dcf77db10174739938d5f Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 5 May 2009 16:39:36 +0000 Subject: [PATCH] Use wp_unique_slug() in wp_insert_attachment(). Props Denis-de-Bernardy. fixes #9726 git-svn-id: http://svn.automattic.com/wordpress/trunk@11202 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index ff57eaea0..b6782eae9 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1717,7 +1717,7 @@ function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_pa $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"; $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent)); } - + if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { $suffix = 2; do { @@ -2415,19 +2415,7 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { else $post_name = sanitize_title($post_name); - // expected_slashed ($post_name) - $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)); - - if ($post_name_check) { - $suffix = 2; - while ($post_name_check) { - $alt_post_name = $post_name . "-$suffix"; - // expected_slashed ($alt_post_name, $post_name) - $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)); - $suffix++; - } - $post_name = $alt_post_name; - } + $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); if ( empty($post_date) ) $post_date = current_time('mysql');