Ticket #21013: 21013.7.patch
| File 21013.7.patch, 3.0 KB (added by SergeyBiryukov, 12 months ago) |
|---|
-
wp-includes/post.php
2850 2850 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { 2851 2851 $suffix = 2; 2852 2852 do { 2853 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2854 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );2853 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2854 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) ); 2855 2855 $suffix++; 2856 2856 } while ( $post_name_check ); 2857 2857 $slug = $alt_post_name; … … 2865 2865 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 ) ) { 2866 2866 $suffix = 2; 2867 2867 do { 2868 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2868 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2869 2869 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) ); 2870 2870 $suffix++; 2871 2871 } while ( $post_name_check ); … … 2879 2879 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { 2880 2880 $suffix = 2; 2881 2881 do { 2882 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2882 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2883 2883 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); 2884 2884 $suffix++; 2885 2885 } while ( $post_name_check ); … … 2891 2891 } 2892 2892 2893 2893 /** 2894 * Truncate a post slug with UTF-8 characters. 2895 * 2896 * @since 3.5.0 2897 * @access private 2898 * 2899 * @param string $slug The slug to truncate. 2900 * @param int $length Max length of the slug. 2901 * @return string The truncated slug. 2902 */ 2903 function _truncate_post_slug( $slug, $length = 200 ) { 2904 while ( strlen( $slug ) > $length ) { 2905 $raw_slug = urldecode( $slug ); 2906 2907 if ( preg_match( '/[\xc2-\xdf][\x80-\xbf]$/', $raw_slug ) ) 2908 $last_char_length = 6; 2909 elseif ( preg_match( '/[\xe0][\xa0-\xbf][\x80-\xbf]$/', $raw_slug ) 2910 || preg_match( '/[\xe1-\xec][\x80-\xbf][\x80-\xbf]$/', $raw_slug ) 2911 || preg_match( '/[\xed-\xef][\x80-\x9f][\x80-\xbf]$/', $raw_slug ) 2912 || preg_match( '/[\xee-\xef][\x80-\xbf][\x80-\xbf]$/', $raw_slug ) ) 2913 $last_char_length = 9; 2914 else 2915 $last_char_length = 1; 2916 2917 $slug = trim( substr( $slug, 0, -$last_char_length ), '-' ); 2918 } 2919 2920 return $slug; 2921 } 2922 2923 /** 2894 2924 * Adds tags to a post. 2895 2925 * 2896 2926 * @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true.