Fix the "Class 'WP_Metadata_Lazyloader' not found" Error When Trying to Update WordPress Using WP-CLI

Did you recently try to update your WordPress core software, plugins, or themes using the WordPress command line interface? Were you frustrated and dismayed when the update failed and WP-CLI gave you an error like this?

PHP Fatal error:  Class 'WP_Metadata_Lazyloader' not found in /Library/WebServer/Sites/example.dev/wp-includes/meta.php on line 865
Fatal error: Class 'WP_Metadata_Lazyloader' not found in /Library/WebServer/Sites/example.dev/wp-includes/meta.php on line 865

What?! Those are core files it’s talking about there! But before you go and try to reinstall WordPress from scratch, just relax. It’s probably just WP-CLI that needs updated.

Similar to what happened when WordPress 4.4 first came out, older versions of WP-CLI were found to be incompatible with the new core software when WordPress 4.5 was released. Fortunately, this release of WP-CLI fixes everything.

To update, all you need to do is to issue the following three Terminal commands, based on the WP-CLI installation guide:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

That’s it! This should fix any issues you might be running into with WP-CLI being broken after the upgrade to WordPress 4.5.

Also note that going forward, WP-CLI’s Phar file should automatically check for updates and prompt you when the time comes. That (hopefully) means that this is that last post like this I’ll need to make!