The Fix for “Publishing failed. Error message: The response is not a valid JSON response.”

I was a Gutenberg early adopter, and – after all the doom and gloom – turns out it’s a pretty nifty piece of kit!

But last weekend I hit the Publish button on a new blog post, and I got this error message:

Publishing failed. Error message: The response is not a valid JSON response.

Initially I thought there might be a weird, non-ASCII character in my content, because I had copied and pasted some code. So I removed the content, hit Publish again, this time no problem. Then I manually wrote a few paragraphs, and hit Update, whereupon I got this error message:

Updating failed. Error message: The response is not a valid JSON response.

What the heck is going on!?

I did some quick searching, and it turns out that a few people have bumped into this issue, but no one seemed to have a solution. Some said hosting security settings, others said plugin conflicts, still others said it was a Gutenberg bug and just wait for the next release.

With no obvious culprit and no obvious solution, I decided to debug it myself. I went through the standard procedure of reducing complexity:

  1. Ensure everything is up to date
  2. Disable plugins
  3. Change theme to basic WordPress theme
  4. Reinstall WordPress
  5. Reset Permalinks
  6. Remove .htaccess file

Still no luck! How is this possible? Perhaps I really did need to wait for the next WordPress release…?

While I was accessing the filesystem to remove the .htaccess file, I noticed that there was also a .user.ini file, which was created by the Wordfence plugin when optimizing its firewall. The file contained the following code:

; Wordfence WAF
auto_prepend_file = '/home/accountname/public_html/wordfence-waf.php'
; END Wordfence WAF

It seems that even with the WordFence plugin deactivated, the Wordfence firewall was still in place via this file. As soon as I removed the .user.ini file, I could publish and update again!

So that’s the cause. But we still need a solution. If you’ve come across this issue, let me know how you resolved it. In the meantime, I will continue testing and see if I can ensure Gutenberg and Wordfence play nice together.

Leave a Comment