-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating failed. Error message: Could not update post in the database when UTF-8 symbol in paragraph #19552
Comments
I'm not able to reproduce this issue. Is it possible that you have somekind of proxy/firewall that prevents this on the network level. Consider checking the response of the API call on the network tab of your browser's development tools. |
Thanks for trying this out.. Tested on a different site, same WP version, same theme, no issue. Testet again on original site with different utf-8 icons: All icons with a 5 digit unicode hex code (like this one https://www.utf8icons.com/character/128497/lightning-mood-bubble) FAILS All icons with a 4 digit hex code (like this one https://www.utf8icons.com/character/9889/high-voltage-sign) WORKS I obviously didn't test all unicode symbols, but enough to notice the pattern. On the site where it fails, the API call network tab returns this error when the post update fails: api-fetch.min.js?ver=3.6.4:1 POST https://oldrup.dk/wp-json/wp/v2/posts/2024?_locale=user 500 I tested in both Chrome and Firefox, same results I disabled all plugins, same results. I'm not using a proxy. I was using Ghostery ad blocker, but disabled that too. So in conclusion, it does not appear to be a widespread problem, but the weird difference about being able to save posts with 4 hex digits unicodes, and not 5 hex digits unicodes, does smell of some software input validation, idk... If I can do anything else to diagnose and squash any possible bug, please let me know. |
Me too facing the same problem.. Trying to add UTF symbol - 😍 When I try to update post with 😍, its showing error Updating failed. Could not update post in the database |
Same. But.... a clue... When using the classic editor plugin, switching to HTML mode and giving it the same Gutenberg-flavoured HTML generated, and specifying the &#; Unicode code, I can save without error.
Whereas even if I use the code editor, not the visual editor, in Gutenberg, I get the "Could not update post in the database" error. It's like Gutenberg is unescaping Unicode, not the other way around. |
I don't think it's related to Gutenberg but more to the REST API somehow. @oldrup do you think you have a specific CDN used on the failing websites? any plugins that are different (security plugins maybe)? One way to try to get more details is to check the network response on your browser's console or your webserver logs. |
@youknowriad Tried again with WordPress 5.5.1, all plugins disabled. Same issue on my host. `XHRPOSThttps://oldrup.dk/wp-json/wp/v2/posts/1979?_locale=user POST
|
I'm really sorry @oldrup :( but I'm not sure we can do anything to help here to be honest. I'm going to close the issue for now as it seems specific to some installs but please reopen if you do find anything that can allow us to reproduce here. |
Same here. Switching to Classic Editor allowed me to save. |
This helped for me: https://stackoverflow.com/questions/63100373/wordpress-unable-to-save-or-update-posts-with-emoji Added to the add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
if ( ! empty( $data['post_content'] ) ) {
$data['post_content'] = wp_encode_emoji( $data['post_content'] );
}
return $data;
}, 99, 2 ); |
@youknowriad
|
I wonder if it has something to do with the server. Would be cool to find the exact failure. Personally I'm still not able to reproduce. |
I was the server. The database was set as utf8mb3 instead of utf8mb4. |
Nice find! That might relate to my experience above - entering the &#; Unicode code in the HTML worked, but raw emoji didn't. Could Gutenburg be submitting the raw emoji and not encoding as an HTML entity? So showing source and putting in HTML entity |
Whatever Gutenberg is doing, with a proper database it should work, and when is not, is giving us information about it. |
I'm having the same issue. Using flag emojis causes a page update to fail. Removing them lets it succeed. |
Here are two other places where this problem has been reported: https://wordpress.org/support/topic/problem-when-saving-with-emoji/#post-17117624 and https://wordpress.org/support/topic/emojis-not-working-in-wordpress-posts/ |
PS: Following these instructions solved the issue for me: https://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8 I didn't have sufficient privileges to just run a SQL command in phpMyAdmin, so I did a modified version of what is given there. I logged into my server via the shell, then generated a list of tables with this: mysql -e "show full tables where Table_Type = 'BASE TABLE'" Then I converted that output to a .sql file (which I named "change_charset.sql") where each table gets a line like this: ALTER TABLE ReplaceWithTableName CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; At the very top of that file put this line: ALTER DATABASE DATABASENAME CHARACTER SET utf8 COLLATE utf8_unicode_ci; Then I uploaded that change_charset.sql file to my server and figured out its path, then executed this command: mysql -u awww -pPASSWORD -h HOST -P PORTNUMBER DATABASENAME < /sites/user/change_charset.sql If you are going to follow my steps, replace PASSWORD, HOST, PORTNUMBER (if needed; if not needed, remove "-P PORTNUMBER"), and DATABASENAME in the above MySQL command with the equivalents for your own server. You can find these in your wp-config.php file in your root HTTP/web directory. |
A combination of two updates fixed this for me: an update to the wp_config.php file and an update to the function.php (which I implemented using the Snippets plugin) rather than updating directly. An example of an emoji that was causing a problem is the mailbox, copied and pasted from here directly into the WP editor: https://emojipedia.org/closed-mailbox-with-raised-flag WP_Config.php Update:
The Function.php update that worked for me is provided by @stormwild above. It uses the wp_encode_emoji function that helps store emojis in your WordPress database using the UTF8 Character set. It can also be referenced at https://developer.wordpress.org/reference/functions/wp_encode_emoji/
Hope this helps someone else, too. |
This helps me out... Thanks |
Thank you so much @kbarkhurst ! It solved the problem I had in my database since I set up my site. It apparently saved emojis as they are and now the emojis getting saved as HTML entity. I only had to hit save on every page and post where I'm using emojis. And don't forget to delete the old revisions with the plain emoji/s. I got the following in my database when I searched for something: It's so weird because all tables are in utf8mb4. |
This has worked for me in 2024, thank you for sharing! |
YESS thank you! :) That fixed it. |
Yes that worked out for me!!
|
Hey
Gutenberg fails saving the post, if it contains the utf-8 symbol Lightning Mood:🗲
https://www.utf8icons.com/character/128498/lightning-mood
See attached screenshot.
Pasting in utf-8 symbols/icons works in any other editor on the planet ✔ ✌
WordPress system health is 100%
Is anyone able to reproduce this issue?
The text was updated successfully, but these errors were encountered: