Resolved
Overview of the issue
Some websites may face the following JavaScript console error in the Translation Management Dashboard or Translation Management Jobs pages:
app.js?ver=5.0.4:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
This error will also produce a series of PHP warnings like the following:
PHP Warning: Cannot modify header information - headers already sent in /app/public/wp-includes/rest-api/class-wp-rest-server.php on line 1258
PHP Stack trace:
PHP 1. {main}() /app/public/index.php:0
PHP 2. require() /app/public/index.php:17
PHP 3. wp() /app/public/wp-blog-header.php:16
PHP 4. WP->main() /app/public/wp-includes/functions.php:1105
PHP 5. WP->parse_request() /app/public/wp-includes/class-wp.php:737
PHP 6. do_action_ref_array() /app/public/wp-includes/class-wp.php:387
PHP 7. WP_Hook->do_action() /app/public/wp-includes/plugin.php:531
PHP 8. WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php:310
PHP 9. call_user_func_array:{/app/public/wp-includes/class-wp-hook.php:286}() /app/public/wp-includes/class-wp-hook.php:286
PHP 10. rest_api_loaded() /app/public/wp-includes/class-wp-hook.php:286
PHP 11. WP_REST_Server->serve_request() /app/public/wp-includes/rest-api.php:309
PHP 12. WP_REST_Server->send_header() /app/public/wp-includes/rest-api/class-wp-rest-server.php:224
PHP 13. header() /app/public/wp-includes/rest-api/class-wp-rest-server.php:1258
The error is specific to websites running PHP 5.6 and is caused by a deprecation warning triggered by PHP when the $HTTP_RAW_POST_DATA
global variable is populated (even if it is not used), as explained here by the author of this change in PHP:
[…] the current way for triggering the deprecated message is a bit sub-optimal (we don’t show you the message when you try to access the $HTTP_RAW_POST_DATA variable, but when $HTTP_RAW_POST_DATA is populated.
The warning explains how to remove the deprecation notice.
Workaround
Editing the php.ini file
- Find and edit your server’s php.ini file.
- Look for a line containing the always_populate_raw_post_data string.
- If the line starts with a semicolon (;), it means it is commented out (and not being used). In this case, remove the semicolon.
- Check that the full line is
always_populate_raw_post_data=-1
(it must end with “=-1”). - Restart your server.
Upgrade PHP
Upgrading PHP to a more recent version (7.1 or greater) will remove the deprecation warning.
PHP 7.1 is much faster than PHP 5.6.
PHP 5.6 reached its end-of-life period on 1st of January 2019. This means that it is a “release that is no longer supported. Users of this release should upgrade as soon as possible, as they may be exposed to unpatched security vulnerabilities.” (source: https://www.php.net/supported-versions.php).
Getting this error even with 7.1. It happened as soon as I turned on Advanced Translation Editor. Even after deactivating WPML, the error remains. I restored from backup, ran it again just to see if would happen again, and yep, same thing. I have Siteground checking on their end, but please let me know if you have this fixed.
Hi giacomoC-11,
This error is not specific to WPML. You will see this error also in the post editor when saving even when WPML is disabled.
There are several tickets in WordPress core about this issue:
– https://github.com/WordPress/gutenberg/issues/11140#issuecomment-433665601
– https://github.com/WordPress/gutenberg/issues/3102
– https://github.com/WordPress/gutenberg/issues/4936
– https://github.com/WordPress/gutenberg/issues/10492
As you can see, WordPress has some plans to have a better error handling which would also include that case, but it would be a way to notify the user, not really to fix the issue. Indeed, this issue must be fixed on the server side, so this is not something we can address. You need to check some possible options with your host provider like the one we suggested in the description.
Why does it only happen when I turn on Advanced Editor? As I said, I restored from backup, and tested the site,. Everything was good. As soon as click the Advnced Editor radio button and click save. I get the error, and then it doesn’t go away. I have to restore from backup again.
Hi giacomoC-11,
The problem that we describe in this errata is global to WordPress and it’s REST API. It also happens on a fresh install with no plugin installed (when you try to save a post with the block editor for instance).
If after restoring your backup you are able to save a post with the block editor, that probably means you have a different problem. I suggest you to open a new ticket on the support forum.