(int) ($budget * 0.6)) { $cut = mb_substr($cut, 0, $last_gap); } return rtrim($cut) . '…'; } /** * Apply a WORD cap that stays a word cap. * * wp_trim_words() reads its unit from the locale, so `$words` silently * becomes a *character* cap on th/ja/zh_* — roughly six times tighter than * intended. Callers that mean "about N words" go through here: word-counting * locales keep wp_trim_words() byte for byte, and the rest get a character * budget instead of a mangled one (#687). * * @since 2.7.0 * * @param string $text Text to trim. * @param int $words Word cap, honoured only where words are the unit. * @param string $more Appended by wp_trim_words() when it trims. * @param int $fallback Character budget used where words are not the unit. * @return string */ public static function trim_words( string $text, int $words, string $more = '...', int $fallback = self::MAX_LENGTH ): string { if (!self::locale_counts_words()) { return self::trim_to_length($text, $fallback); } return wp_trim_words($text, $words, $more); } }