Make WordPress Core

Ticket #21013: 21013.11.patch

File 21013.11.patch, 2.7 KB (added by SergeyBiryukov, 14 years ago)

Refreshed

  • wp-includes/post.php

     
    31503150                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
    31513151                        $suffix = 2;
    31523152                        do {
    3153                                 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    3154                                 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
     3153                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     3154                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
    31553155                                $suffix++;
    31563156                        } while ( $post_name_check );
    31573157                        $slug = $alt_post_name;
    … …  
    31673167                if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
    31683168                        $suffix = 2;
    31693169                        do {
    3170                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     3170                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    31713171                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
    31723172                                $suffix++;
    31733173                        } while ( $post_name_check );
    … …  
    31813181                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
    31823182                        $suffix = 2;
    31833183                        do {
    3184                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     3184                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    31853185                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
    31863186                                $suffix++;
    31873187                        } while ( $post_name_check );
    … …  
    31933193}
    31943194
    31953195/**
     3196 * Truncates a post slug.
     3197 *
     3198 * @since 3.6.0
     3199 * @access private
     3200 * @uses utf8_uri_encode() Makes sure UTF-8 characters are properly cut and encoded.
     3201 *
     3202 * @param string $slug The slug to truncate.
     3203 * @param int $length Max length of the slug.
     3204 * @return string The truncated slug.
     3205 */
     3206function _truncate_post_slug( $slug, $length = 200 ) {
     3207        if ( strlen( $slug ) > $length ) {
     3208                $decoded_slug = urldecode( $slug );
     3209                if ( $decoded_slug === $slug )
     3210                        $slug = substr( $slug, 0, $length );
     3211                else
     3212                        $slug = utf8_uri_encode( $decoded_slug, $length );
     3213        }
     3214
     3215        return rtrim( $slug, '-' );
     3216}
     3217
     3218/**
    31963219 * Adds tags to a post.
    31973220 *
    31983221 * @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true.