Skip to content

WP-CLI's use of composer is interfering with site's usage of composer #4632

Description

@AaronHolbrook

I am running into an issue with WP CLI and composer.

It appears to be due to WP CLI now utilizing composer prior to loading the WP application logic. More specifically, as I am using composer myself in my application logic to load and handle my own dependencies, when it comes time to call upon a class that should be auto-loadable it fatals out as it is unable to find it.

Steps to reproduce:

  1. In wp-content/ create a composer.json file with the following:
{
	"config": {
		"preferred-install": "dist",
		"vendor-dir": "mu-plugins/app/vendor"
	},
	"extra": {
		"installer-paths": {
			"mu-plugins/{$name}/": [
				"type:wordpress-muplugin"
			]
		}
	},
	"require": {
		"php": ">=5.5",
		"composer/installers": "~1.0.12",
		"arrilot/dotenv-php": "^1.0"
	}
}
  1. In wp-content/mu-plugins/ create the directory app and a file inside app.php with the following:
<?php
require_once __DIR__ . '/vendor/autoload.php';
/**
 * Load dotenv if .env file is present
 */
$vars = Arrilot\DotEnv\DotEnv::all();
  1. Load mu-plugins/app/app.php by creating a load.php in mu-plugins/load.php with the following:
<?php
require_once __DIR__ . '/app/app.php';
  1. Run composer update at the wp-content/ directory path.

  2. Load the site in a browser, see that it loads correctly/fine and properly executes the app.php logic.

  3. Attempt to run wp on the same site, and see that it fatals on the Arrilot\DotEnv\DotEnv load attempt:

Fatal error: Uncaught Error: Class 'Arrilot\DotEnv\DotEnv' not found in /var/www/html/sites/wordpress/htdocs/wp-content/mu-plugins/app/app.php:8
Stack trace:
#0 /var/www/html/sites/wordpress/htdocs/wp-content/mu-plugins/load.php(2): require_once()
#1 /var/www/html/sites/wordpress/htdocs/wp-settings.php(260): include_once('/var/www/html/s...')
#2 phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1105): require('/var/www/html/s...')
#3 phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1032): WP_CLI\Runner->load_wordpress()
#4 phar:///usr/local/bin/wp/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#5 phar:///usr/local/bin/wp/php/bootstrap.php(75): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#6 phar:///usr/local/bin/wp/php/wp-cli.php(23): WP_CLI\bootstrap()
#7 phar:///usr/local/bin/wp/php/boot-phar.php(8): include('phar:///usr/loc...')
#8 /usr/local/bin/wp(4): include('phar:///usr/loc...')
#9 {main}
  thrown in /var/www/html/sites/wordpress/htdocs/wp-content/mu-plugins/app/app.php on line 8

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions