From 1a0fa52d7e06d3ef51ea40c0443d0d39797fefde Mon Sep 17 00:00:00 2001 From: tijmen Date: Tue, 8 Apr 2025 23:01:39 +0200 Subject: [PATCH 1/5] Only check local file setting if plugin is active, check if option is available --- src/compatibility/as3cf/class-tiny-as3cf.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compatibility/as3cf/class-tiny-as3cf.php b/src/compatibility/as3cf/class-tiny-as3cf.php index 09f7ef60..45b96c3b 100644 --- a/src/compatibility/as3cf/class-tiny-as3cf.php +++ b/src/compatibility/as3cf/class-tiny-as3cf.php @@ -52,7 +52,13 @@ public static function is_active() { } public static function remove_local_files_setting_enabled() { + if ( ! Tiny_AS3CF::is_active() ) { + return false; + } $settings = get_option( 'tantan_wordpress_s3' ); + if ( !is_array( $settings ) ) { + return false; + } return array_key_exists( 'remove-local-file', $settings ) && $settings['remove-local-file']; } From 2b564f15a2fb114af441d49ab91766b0b02750d0 Mon Sep 17 00:00:00 2001 From: tijmen Date: Tue, 8 Apr 2025 23:01:49 +0200 Subject: [PATCH 2/5] Add tests --- test/helpers/wordpress.php | 1 + test/unit/compatibility/TinyAC3SFTest.php | 113 ++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 test/unit/compatibility/TinyAC3SFTest.php diff --git a/test/helpers/wordpress.php b/test/helpers/wordpress.php index ec5d35f8..933a9f2b 100644 --- a/test/helpers/wordpress.php +++ b/test/helpers/wordpress.php @@ -75,6 +75,7 @@ public function __construct( $vfs ) { $this->addMethod( 'current_user_can' ); $this->addMethod( 'wp_get_attachment_metadata' ); $this->addMethod( 'is_admin' ); + $this->addMethod( 'is_plugin_active' ); $this->defaults(); $this->create_filesystem(); } diff --git a/test/unit/compatibility/TinyAC3SFTest.php b/test/unit/compatibility/TinyAC3SFTest.php new file mode 100644 index 00000000..42d6ce20 --- /dev/null +++ b/test/unit/compatibility/TinyAC3SFTest.php @@ -0,0 +1,113 @@ +wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return $plugin_name === 'amazon-s3-and-cloudfront-pro/amazon-s3-and-cloudfront-pro.php'; + } + ); + + $tiny_settings = new Tiny_Settings(); + $tiny_ac3sf = new Tiny_AS3CF($tiny_settings); + + $this->assertTrue(Tiny_AS3CF::is_active()); + } + + public function test_is_active_when_lite_is_enabled() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return $plugin_name === 'amazon-s3-and-cloudfront/wordpress-s3.php'; + } + ); + + + $this->assertTrue(Tiny_AS3CF::is_active()); + } + + public function test_is_not_active() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return false; + } + ); + + + $this->assertFalse(Tiny_AS3CF::is_active()); + } + + public function test_remove_local_enabled_is_false_when_plugin_inactive() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return false; + } + ); + + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); + } + + public function test_remove_local_false_when_option_not_exists() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return true; + } + ); + + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); + } + + public function test_remove_local_false_when_option_is_false() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return true; + } + ); + + $this->wp->addOption('tantan_wordpress_s3', array( + 'remove-local-file' => false, + )); + + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); + } + + public function test_remove_local_true_when_option_is_true() + { + $this->wp->stub( + 'is_plugin_active', + function ($plugin_name) { + return true; + } + ); + + $this->wp->addOption('tantan_wordpress_s3', array( + 'remove-local-file' => true, + )); + + $this->assertTrue(Tiny_AS3CF::remove_local_files_setting_enabled()); + } +} From 4877d76dface4cf42ba73beab34c8ada5e287edf Mon Sep 17 00:00:00 2001 From: tijmen Date: Tue, 8 Apr 2025 23:01:56 +0200 Subject: [PATCH 3/5] Add debug script --- .vscode/launch.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..bdc5238e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for XDebug", + "type": "php", + "request": "launch", + "port": 9003 + } + ] + } \ No newline at end of file From b4a714645caa9b6a60f5bc316a4f3adf499b8d41 Mon Sep 17 00:00:00 2001 From: tijmen Date: Tue, 8 Apr 2025 23:03:47 +0200 Subject: [PATCH 4/5] 3.5.1 --- readme.txt | 5 ++++- src/class-tiny-plugin.php | 2 +- tiny-compress-images.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/readme.txt b/readme.txt index da29d7fa..7993ad46 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://tinypng.com/ Tags: compress images, compression, image size, page speed, performance Requires at least: 4.0 Tested up to: 6.7 -Stable tag: 3.5.0 +Stable tag: 3.5.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -127,6 +127,9 @@ A: Yes! After installing the plugin, go to *Media > Bulk Optimization*, and clic A: You can upgrade to a paid account by adding your *Payment details* on your [account dashboard](https://tinypng.com/dashboard/api). Additional compressions above 500 will then be charged at the end of each month as a one-time fee. == Changelog == += 3.5.1 = +* Will only check local file removal if AS3CF is active + = 3.5.0 = * Support files uploaded through the WordPress REST API * Removed notification on WooCommerce incompatibility diff --git a/src/class-tiny-plugin.php b/src/class-tiny-plugin.php index 90d90834..ead763fc 100644 --- a/src/class-tiny-plugin.php +++ b/src/class-tiny-plugin.php @@ -18,7 +18,7 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ class Tiny_Plugin extends Tiny_WP_Base { - const VERSION = '3.5.0'; + const VERSION = '3.5.1'; const MEDIA_COLUMN = self::NAME; const DATETIME_FORMAT = 'Y-m-d G:i:s'; diff --git a/tiny-compress-images.php b/tiny-compress-images.php index 3aaa67e5..307353f4 100644 --- a/tiny-compress-images.php +++ b/tiny-compress-images.php @@ -2,7 +2,7 @@ /** * Plugin Name: TinyPNG - JPEG, PNG & WebP image compression * Description: Speed up your website. Optimize your JPEG, PNG, and WebP images automatically with TinyPNG. - * Version: 3.5.0 + * Version: 3.5.1 * Author: TinyPNG * Author URI: https://tinypng.com * Text Domain: tiny-compress-images From d834f6526a52ce642c098dad83d49bce1910bdf2 Mon Sep 17 00:00:00 2001 From: tijmen Date: Tue, 8 Apr 2025 23:08:09 +0200 Subject: [PATCH 5/5] Format --- src/compatibility/as3cf/class-tiny-as3cf.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compatibility/as3cf/class-tiny-as3cf.php b/src/compatibility/as3cf/class-tiny-as3cf.php index 45b96c3b..45e63e29 100644 --- a/src/compatibility/as3cf/class-tiny-as3cf.php +++ b/src/compatibility/as3cf/class-tiny-as3cf.php @@ -52,11 +52,11 @@ public static function is_active() { } public static function remove_local_files_setting_enabled() { - if ( ! Tiny_AS3CF::is_active() ) { + if ( ! Tiny_AS3CF::is_active() ) { return false; } $settings = get_option( 'tantan_wordpress_s3' ); - if ( !is_array( $settings ) ) { + if ( ! is_array( $settings ) ) { return false; } return array_key_exists( 'remove-local-file', $settings ) && $settings['remove-local-file'];