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

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

Projects

None yet

4 participants

@whimsy-github

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)

<?php 
/* Short and sweet */
define('WP_USE_THEMES', true);
require('./wordpress/wp-blog-header.php');
?>

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 example.com and WordPress location settings point to example.com/wordpress

wp plugin path should output:

/path/to/public_html/wp-content/plugins

Instead it outputs:

/path/to/public_html/wordpress/wp-content/plugins

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

@whimsy-github

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
Member
scribu commented Sep 23, 2013

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

var_dump($_SERVER['DOCUMENT_ROOT']);
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__).

@whimsy-github

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

(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: http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder

@scribu
Member
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
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.

http://stackoverflow.com/questions/626416/php-server-name-from-command-line

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.

@danielbachhuber
Member

Related #730

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

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