Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5462,13 +5462,21 @@ function wp_sprintf_l( $pattern, $args ) {
}

/**
* Safely extracts not more than the first $count characters from HTML string.
* Returns up to a given number of code points of the renderable text
* from the given HTML input, after decoding character references.
*
* UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
* be counted as one character. For example & will be counted as 4, < as
* 3, etc.
* Example:
*
* 'Chap' === wp_html_excerpt( '<h2>Chapter One</h2>', 4 );
*
* // Counts after decoding character references.
* '¶ 3.' === wp_html_excerpt( '&para; <span major>3</span>.<span minor>1</span>', 4 );
*
* // Code point counts may trim in the middle of extended grapheme clusters.
* '👩' === wp_html_excerpt( '👩‍✈️', 1 );
*
* @since 2.5.0
* @since 7.2.0 Trims by code point count in decoded string and normalize output.
*
* @param string $str String to get the excerpt from.
* @param int $count Maximum number of characters to take.
Expand All @@ -5481,7 +5489,16 @@ function wp_html_excerpt( $str, $count, $more = null ) {
}

$str = wp_strip_all_tags( $str, true );
$str = WP_HTML_Decoder::decode_text_node( $str );
$excerpt = mb_substr( $str, 0, $count );
$excerpt = strtr(
$excerpt,
array(
'<' => '&lt;',
'&' => '&amp;',
'>' => '&gt;',
)
);

// Remove part of an entity at the end.
$excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ public function is_tag_closer(): bool {
*
* @return bool Whether the current token is virtual.
*/
private function is_virtual(): bool {
protected function is_virtual(): bool {
return (
isset( $this->current_element->provenance ) &&
'virtual' === $this->current_element->provenance
Expand Down
Loading
Loading