humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.93k stars 389 forks source link

Existing AWS SDK class causes fatal error because vendor/autoload.php is not required #515

Open modelm opened 3 years ago

modelm commented 3 years ago

Version c6c23f1f98016e45ca275f288d5ec27513cabfec In inc/namespace.php init():

    // Ensure the AWS SDK can be loaded.
    if ( ! class_exists( '\\Aws\\S3\\S3Client' ) ) {
        // Require AWS Autoloader file.
        require_once dirname( __DIR__ ) . '/vendor/autoload.php';
    }

On this install, this class does already exist because another plugin is using the AWS SDK. However the S3-Uploads plugin still needs to load /vendor/autoload.php to avoid this error:

Fatal error: Uncaught Error: Class 'S3_Uploads\Plugin' not found in /app/wordpress/wp-content/plugins/S3-Uploads/inc/namespace.php:32 Stack trace: #0 /app/wordpress/wp-includes/class-wp-hook.php(287): S3_Uploads\init('') #1 /app/wordpress/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #2 /app/wordpress/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #3 /app/wordpress/wp-settings.php(420): do_action('plugins_loaded') #4 /app/wordpress/wp-config.php(105): require_once('/app/wordpress/...') #5 /app/wordpress/wp-load.php(37): require_once('/app/wordpress/...') #6 /app/wordpress/wp-admin/admin.php(34): require_once('/app/wordpress/...') #7 /app/wordpress/wp-admin/plugins.php(10): require_once('/app/wordpress/...') #8 {main} thrown in /app/wordpress/wp-content/plugins/S3-Uploads/inc/namespace.php on line 32 

Just removing the condition seems to work fine. Why not always require the autoload file?

modelm commented 3 years ago

To avoid a related error with WP CLI, the require line should be closer to the top of the file under namespace instead of inside init().