humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.94k stars 391 forks source link

Installation with release ZIP and composer install does not register the WPCLI command correctly #530

Open korridor opened 3 years ago

korridor commented 3 years ago

Steps to reproduce

Given a wordpress instance without another plugin that provides a \Aws\S3\S3Client class.

Now everything works fine, but if I run any wpcli command (even works with wp user list) the following error occurs:

Error: Callable "S3_Uploads\\WP_CLI_Command" does not exist, and cannot be registered as `wp s3-uploads`.

I think the problem is that the action plugins_loaded/S3_Uploads\\init happens after WP_CLI::add_command(..) and the init function requires the autoload.php, which loads S3_Uploads\\WP_CLI_Command.

I fixed it by moving the following code to the begin of the s3-uploads.php file.

if ( ! class_exists( '\\Aws\\S3\\S3Client' ) ) {
        // Require AWS Autoloader file.
       require_once dirname( __DIR__ ) . '/vendor/autoload.php';
}
korridor commented 3 years ago

Given what @modelm is experiencing in #519, the given solution might not be the best idea.

Maybe it would be a good idea to add a constant like S3_UPLOADS_COMPOSER to decide whether autoload.php should be required or not.

laurent-le-graverend commented 3 years ago

Experiencing the same issue with the same steps.

korridor commented 3 years ago

If the maintainers are open to the solution with the constant, I would be happy to provide a pull request.

luco commented 3 years ago

Same here.

fabiomontefuscolo commented 3 years ago

I think that would be more self-contained if added directly into the plugin functions.php ... something like proposed by @korridor

// wp-content/plugins/s3-uploads/s3-uploads.php
if ( ! class_exists( '\\Aws\\S3\\S3Client' ) ) {
        // Require AWS Autoloader file.
       require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}
scottg369 commented 3 years ago

was getting the following error Error: Callable "S3_Uploads\WP_CLI_Command" does not exist, and cannot be registered as wp s3-uploads.

Added the class_exists() code to s3-uploads.php - this fixed the error

dingo-d commented 3 years ago

Happened to me as well when I tried to install the plugin using WPCLI

wp plugin install "https://github.com/humanmade/S3-Uploads/archive/refs/tags/3.0.3.zip" --force

$ wp plugin list

+--------------------------+----------+-----------+------------+
| name                     | status   | update    | version    |
+--------------------------+----------+-----------+------------+
| query-monitor            | inactive | available | 3.6.7      |
| S3-Uploads               | inactive | none      | 3.0.0-beta |
+--------------------------+----------+-----------+------------+

$ wp plugin activate S3-Uploads

Error: Callable "S3_Uploads\\WP_CLI_Command" does not exist, and cannot be registered as `wp s3-uploads`.

Also, the version name is not correct.

This is happening on all v3 releases.

henrywright commented 2 years ago

Hi @korridor

I fixed it by moving the following code to the begin of the s3-uploads.php file.

I did the same but fyi I had to adjust the file path.

require_once __DIR__ . '/vendor/autoload.php';
halburgiss commented 2 years ago

It seems like this plugin is no longer maintained ... not good.

MattWilliamsDev commented 1 year ago

Tagging @kovshenin for visibility on this duplicate issue as well as he seems to be the only one looking at issues recently.