Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5113,7 +5113,11 @@ function wp_encode_emoji( $content ) {
$emoji = _wp_emoji_list( 'partials' );

foreach ( $emoji as $emojum ) {
$emoji_char = html_entity_decode( $emojum );
if ( version_compare( phpversion(), '5.4', '<' ) ) {
$emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
} else {
$emoji_char = html_entity_decode( $emojum );
}
if ( false !== strpos( $content, $emoji_char ) ) {
$content = preg_replace( "/$emoji_char/", $emojum, $content );
}
Expand Down Expand Up @@ -5151,7 +5155,11 @@ function wp_staticize_emoji( $text ) {
$possible_emoji = array();
foreach( $emoji as $emojum ) {
if ( false !== strpos( $text, $emojum ) ) {
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
if ( version_compare( phpversion(), '5.4', '<' ) ) {
$possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
} else {
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
}
}
}

Expand Down
12 changes: 3 additions & 9 deletions tests/phpunit/tests/formatting/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,20 @@ public function data_wp_staticize_emoji() {
array(
// Simple emoji
'🙂',
'<img src="' . $this->png_cdn . '1f642.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
'<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Skin tone, gender, ZWJ, emoji selector
'👮🏼‍♀️',
'<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
'<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Unicode 10
'🧚',
'<img src="' . $this->png_cdn . '1f9da.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
'<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
);

// Older versions of PHP don't html_entity_decode() emoji, so we need to make sure they're testing in the expected form.
foreach ( $data as $key => $datum ) {
$emoji = html_entity_decode( wp_encode_emoji( $datum[0] ) );
$data[ $key ][1] = str_replace( 'alt=""', 'alt="' . $emoji . '"', $datum[1] );
}

return $data;
}

Expand Down