I am creating a wordpress plugin which allow user to select different emojis with text. I am then making a fetch request to back end to update with selected emoji. Right now I am just rendering a picture. and it saved as a hard coded emoji in
.php file. However I could be adding more emoji's later.
My question is
- How can I verify text posted / rendered is actually an emoji (ie. sanitise it?)
- How I can ensure emoji is safe to render on FE and then
fetch/ajaxpost request to backend and have the emoji secured with encoding/decoding?
// Render from Backend to frontend JS constant const moodList = <?php echo json_encode( ['😀 - smile', '😁 - grin', '😂 - tears of joy', '🤣 - rofl', '😅 - smiling cold sweat'] ); ?>
// Update my HTML const moodlist = ['😀 - smile', '😁 - grin', '😂 - tears of joy', '🤣 - rofl', '😅 - smiling cold sweat'] document.querySelector('.moods').innerHTML = moodlist.join(' ');
Thanks a bunch in advance.