WordPress.org

Make WordPress Core

Ticket #16079: 16079.diff

File 16079.diff, 1.3 KB (added by nacin, 6 years ago)
  • wp-includes/formatting.php

     
    20392039/**
    20402040 * Trims text to a certain number of words.
    20412041 *
     2042 * This function is localized. For languages that count 'words' by the individual
     2043 * character (such as East Asian languages), the $num_words argument will apply
     2044 * to the number of individual characters.
     2045 *
    20422046 * @since 3.3.0
    20432047 *
    20442048 * @param string $text Text to trim.
     
    20512055                $more = __( '…' );
    20522056        $original_text = $text;
    20532057        $text = wp_strip_all_tags( $text );
    2054         $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
     2058        /* translators: If your word count is based on single characters (East Asian characters),
     2059           enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
     2060        if ( 'characters' == _x( 'words', 'word count: words or characters?' ) ) {
     2061                preg_match_all( '/(\S)/', $text, $words_array );
     2062                $words_array = array_slice( $words_array[1], 0, $num_words + 1 );
     2063        } else {
     2064                $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
     2065        }
    20552066        if ( count( $words_array ) > $num_words ) {
    20562067                array_pop( $words_array );
    20572068                $text = implode( ' ', $words_array );