WordPress.org

Make WordPress Core

Ticket #12078: 12078.diff

File 12078.diff, 4.8 KB (added by nacin, 8 years ago)

Includes code convention cleanups. Actual fix is ~L 2267

  • wp-includes/post.php

     
    22072207
    22082208
    22092209/**
    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.
    22112211 *
    22122212 * @global wpdb $wpdb
    22132213 * @global WP_Rewrite $wp_rewrite
     
    22182218 * @param integer $post_parent
    22192219 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
    22202220 */
    2221 function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
     2221function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    22222222        if ( in_array( $post_status, array( 'draft', 'pending' ) ) )
    22232223                return $slug;
    22242224
    22252225        global $wpdb, $wp_rewrite;
    22262226
    22272227        $feeds = $wp_rewrite->feeds;
    2228         if ( !is_array($feeds) )
     2228        if ( ! is_array( $feeds ) )
    22292229                $feeds = array();
    22302230
    2231         $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page'));
     2231        $hierarchical_post_types = apply_filters( 'hierarchical_post_types', array( 'page' ) );
    22322232        if ( 'attachment' == $post_type ) {
    22332233                // Attachment slugs must be unique across all types.
    22342234                $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 ) );
    22362236
    2237                 if ( $post_name_check || in_array($slug, $feeds) ) {
     2237                if ( $post_name_check || in_array( $slug, $feeds ) ) {
    22382238                        $suffix = 2;
    22392239                        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 ) );
    22422242                                $suffix++;
    2243                         } while ($post_name_check);
     2243                        } while ( $post_name_check );
    22442244                        $slug = $alt_post_name;
    22452245                }
    2246         } elseif ( in_array($post_type, $hierarchical_post_types) ) {
    2247                 // Page slugs must be unique within their own trees.  Pages are in a
    2248                 // separate 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));
     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 ) );
    22512251
    2252                 if ( $post_name_check || in_array($slug, $feeds) ) {
     2252                if ( $post_name_check || in_array( $slug, $feeds ) ) {
    22532253                        $suffix = 2;
    22542254                        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 ) );
    22572257                                $suffix++;
    2258                         } while ($post_name_check);
     2258                        } while ( $post_name_check );
    22592259                        $slug = $alt_post_name;
    22602260                }
    22612261        } else {
    22622262                // Post slugs must be unique across all posts.
    22632263                $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 ) );
    22652265
    2266                 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
     2266                if ( $post_name_check || in_array( $slug, $feeds ) ) {
    22672267                        $suffix = 2;
    22682268                        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 ) );
    22712271                                $suffix++;
    2272                         } while ($post_name_check);
     2272                        } while ( $post_name_check );
    22732273                        $slug = $alt_post_name;
    22742274                }
    22752275        }