0

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 make a fetch/ajax post 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.

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.