Failure to correctly find wp-content/plugins or themes #785

whimsy-github opened this Issue Sep 23, 2013 · 6 comments


None yet

4 participants


I cannot get wp-cli to find my plugin or theme directories the way I've structured wordpress files (relative to webserver root)

index.php: (copied from WordPress install with path modified to send it to the subdirectory)

/* Short and sweet */
define('WP_USE_THEMES', true);

wordpress/ -->> Wordpress install as downloaded, no edited files
wp-content/ -->> MY plugins and themes under this

wp-config.php: (relevant excerpt below)

if ($_SERVER['DOCUMENT_ROOT'] == "")
   $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content' );

Note: I added the first two lines in an attempt to work around this problem. My blog behaves well on both my production web host and my local test install (MAMP) without it.

In my database, the blog location settings point to and WordPress location settings point to

wp plugin path should output:


Instead it outputs:


wp plugin list shows me Hello Dolly and Akismet from the default wordpress file structure, instead of all the plugins I've got installed on my blog


Jezza:public_html flutterby$ wp --info
PHP binary: /Applications/MAMP/bin/php/php5.3.14/bin/php
PHP version: 5.3.14
php.ini used: /Applications/MAMP/bin/php/php5.3.14/conf/php.ini
WP-CLI root: /Users/flutterby/.wp-cli/vendor/wp-cli/wp-cli
WP-CLI config: /path/to/my/wp-cli.yml
WP-CLI version: 0.11.2

scribu commented Sep 23, 2013

Modify wp-config.php so that it looks like this:

if ($_SERVER['DOCUMENT_ROOT'] == "")
  $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);

And tell me what wp plugin path outputs.

Also, why do you use $_SERVER['DOCUMENT_ROOT'] to define WP_CONTENT_DIR, instead of just dirname(__FILE__).


wp plugin path now outputs:
string(66) "/path/to/public_html/wordpress"

(plugin path is unchanged)

Now my local (testing) MAMP webserver outputs:
string(56) "/path/to/public_html"

I didn't have any reason I can identify to choose $_SERVER['DOCUMENT_ROOT'] instead of dirname(FILE). I just took the example from the WordPress Codex here:

scribu commented Sep 23, 2013

Ok, I edited the codex page. If you replace $_SERVER['DOCUMENT_ROOT'] with dirname(__FILE__), WP-CLI should work fine.

I'll keep this ticket open in case we can set $_SERVER['DOCUMENT_ROOT'] correctly from WP-CLI.

Ipstenu commented Sep 6, 2015

Just FYI, this is because PHP is a bit of an idiot.

The SERVER_NAME is not available when you run PHP from the CLI for that very same reason.

When you run PHP from the CLI, you start your own PHP intepreter that runs whatever code you passed to it, without any kind of server. So from the CLI, PHP knows nothing about your web server that you do not explicitly tell it.

You're not doing it wrong, PHP is doing it right and it's unexpected. WP-CLI doesn't fully populate the #_SERVER array because PHP can't via command line :( Not an answer, but hopefully an explanation that helps.


Related #730

@danielbachhuber danielbachhuber added this to the 0.25.0 milestone Aug 23, 2016
@danielbachhuber danielbachhuber referenced this issue in wp-cli/ Aug 23, 2016

Add `$_SERVER['document_root']` to common issues #203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment