Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login command fails when installing server plugin as a mu-plugin via Composer #69

Open
thunderdw opened this issue Jun 26, 2023 · 0 comments

Comments

@thunderdw
Copy link
Contributor

Problem

I'd like to install the server plugin via Composer as a mu-plugin. I'm doing that by modifying the installer path for the server plugin in my composer.json, like so:

"installer-paths": {
    "path/to/mu-plugins/{$name}/": [
        "type:wordpress-muplugin",
        "aaemnnosttv/wp-cli-login-server",
    ],

This results in a server plugin PHP file installed inside a subdirectory of the mu-plugins folder located at mu-plugins/wp-cli-login-server/wp-cli-login-server.php.

However, the command only checks for the mu-plugin PHP file at mu-plugins/wp-cli-login-server.php.

public static function mustUse()
{
return new MustUseServerPlugin(WPMU_PLUGIN_DIR . '/' . basename(static::PLUGIN_FILE));
}

Since the command is unable to locate that file, it assumes that the plugin is installed as a normal plugin. So when you attempt to execute a command like wp login as 1, the command fails and you get an error like file_get_contents(/path/to/plugins/wp-cli-login-server/wp-cli-login-server.php): Failed to open stream: No such file or directory

This error happens instead of a message that the server plugin isn't installed because the command doesn't test for the location of the server plugin, but rather the existence of the WP_CLI_Login\WP_CLI_Login_Server class.

public static function isActive()
{
return class_exists(WP_CLI_Login_Server::class, false);
}

Potential fixes

  • Alter the mustUse() function above to look for the server plugin in both mu-plugins/wp-cli-login-server.php and mu-plugins/wp-cli-login-server/wp-cli-login-server.php
  • Instead of using constants to define the potential locations of the server plugin, use Reflection to get the location of the server plugin. E.g. (new \ReflectionClass(WP_CLI_Login_Server::class))->getFileName(). IMO this approach is more flexible and better aligns with the isActive() test linked above

Happy to submit a PR if this makes sense

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

No branches or pull requests

2 participants