Skip to content

"Updating failed" in the WordPress block editor: the real fix

"Updating failed" and "Publishing failed" mean the block editor could not get JSON back from the REST API. Diagnose the route, not the post: permalinks, WAF rules, redirects, stray PHP output and cached /wp-json/ responses.

“Updating failed.” “Publishing failed.” “The response is not a valid JSON response.” All three mean the same thing, and none of them is about your post. The block editor saves by sending POST /wp-json/wp/v2/posts/<id> and expecting a JSON document back. When anything between the browser and PHP answers with something else — a 404 page, a WAF block page, a redirect, or JSON with a PHP warning glued to the front of it — the editor cannot parse the reply and prints that one generic string. The check that resolves most cases takes ten seconds: load https://example.com/wp-json/wp/v2/types in a browser tab. If that is not a wall of JSON with a 200 status, you have found the fault, and it has nothing to do with the content you were writing.

What you’ll accomplish

  • Read the actual HTTP response behind the message instead of guessing from the message itself.
  • Tell a broken rewrite apart from a WAF block, a scheme mismatch, and stray PHP output — four causes that look identical in the editor.
  • Fix each of them at the layer that owns it, with commands whose output tells you whether it worked.
  • Verify the fix end to end with an authenticated REST write, not just by clicking Update and hoping.
  • Know when the REST API is broken on purpose and the right move is something other than “make it work again”.

Prerequisites

  • WordPress 5.0 or later. The block editor has depended on the REST API since it shipped; nothing here applies to the classic editor, which posts to post.php and never touches /wp-json/.
  • Shell access with WP-CLI 2.x. Confirm with wp --info, which prints the WP-CLI version and the PHP binary in use.
  • Ability to read your web server error log and, on a cPanel or managed host, the ModSecurity audit log. Without logs, several branches below end in a shrug.
  • A browser with DevTools. Chrome, Firefox and Safari all show the failing request; you need the Network tab, not the Console.
  • The examples use example.com and post ID 12. Substitute your own everywhere.

How it works

Every save in the block editor is an HTTP request that the JavaScript layer expects to answer in JSON. Autosaves go to /wp-json/wp/v2/posts/<id>/autosaves, real saves to /wp-json/wp/v2/posts/<id>, and media uploads to /wp-json/wp/v2/media. The editor calls JSON.parse() on whatever comes back. If the parse throws, the store dispatches a save failure, and the notice component has exactly one string for it. That is why a permalink problem, a firewall rule and a deprecation notice from an abandoned plugin all surface as the same six words.

The route from the browser to the database has more hops than most people expect, and every hop can produce a non-JSON answer.

Diagram of the six layers a WordPress block editor save request passes through, each with the HTTP status it returns when it breaks

Two details make this tractable. First, WordPress serves the REST API from two addresses: the pretty one at /wp-json/, which only exists if the rewrite rules are in place, and the always-available fallback at /?rest_route=/, which is plain index.php with a query string. Comparing the two tells you instantly whether the problem is the rewrite layer or something deeper. Second, the REST API answers unauthenticated requests with JSON too. An anonymous POST to a post route should come back as 401 with a body of {"code":"rest_not_logged_in",...}. If it comes back as HTML, something in front of PHP intercepted the request and WordPress never saw it.

Those two facts turn the whole problem into a short decision tree.

Decision tree mapping the HTTP status and response body of a curl request to the specific cause and the command that fixes it

