Ticket #16079: 16079.2.diff
File 16079.2.diff, 1.7 KB (added by , 13 years ago) |
---|
-
wp-includes/formatting.php
2044 2044 /** 2045 2045 * Trims text to a certain number of words. 2046 2046 * 2047 * This function is localized. For languages that count 'words' by the individual 2048 * character (such as East Asian languages), the $num_words argument will apply 2049 * to the number of individual characters. 2050 * 2047 2051 * @since 3.3.0 2048 2052 * 2049 2053 * @param string $text Text to trim. … … 2056 2060 $more = __( '…' ); 2057 2061 $original_text = $text; 2058 2062 $text = wp_strip_all_tags( $text ); 2059 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 2063 /* translators: If your word count is based on single characters (East Asian characters), 2064 enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ 2065 if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { 2066 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); 2067 preg_match_all( '/./u', $text, $words_array ); 2068 $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); 2069 $sep = ''; 2070 } else { 2071 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 2072 $sep = ' '; 2073 } 2060 2074 if ( count( $words_array ) > $num_words ) { 2061 2075 array_pop( $words_array ); 2062 $text = implode( ' ', $words_array );2076 $text = implode( $sep, $words_array ); 2063 2077 $text = $text . $more; 2064 2078 } else { 2065 $text = implode( ' ', $words_array );2079 $text = implode( $sep, $words_array ); 2066 2080 } 2067 2081 return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); 2068 2082 }