diff --git a/src/wp-includes/js/wp-emoji.js b/src/wp-includes/js/wp-emoji.js index f41907865e..eed3fe389e 100644 --- a/src/wp-includes/js/wp-emoji.js +++ b/src/wp-includes/js/wp-emoji.js @@ -70,7 +70,7 @@ node = node.parentNode; } - if ( node && node.nodeType === 1 ) { + if ( node && node.nodeType === 1 && test( node.textContent ) ) { parse( node ); } } @@ -84,6 +84,22 @@ parse( document.body ); } + /** + * Test if a text string contains emoji characters + * + * @since 4.3.0 + * + * @param {String} text The string to test + * @returns Boolean + */ + function test( text ) { + if ( text && twemoji ) { + return twemoji.test( text ); + } + + return false; + } + /** * Given an element or string, parse any emoji characters into Twemoji images. * @@ -144,7 +160,8 @@ return { replaceEmoji: replaceEmoji, - parse: parse + parse: parse, + test: test }; }