WordPress.org

Make WordPress Core

Ticket #21013: 21013.9.patch

File 21013.9.patch, 2.6 KB (added by SergeyBiryukov, 6 years ago)
  • wp-includes/post.php

     
    28672867                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
    28682868                        $suffix = 2;
    28692869                        do {
    2870                                 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    2871                                 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
     2870                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2871                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
    28722872                                $suffix++;
    28732873                        } while ( $post_name_check );
    28742874                        $slug = $alt_post_name;
     
    28822882                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 ) ) {
    28832883                        $suffix = 2;
    28842884                        do {
    2885                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2885                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    28862886                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
    28872887                                $suffix++;
    28882888                        } while ( $post_name_check );
     
    28962896                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
    28972897                        $suffix = 2;
    28982898                        do {
    2899                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2899                                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    29002900                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
    29012901                                $suffix++;
    29022902                        } while ( $post_name_check );
     
    29082908}
    29092909
    29102910/**
     2911 * Truncate a post slug with UTF-8 characters.
     2912 *
     2913 * @since 3.5.0
     2914 * @access private
     2915 *
     2916 * @param string $slug The slug to truncate.
     2917 * @param int $length Max length of the slug.
     2918 * @return string The truncated slug.
     2919 */
     2920function _truncate_post_slug( $slug, $length = 200 ) {
     2921        if ( urldecode( $slug ) === $slug )
     2922                return substr( $slug, 0, $length );
     2923
     2924        while ( strlen( $slug ) > $length ) {
     2925                $slug = mb_substr( urldecode( $slug ), 0, -1 );
     2926                $slug = utf8_uri_encode( rtrim( $slug, '-' ) );
     2927        }
     2928
     2929        return $slug;
     2930}
     2931
     2932/**
    29112933 * Adds tags to a post.
    29122934 *
    29132935 * @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true.