A WordPress-centric search engine for devs and theme authors



wp_encode_emoji ›

Since4.2.0
Deprecatedn/a
wp_encode_emoji ( $content )
Parameters:
  • (string) $content The content to encode.
    Required: Yes
Returns:
  • (string) The encoded content.
Defined at:
Codex:

Convert emoji characters to their equivalent HTML entity.

This allows us to store emoji in a DB using the utf8 character set.



Source

function wp_encode_emoji( $content ) {
	$emoji = _wp_emoji_list( 'partials' );

	foreach ( $emoji as $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 );
		}
	}

	return $content;
}