Make WordPress Core


Ignore:
Timestamp:
02/13/2010 02:42:17 AM (17 years ago)
Author:
nacin
Message:

Use correct var name. Props firebird75. Whitespace cleanup in wp_unique_post_slug(). Fixes #12078.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r13052 r13075  
    22932293
    22942294/**
    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.
    22962296 *
    22972297 * @global wpdb $wpdb
     
    23042304 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
    23052305 */
    2306 function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
     2306function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    23072307        if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
    23082308                return $slug;
     
    23112311
    23122312        $feeds = $wp_rewrite->feeds;
    2313         if ( !is_array($feeds) )
     2313        if ( ! is_array( $feeds ) )
    23142314                $feeds = array();
    23152315
    2316         $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page'));
     2316        $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array( 'page' ) );
    23172317        if ( 'attachment' == $post_type ) {
    23182318                // Attachment slugs must be unique across all types.
    23192319                $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 ) ) {
    23232323                        $suffix = 2;
    23242324                        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 ) );
    23272327                                $suffix++;
    2328                         } while ($post_name_check);
     2328                        } while ( $post_name_check );
    23292329                        $slug = $alt_post_name;
    23302330                }
    2331         } elseif ( in_array($post_type, $hierarchical_post_types) ) {
    2332                 // Page slugs must be unique within their own trees.  Pages are in a
    2333                 // separate 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) ) {
     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 ) ) {
    23382338                        $suffix = 2;
    23392339                        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 ) );
    23422342                                $suffix++;
    2343                         } while ($post_name_check);
     2343                        } while ( $post_name_check );
    23442344                        $slug = $alt_post_name;
    23452345                }
     
    23472347                // Post slugs must be unique across all posts.
    23482348                $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 ) ) {
    23522352                        $suffix = 2;
    23532353                        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 ) );
    23562356                                $suffix++;
    2357                         } while ($post_name_check);
     2357                        } while ( $post_name_check );
    23582358                        $slug = $alt_post_name;
    23592359                }
Note: See TracChangeset for help on using the changeset viewer.