ewww-image-optimizer icon indicating copy to clipboard operation
ewww-image-optimizer copied to clipboard

S3-Uploads may be incorrectly detected as active

Open ocean90 opened this issue 2 years ago • 1 comments

Describe the bug It's possible to install S3-Uploads via Composer which provides an autoloader for all the classes. This means that any class_exists() check will always return true for S3_Uploads\Plugin.

To Reproduce Steps to reproduce the behavior:

  1. Create a setup with Composer which installs WordPress, 3-Uploads and EWWW (composer require johnpbloch/wordpress humanmade/s3-uploads wpackagist-plugin/ewww-image-optimizer
  2. Activate EWWW but keep S3-Uploads deactivated
  3. Enable debug mode in EWWW and optimize an image
  4. The log file will include the message s3-uploads detected, deferring resize_upload.

Expected behavior Adjustments for S3-Uploads should only be done if the plugin is active.

Additional context The plugin has currently two ways to check if the plugin is active. Examples:

  • https://github.com/nosilver4u/ewww-image-optimizer/blob/d5b0dab2dc83869199241b0e14d3568ad478f3b8/common.php#L818-L821
  • https://github.com/nosilver4u/ewww-image-optimizer/blob/d5b0dab2dc83869199241b0e14d3568ad478f3b8/common.php#L1974-L1979

Maybe these should be combined into a reusable function. The function should set the autoload parameter for class_exists() to false and should probably check s3_uploads_enabled() too.

Example:

function ewww_image_optimizer_s3_uploads_enabled() {
	if ( class_exists( 'S3_Uploads\Plugin', false ) && function_exists( 'S3_Uploads\enabled' ) && \S3_Uploads\enabled() ) {
		return true;
	}

	if ( class_exists( 'S3_Uploads', false ) && function_exists( 's3_uploads_enabled' ) && s3_uploads_enabled() ) {
		return true;
	}

	return false;
}

ocean90 avatar Jan 21 '22 14:01 ocean90

Hi @ocean90, thanks for providing the report, that's not a setup I've seen before, but definitely makes sense. If you're up for making a pull request and testing it out, that would be amazing, otherwise I'll work on it when I have time later this month (or next).

nosilver4u avatar Jan 21 '22 17:01 nosilver4u

Fixed finally, will be in next release!

nosilver4u avatar Sep 22 '22 04:09 nosilver4u