Step-by-step

  1. Capture the failing request in DevTools before you change anything. Open the post, open DevTools, select the Network tab, filter to Fetch/XHR, then click Update. One request to a wp-json URL will be red or will have an unexpected status. Click it and read three things: the Status line, the content-type response header, and the first few lines of the Response tab. That response body is the entire diagnosis. Everything below just confirms it from the shell.

  2. Probe the REST root from outside the browser.

    curl -i -s https://example.com/wp-json/wp/v2/types | head -n 12

    A healthy site starts with HTTP/2 200, a content-type: application/json; charset=UTF-8 header, and a body beginning {"post":{"description". Anything else is your answer. For a one-line summary across several sites:

    curl -s -o /dev/null -w '%{http_code} %{content_type} %{redirect_url}\n' https://example.com/wp-json/wp/v2/types

    Expected: 200 application/json; charset=UTF-8 with an empty third field.

  3. Split rewrite failures from PHP failures with the query-string fallback.

    curl -s -o /dev/null -w '%{http_code}\n' 'https://example.com/?rest_route=/wp/v2/types'

    If this returns 200 while /wp-json/wp/v2/types returned 404, the REST API itself is healthy and the rewrite layer is broken. If both return 404, the problem is inside PHP and you should skip to step 7.

  4. Rebuild the rewrite rules when /wp-json/ is a 404.

    wp rewrite flush --hard

    Expected output: Success: Rewrite rules flushed. The --hard flag also regenerates the .htaccess block on Apache, which is the part that usually went missing. Confirm the block is back:

    grep -A5 'BEGIN WordPress' /path/to/site/.htaccess

    You want to see the RewriteRule . /index.php [L] line. On nginx there is no .htaccess; the server block needs try_files $uri $uri/ /index.php?$args; inside location /, and a flush cannot create it for you. If the permalink structure is set to Plain, /wp-json/ never works by design — the pretty route requires a rewrite structure:

    wp option get permalink_structure

    An empty result means Plain. Set something and flush. There is more on this failure mode in WordPress 404 troubleshooting.

  5. Line up siteurl, home and the scheme the browser is actually using when you see a 301 or 302.

    wp option get siteurl
    wp option get home

    Both should print https://example.com — same scheme, same host, no trailing slash, and matching what is in the address bar. If they do not:

    wp option update siteurl 'https://example.com'
    wp option update home 'https://example.com'

    Expected: Success: Updated 'siteurl' option. If that command reports success but nothing changes, constants are overriding the options:

    wp config get WP_HOME

    A value here wins over the database, so edit wp-config.php instead. Behind a load balancer that terminates TLS, PHP may also see the request as plain HTTP and build http:// REST URLs on an HTTPS page; the fix is to trust the proxy header in wp-config.php rather than to change the options. Mixed-scheme sites have a broader failure surface than just the editor.

  6. Read the firewall log when the status is 403, 406 or 503. First confirm the block is in front of PHP by sending an anonymous write:

    curl -i -s -X POST 'https://example.com/wp-json/wp/v2/posts/12' -H 'Content-Type: application/json' -d '{"content":"<p>hello</p>"}' | head -n 15

    The correct answer is HTTP/2 401 with a JSON body containing rest_not_logged_in. That means REST is reachable and only your credentials were missing. An HTML error page instead means a WAF, a CDN rule or ModSecurity ate the request. On a cPanel host, find the rule:

    grep -F 'wp-json' /usr/local/apache/logs/modsec_audit.log | tail -n 20

    You are looking for the [id "..."] token in the matching entry. Give that ID to your host, or disable that single rule for the domain — never the whole engine. Reading these entries is its own skill; see reading the ModSecurity audit log.

  7. Find what PHP printed before the JSON when the status is 200 but the body will not parse.

    curl -s https://example.com/wp-json/wp/v2/types | head -c 200

    A clean response starts with {. If it starts with Warning:, Notice:, Deprecated:, whitespace or an invisible byte-order mark, that is the corruption. Turn on file logging so the source is named:

    wp config set WP_DEBUG true --raw
    wp config set WP_DEBUG_LOG true --raw
    wp config set WP_DEBUG_DISPLAY false --raw

    Expected: Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the value true. Re-run the curl, then read wp-content/debug.log — the newest entry names the file and line. WP_DEBUG_DISPLAY false matters: it stops the notice being printed into the response while you investigate, which alone can make saving work again. See WordPress debug modes explained for what each constant does. For a byte-order mark hiding at the top of a theme or plugin file:

    grep -rl $'\xEF\xBB\xBF' wp-content/themes wp-content/mu-plugins

    Any file listed needs re-saving without the BOM.

  8. Bisect plugins if REST is still refusing from inside PHP. Some security plugins hook rest_authentication_errors and reject every request that is not from a logged-in user with a token they issue. Grep for it first — that is faster than deactivating anything:

    grep -rn 'rest_authentication_errors' wp-content/plugins wp-content/mu-plugins

    If the grep is inconclusive, bisect:

    wp plugin deactivate --all
    curl -s -o /dev/null -w '%{http_code}\n' https://example.com/wp-json/wp/v2/types

    A 200 here confirms a plugin. Reactivate in batches with wp plugin activate <slug> and re-run the curl after each until the status flips.

  9. Stop the edge from caching or challenging /wp-json/.

    curl -s -o /dev/null -D - https://example.com/wp-json/wp/v2/types | grep -i -E 'cf-cache-status|x-cache|age:'

    cf-cache-status: DYNAMIC or BYPASS is correct. HIT means the API is being served from cache, which breaks nonces and returns other users’ data. Add a cache rule that bypasses /wp-json/*, and check that bot-protection or “under attack” modes are not challenging it — a challenge page is HTML, and HTML is not JSON.

Validate it works

Run the three checks in order. All three must pass.

curl -s -o /dev/null -w '%{http_code} %{content_type}\n' https://example.com/wp-json/wp/v2/types

Expected: 200 application/json; charset=UTF-8.

curl -s -o /dev/null -w '%{http_code}\n' -X POST 'https://example.com/wp-json/wp/v2/posts/12'

Expected: 401. A JSON 401 proves the request reached WordPress and was rejected by WordPress, which is exactly what you want from an anonymous caller.

Then do a real authenticated write. Create an application password for your account under Users, Profile, and use it:

curl -i -s -u 'yourlogin:APPLICATION PASSWORD HERE' -X POST 'https://example.com/wp-json/wp/v2/posts/12' -H 'Content-Type: application/json' -d '{"title":"REST write test"}' | head -n 8

Expected: HTTP/2 200 and a JSON body whose title.raw is REST write test. That is the same operation the editor performs. If curl can write and the editor still cannot, the remaining difference is the browser: nonce, cookies or an extension. Finish by opening the post, typing a character and clicking Update — you should get the “Post updated.” notice and a View Post link.

Troubleshooting

The API is fine but only some posts fail to save. This is a ModSecurity or WAF rule matching the content of the request body, not the route. Posts containing <script>, SQL-looking text, base64 blobs or certain URL patterns trip generic rules. The tell is that an empty edit saves and a real edit does not. Get the rule ID from the audit log entry that matches the timestamp of your click.

Saving fails only on long posts. You are hitting a size or input limit rather than a REST problem. Check the PHP side:

wp eval 'echo ini_get("post_max_size"), " / ", ini_get("max_input_vars"), "\n";'

Then check the web server: LimitRequestBody on Apache, client_max_body_size on nginx, and SecRequestBodyLimit in ModSecurity. A truncated body usually returns 413 or an empty response.

It works in one browser and fails in another. Content blockers ship filter lists that match paths containing wp-json, and a stale service worker can serve a cached HTML shell to a JSON request. Test in a private window with extensions disabled. If that works, the server is fine and the fix belongs on the workstation.

403 with rest_cookie_invalid_nonce after a long editing session. The nonce aged out. Normally the Heartbeat API refreshes it in the background, so this only appears when heartbeat is disabled by an optimization plugin or blocked by the edge. Confirm by watching the Network tab for a request to admin-ajax.php with action=heartbeat every 15 to 60 seconds. If it is absent, re-enable heartbeat for the editor screen. In the meantime, a hard reload of the editor issues a new nonce; your draft survives in the browser autosave.

Everything passes but the editor still fails silently. Check for a JavaScript error in the Console. A block plugin that throws during serialization can abort the save before any request is sent — in that case the Network tab shows no wp-json request at all, which rules out this entire guide.

When this is the wrong approach

If someone deliberately installed a “disable REST API” plugin, restoring the endpoint wholesale undoes a decision that may have been correct. The better answer is to allowlist the routes the editor needs, or to standardize on the classic editor. Likewise, if a ModSecurity rule is blocking a save, disabling the engine to make the message go away trades an annoyance for an exposure — get the rule ID and disable that rule for that vhost.

Do not leave WP_DEBUG on in production once you have your answer, and never enable WP_DEBUG_DISPLAY there; you turned it on to name a file, not to publish stack traces.

Finally, if exactly one person on one machine sees the failure and every command in this guide passes, the fault is on their side of the connection — an extension, a proxy, a corporate filter. Rebuilding rewrite rules on a healthy server will not help them, and you will have changed production for nothing.

The official reference for the routes and status codes used here is the WordPress REST API handbook, and the flush behaviour in step 4 is documented under the wp rewrite command.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.