Changeset 13075
- Timestamp:
- 02/13/2010 02:42:17 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r13052 r13075 2293 2293 2294 2294 /** 2295 * Given the desired slug and some post details computes a unique slug for the post.2295 * Computes a unique slug for the post, when given the desired slug and some post details. 2296 2296 * 2297 2297 * @global wpdb $wpdb … … 2304 2304 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 2305 2305 */ 2306 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent) {2306 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 2307 2307 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 2308 2308 return $slug; … … 2311 2311 2312 2312 $feeds = $wp_rewrite->feeds; 2313 if ( ! is_array($feeds) )2313 if ( ! is_array( $feeds ) ) 2314 2314 $feeds = array(); 2315 2315 2316 $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array('page'));2316 $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array( 'page' ) ); 2317 2317 if ( 'attachment' == $post_type ) { 2318 2318 // Attachment slugs must be unique across all types. 2319 2319 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 2320 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_ID));2321 2322 if ( $post_name_check || in_array( $slug, $feeds) ) {2320 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 2321 2322 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2323 2323 $suffix = 2; 2324 2324 do { 2325 $alt_post_name = substr ($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2326 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID));2325 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2326 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) ); 2327 2327 $suffix++; 2328 } while ( $post_name_check);2328 } while ( $post_name_check ); 2329 2329 $slug = $alt_post_name; 2330 2330 } 2331 } elseif ( in_array( $post_type, $hierarchical_post_types) ) {2332 // Page slugs must be unique within their own trees. Pages are in a2333 // separatenamespace than posts so page slugs are allowed to overlap post slugs.2334 $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";2335 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_ID, $post_parent));2336 2337 if ( $post_name_check || in_array( $slug, $feeds) ) {2331 } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { 2332 // Page slugs must be unique within their own trees. Pages are in a separate 2333 // namespace than posts so page slugs are allowed to overlap post slugs. 2334 $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"; 2335 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); 2336 2337 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2338 2338 $suffix = 2; 2339 2339 do { 2340 $alt_post_name = substr( $slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2341 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent));2340 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2341 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) ); 2342 2342 $suffix++; 2343 } while ( $post_name_check);2343 } while ( $post_name_check ); 2344 2344 $slug = $alt_post_name; 2345 2345 } … … 2347 2347 // Post slugs must be unique across all posts. 2348 2348 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 2349 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $slug, $post_type, $post_ID));2350 2351 if ( $post_name_check || in_array( $slug, $wp_rewrite->feeds) ) {2349 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 2350 2351 if ( $post_name_check || in_array( $slug, $feeds ) ) { 2352 2352 $suffix = 2; 2353 2353 do { 2354 $alt_post_name = substr( $slug, 0, 200-(strlen($suffix)+1)). "-$suffix";2355 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID));2354 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2355 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); 2356 2356 $suffix++; 2357 } while ( $post_name_check);2357 } while ( $post_name_check ); 2358 2358 $slug = $alt_post_name; 2359 2359 }
Note: See TracChangeset
for help on using the changeset viewer.