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.

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.


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!