I knew something wasn’t right when I saw WP CLI Cannot redeclare wp_get_server_protocol. So I did a little research on it but it seems like the cause for this can be many various things. In the end I was able to fix it. In this post I will try to list all fixes I found.
WP CLI Cannot redeclare wp_get_server_protocol
According to it’s maintainers WP CLI is using it’s own version of wp-settings.php
but before it can use it’s own version it’s scraping for all constant that are defined in your wp-config.php
. Herein lies the first path to trouble.
Causes for Fatal error: Cannot redeclare wp_get_server_protocol()
1. A custom wp-settings.php file is most likely the cause of you trouble
This was my case since I was using WP CLI on my local development but I was hosting the website on Pantheon. Truth be said Pantheon uses a very advanced wp-settings.php file, this just makes. In the end I had to use a different version of wp-settings.php on my local then on the server.
- renamed original
wp-config.pgp
->wp-config-original.php
- created new wp-config.php from https://gist.github.com/lehelmatyus/3eb64e976be9d44f3a6ba186778e6073
- added both these files to .gitignore
2. One of you plugins or your theme is calling for wp-includes\load.php
Most likely you plugin should not be calling for for it in the first place since it’s already included but if this is the case either do 2.1 or 2.2
2.1 Call WP CLI with these two parameter in your WordPress directory
wp --skip-themes --skip-plugins
this should bypass the errors.
2.2 Clean up your theme and plugins
Look for lines like require('wp-includes/load.php')
or include(functions.php')
and try to do some cleanup.
WP CLI
To know more about using WP CLI to manage plugins visit my previous post Managing WordPress plugins with WP CLI.
Install WP CLI form the wp-cli.org website.
Cheers! Please Like♥ the page if you found this useful!
Excellent post, thank you, I had the following error:
root@4d9a7c8467b5:/var/www/html# sudo -u www-data — php wp-cli.phar plugin list –debug -vv
Debug (bootstrap): No readable global config found (0.129s)
Debug (bootstrap): No project config found (0.129s)
Debug (bootstrap): argv: wp-cli.phar plugin list –debug -vv (0.129s)
Debug (bootstrap): ABSPATH defined: /var/www/html/ (0.132s)
Debug (bootstrap): Begin WordPress load (0.132s)
Debug (bootstrap): wp-config.php path: /var/www/html/wp-config.php (0.132s)
Debug (commandfactory): No doc comment for plugins. (0.216s)
Notice: Constant WPINC already defined in /var/www/html/wp-settings.php on line 16
Fatal error: Cannot redeclare wp_get_server_protocol() (previously declared in /var/www/html/wp-includes/load.php:16) in /var/www/html/wp-includes/load.php on line 21
My solution was to use your Git wp-config.php snippet; my wp-config.php had obviously home-edited by other people with strange french text.
Hi Jonathan,
Thank you for your comment and debug data. I am glad you were able to use the wp-config I provided!
Cheers!
Lehel