S3-Uploads icon indicating copy to clipboard operation
S3-Uploads copied to clipboard

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

Open modelm opened this issue 3 years ago • 1 comments

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 avatar May 07 '21 18:05 modelm

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().

modelm avatar May 17 '21 22:05 modelm