WordPress.org

Make WordPress Core

Ticket #16079: 16079.2.diff

File 16079.2.diff, 1.7 KB (added by tenpura, 2 years ago)
  • wp-includes/formatting.php

     
    20442044/** 
    20452045 * Trims text to a certain number of words. 
    20462046 * 
     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 * 
    20472051 * @since 3.3.0 
    20482052 * 
    20492053 * @param string $text Text to trim. 
     
    20562060                $more = __( '…' ); 
    20572061        $original_text = $text; 
    20582062        $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        } 
    20602074        if ( count( $words_array ) > $num_words ) { 
    20612075                array_pop( $words_array ); 
    2062                 $text = implode( ' ', $words_array ); 
     2076                $text = implode( $sep, $words_array ); 
    20632077                $text = $text . $more; 
    20642078        } else { 
    2065                 $text = implode( ' ', $words_array ); 
     2079                $text = implode( $sep, $words_array ); 
    20662080        } 
    20672081        return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); 
    20682082}