WP-CLI and separated structure

An issue with WP-CLI and a WordPress installation with separated parts (WP-Core & WP-Content).

For some reason the $_SERVER['DOCUMENT_ROOT'] of PHP in CLI was wrong.
In my case all my Core-files where in wordpress/.
To quickfix this issue just add the following to your wp-config (or ENVabled configuration file):

if(defined( 'WP_CLI' ) && WP_CLI) {
define('WP_CONTENT_DIR', str_replace('wordpress', '', $_SERVER['DOCUMENT_ROOT']) . '/content');
} else {
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/content');
}

Leave a Reply

Your email address will not be published. Required fields are marked *