Ticket #21013: 21013.10.patch
| File 21013.10.patch, 2.6 KB (added by SergeyBiryukov, 9 months ago) |
|---|
-
wp-includes/post.php
2964 2964 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { 2965 2965 $suffix = 2; 2966 2966 do { 2967 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2968 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );2967 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2968 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) ); 2969 2969 $suffix++; 2970 2970 } while ( $post_name_check ); 2971 2971 $slug = $alt_post_name; … … 2979 2979 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 ) ) { 2980 2980 $suffix = 2; 2981 2981 do { 2982 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2982 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2983 2983 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) ); 2984 2984 $suffix++; 2985 2985 } while ( $post_name_check ); … … 2993 2993 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { 2994 2994 $suffix = 2; 2995 2995 do { 2996 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2996 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2997 2997 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); 2998 2998 $suffix++; 2999 2999 } while ( $post_name_check ); … … 3005 3005 } 3006 3006 3007 3007 /** 3008 * Truncates a post slug with UTF-8 characters. 3009 * 3010 * @since 3.5.0 3011 * @access private 3012 * 3013 * @param string $slug The slug to truncate. 3014 * @param int $length Max length of the slug. 3015 * @return string The truncated slug. 3016 */ 3017 function _truncate_post_slug( $slug, $length = 200 ) { 3018 if ( strlen( $slug ) > $length ) { 3019 if ( urldecode( $slug ) === $slug ) 3020 $slug = substr( $slug, 0, $length ); 3021 else 3022 $slug = utf8_uri_encode( urldecode( $slug ), $length ); 3023 } 3024 3025 return rtrim( $slug, '-' ); 3026 } 3027 3028 /** 3008 3029 * Adds tags to a post. 3009 3030 * 3010 3031 * @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true.
