ewww-image-optimizer
ewww-image-optimizer copied to clipboard
S3-Uploads may be incorrectly detected as active
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:
- Create a setup with Composer which installs WordPress, 3-Uploads and EWWW (
composer require johnpbloch/wordpress humanmade/s3-uploads wpackagist-plugin/ewww-image-optimizer
- Activate EWWW but keep S3-Uploads deactivated
- Enable debug mode in EWWW and optimize an image
- 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;
}
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).
Fixed finally, will be in next release!