I client of mine recently upgraded a very basic WordPress install to version 5.6.1. While the update seemed to go well, right at the very end the site died with an error that read something like this; identifying details altered for privacy:
[Sat Feb 06 12:12:11.123456 2021] [fcgid:warn] [pid 128] [client 12.34.56.78:12345] mod_fcgid: stderr: PHP Fatal error: Uncaught Error: Class 'WP_Site_Health' not found in /var/www/html/wp-includes/rest-api.php:321
I have fairly deep experience debugging WordPress and related PHP sites, but this was baffling. According to them they disabled all of the plug-ins and themes and even downloaded a clean archive of WordPress 5.6.1 and did the basic manual upgrade process of retaining the wp-config.php
, .htaccess
and related user specific uploads in the wp-content
directory and the error still shows up.
I’ve read advice like what was posted here on the WordPress forums that basically state one should restore from a backup and try again, but find that advice to be a classic “Hail Mary” play; sometimes it works and other times you are just left in the same exact position as before but with new file modification dates.
So given that the class WP_Site_Health
and the file wp-includes/rest-api.php
are both items that exist in core WordPress, what can be done to quickly patch the system to get it working again?
P.S.: And to truly confirm the files were fine, I did the following:
- Created a Tar/Gzip archive of the whole WordPress install — including all
wp-content
items — and downloaded it to my desktop. - Then I decompressed the archive, went into that directory and ran
git init
inside of it to create a Git repo. - I left the site as-is as the
master
branch and then created a new branch calledtest
. - In that test branch, I manually downloaded a 100% WordPress 5.6.1 install from WordPress directly, manually copied the clean files into the new branch and committed them.
- Then I ran local
git diff master..test
to see what files were changed between the sourcemaster
branch and thetest
branch. The diff said the files from the server versus clean WordPress 5.6.1 files were 100% the same; what was on the server is 100% the same as a clean WordPress install.
wp-config.php
,.htaccess
and related user specific uploads in thewp-content
directory and the error still shows up.”git diff
between the branches. The results? 100% the same… Expect for now the only file changed is the one I indicated in the answer:wp-includes/rest-api.php
. So your advice is well intentioned — mucking with core files is not ideal — but honestly there was no difference between the server files and clean WordPress 5.6.1.