Ticket #12078: 12078.diff
| File 12078.diff, 4.8 KB (added by , 16 years ago) |
|---|
-
wp-includes/post.php
2207 2207 2208 2208 2209 2209 /** 2210 * Given the desired slug and some post details computes a unique slug for the post.2210 * Computes a unique slug for the post, when given the desired slug and some post details. 2211 2211 * 2212 2212 * @global wpdb $wpdb 2213 2213 * @global WP_Rewrite $wp_rewrite … … 2218 2218 * @param integer $post_parent 2219 2219 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 2220 2220 */ 2221 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent) {2221 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 2222 2222 if ( in_array( $post_status, array( 'draft', 'pending' ) ) ) 2223 2223 return $slug; 2224 2224 2225 2225 global $wpdb, $wp_rewrite; 2226 2226 2227 2227 $feeds = $wp_rewrite->feeds; 2228 if ( ! is_array($feeds) )2228 if ( ! is_array( $feeds ) ) 2229 2229 $feeds = array(); 2230 2230 2231 $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array('page'));2231 $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array( 'page' ) ); 2232 2232 if ( 'attachment' == $post_type ) { 2233 2233 // Attachment slugs must be unique across all types. 2234 2234 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 2235 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_ID));2235 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 2236 2236 2237 if ( $post_name_check || in_array( $slug, $feeds) ) {2237 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2238 2238 $suffix = 2; 2239 2239 do { 2240 $alt_post_name = substr ($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2241 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID));2240 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2241 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) ); 2242 2242 $suffix++; 2243 } while ( $post_name_check);2243 } while ( $post_name_check ); 2244 2244 $slug = $alt_post_name; 2245 2245 } 2246 } elseif ( in_array( $post_type, $hierarchical_post_types) ) {2247 // Page slugs must be unique within their own trees. Pages are in a2248 // separatenamespace than posts so page slugs are allowed to overlap post slugs.2249 $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";2250 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_ID, $post_parent));2246 } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { 2247 // Page slugs must be unique within their own trees. Pages are in a separate 2248 // namespace than posts so page slugs are allowed to overlap post slugs. 2249 $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"; 2250 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); 2251 2251 2252 if ( $post_name_check || in_array( $slug, $feeds) ) {2252 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2253 2253 $suffix = 2; 2254 2254 do { 2255 $alt_post_name = substr( $slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2256 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent));2255 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2256 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) ); 2257 2257 $suffix++; 2258 } while ( $post_name_check);2258 } while ( $post_name_check ); 2259 2259 $slug = $alt_post_name; 2260 2260 } 2261 2261 } else { 2262 2262 // Post slugs must be unique across all posts. 2263 2263 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 2264 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_type, $post_ID));2264 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 2265 2265 2266 if ( $post_name_check || in_array( $slug, $wp_rewrite->feeds) ) {2266 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2267 2267 $suffix = 2; 2268 2268 do { 2269 $alt_post_name = substr( $slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2270 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID));2269 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2270 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); 2271 2271 $suffix++; 2272 } while ( $post_name_check);2272 } while ( $post_name_check ); 2273 2273 $slug = $alt_post_name; 2274 2274 } 2275 2275 }