Closed mohammad425 closed 1 year ago
Hey, @mohammad425!
Thanks for spotting that issue and taking the time to open the PR — we truly appreciate it. 🙂
Everything looks clean and fits well with the plugin’s existing code. However, I have one concern. While the HTML entities are being displayed as 📢
when in a text field or textarea, they are rendered correctly on the front-end.
To avoid the overhead of running a recursive function for decoding in Settings::get()
, which would execute every time settings are retrieved (i.e., with every user visit), I suggest restricting the conversion from HTML entities back to emoji characters only when necessary for displaying settings on the plugin’s settings page.
If you think you’ve already invested enough time in this, that’s perfectly understandable, and you’ve given us an excellent starting point. Just let me know if you’d like to explore this further.
Very good idea! I made the necessary changes for this: cf2e3d
@mohammad425 Thanks for getting back so quickly! I’ve merged your PR and scheduled your changes for the next release 🙂
Issue Description:
In the previous implementation, when storing emojis in the database, they were saved in the utf8 character set (e.g.,
📢
). However, when attempting to display these emojis within an input or textarea field, they were still being shown as "📢
" instead of the actual emoji representation.Changes Made:
To fix the emoji display issue, two changes were implemented:
Updated Settings.php: The
get()
method in Settings.php was modified to handle decoding emoji arrays. Now, before returning the settings, the method callsUtils::decode_emoji_array($settings)
to ensure that any emoji characters in the settings array are properly decoded.To fix the emoji display issue, two new functions were added to the existing Utils.php file:
decode_emoji_array()
: This function is responsible for decoding emoji characters in a nested array. It iterates through the elements of the input array and, if an element is a string containing emoji characters, it replaces them with their respective HTML entities. If an element is another array, the function recursively calls itself to handle nested arrays.staticize_emoji()
: This function is used to check a given text for emoji characters and replace them with their respective HTML entities. Before encoding, the function first checks if the text contains any characters that might be emojis. If not, it returns the input text as it is. If emoji characters are present, the function uses WordPress' wp_encode_emoji() function to encode them. It also narrows down the list of emojis that might be in the text for more efficient processing. The function then iterates through the text and replaces the possible emojis with their corresponding HTML entities.