From 827c9c028634785d4ada87b37a3552ea0c4377c8 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 15:07:37 +0200 Subject: [PATCH 01/23] Increase strictness of phpcs --- phpcs.xml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 9d0d00d2..b56e261b 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,8 +2,24 @@ - - + + + + + + + + + + + + + + + + + + From c1d32aba4f093fcd969d0931c01dc1e1ba70703f Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 15:08:07 +0200 Subject: [PATCH 02/23] autofixes --- src/class-tiny-apache-rewrite.php | 6 ++--- src/class-tiny-cli.php | 1 - src/class-tiny-compress-client.php | 9 ++++---- src/class-tiny-compress.php | 6 ++--- src/class-tiny-helpers.php | 24 ++++++++++---------- src/class-tiny-image.php | 6 +++-- src/class-tiny-logger.php | 1 - src/class-tiny-php.php | 6 ++--- src/class-tiny-picture.php | 6 ++--- src/class-tiny-plugin.php | 10 +++++--- src/class-tiny-settings.php | 7 +++--- src/compatibility/as3cf/class-tiny-as3cf.php | 4 ++-- src/views/account-status-connected.php | 16 ++++++------- 13 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/class-tiny-apache-rewrite.php b/src/class-tiny-apache-rewrite.php index e91f4c56..e6944d70 100644 --- a/src/class-tiny-apache-rewrite.php +++ b/src/class-tiny-apache-rewrite.php @@ -31,6 +31,7 @@ class Tiny_Apache_Rewrite extends Tiny_WP_Base { /** * seperator when rules are inserted + * * @var string */ const MARKER = 'tiny-compress-images'; @@ -40,9 +41,8 @@ class Tiny_Apache_Rewrite extends Tiny_WP_Base { * hooked into `update_option_tinypng_convert_format` * https://developer.wordpress.org/reference/hooks/update_option_option/ * - * - * @param mixed $old_value - * @param mixed $value + * @param mixed $old_value + * @param mixed $value * @param string $option * @return void */ diff --git a/src/class-tiny-cli.php b/src/class-tiny-cli.php index ba02f3af..d4f8a182 100644 --- a/src/class-tiny-cli.php +++ b/src/class-tiny-cli.php @@ -52,7 +52,6 @@ public static function register_command( $settings ) { * optimize all unprocessed images * wp tiny optimize * - * * @param array $args * @param array $assoc_args * @return void diff --git a/src/class-tiny-compress-client.php b/src/class-tiny-compress-client.php index 3acd24b8..2f3531d6 100644 --- a/src/class-tiny-compress-client.php +++ b/src/class-tiny-compress-client.php @@ -98,7 +98,7 @@ protected function validate() { } throw new Tiny_Exception( - $err->getMessage(), + esc_html( $err->getMessage() ), get_class( $err ), $err->status ); @@ -165,7 +165,7 @@ protected function compress( $input, $resize_opts, $preserve_opts, $convert_to ) ); throw new Tiny_Exception( - $err->getMessage(), + esc_html( $err->getMessage() ), get_class( $err ), $err->status ); @@ -184,7 +184,7 @@ public function create_key( $email, $options ) { $this->last_error_code = $err->status; throw new Tiny_Exception( - $err->getMessage(), + esc_html( $err->getMessage() ), get_class( $err ), $err->status ); @@ -192,7 +192,8 @@ public function create_key( $email, $options ) { } private function set_request_options( $client ) { - /* The client does not let us override cURL properties yet, so we have + /* + The client does not let us override cURL properties yet, so we have to use a reflection property. */ $property = new ReflectionProperty( $client, 'options' ); $property->setAccessible( true ); diff --git a/src/class-tiny-compress.php b/src/class-tiny-compress.php index d17f55c9..75ced00c 100644 --- a/src/class-tiny-compress.php +++ b/src/class-tiny-compress.php @@ -96,9 +96,9 @@ public function get_status() { /** * Compresses a single file * - * @param [type] $file - * @param array $resize_opts - * @param array $preserve_opts + * @param [type] $file + * @param array $resize_opts + * @param array $preserve_opts * @param array{ string } conversion options * @return void */ diff --git a/src/class-tiny-helpers.php b/src/class-tiny-helpers.php index f2140d3c..51c678c3 100644 --- a/src/class-tiny-helpers.php +++ b/src/class-tiny-helpers.php @@ -29,7 +29,7 @@ class Tiny_Helpers { * We can use mb_strlen & mb_substr as WordPress provides a compat function for * it if mbstring php module is not installed. * - * @param string $text the text + * @param string $text the text * @param integer $length the maximum length of the string * @return string the truncated string */ @@ -173,17 +173,17 @@ public static function get_wp_filesystem() { } /** - * Polyfill for `str_starts_with()` function added in PHP 8.0. - * - * Performs a case-sensitive check indicating if - * the haystack begins with needle. - * - * @since 5.9.0 - * - * @param string $haystack The string to search in. - * @param string $needle The substring to search for in the `$haystack`. - * @return bool True if `$haystack` starts with `$needle`, otherwise false. - */ + * Polyfill for `str_starts_with()` function added in PHP 8.0. + * + * Performs a case-sensitive check indicating if + * the haystack begins with needle. + * + * @since 5.9.0 + * + * @param string $haystack The string to search in. + * @param string $needle The substring to search for in the `$haystack`. + * @return bool True if `$haystack` starts with `$needle`, otherwise false. + */ public static function str_starts_with( $haystack, $needle ) { if ( function_exists( 'str_starts_with' ) ) { return str_starts_with( $haystack, $needle ); diff --git a/src/class-tiny-image.php b/src/class-tiny-image.php index a586f430..1a6576f5 100644 --- a/src/class-tiny-image.php +++ b/src/class-tiny-image.php @@ -51,7 +51,8 @@ private function parse_wp_metadata() { } if ( ! is_array( $this->wp_metadata ) || ! isset( $this->wp_metadata['file'] ) ) { - /* No file metadata found, this might be another plugin messing with + /* + No file metadata found, this might be another plugin messing with metadata. Simply ignore this! */ return; } @@ -63,7 +64,8 @@ private function parse_wp_metadata() { $path_prefix .= $path_info['dirname'] . '/'; } - /* Do not use pathinfo for getting the filename. + /* + Do not use pathinfo for getting the filename. It doesn't work when the filename starts with a special character. */ $path_parts = explode( '/', $this->wp_metadata['file'] ); $this->name = end( $path_parts ); diff --git a/src/class-tiny-logger.php b/src/class-tiny-logger.php index 311eec79..6fc8f061 100644 --- a/src/class-tiny-logger.php +++ b/src/class-tiny-logger.php @@ -22,7 +22,6 @@ /** * Handles logging of plugin events to file. * - * * @since 3.7.0 */ class Tiny_Logger { diff --git a/src/class-tiny-php.php b/src/class-tiny-php.php index 91071da0..bbeb5818 100644 --- a/src/class-tiny-php.php +++ b/src/class-tiny-php.php @@ -37,8 +37,8 @@ public static function curl_exec_disabled() { } public static function client_supported() { - return Tiny_PHP::has_fully_supported_php() && - Tiny_PHP::curl_available() && - ! Tiny_PHP::curl_exec_disabled(); + return self::has_fully_supported_php() && + self::curl_available() && + ! self::curl_exec_disabled(); } } diff --git a/src/class-tiny-picture.php b/src/class-tiny-picture.php index ab318131..ae3f5e41 100644 --- a/src/class-tiny-picture.php +++ b/src/class-tiny-picture.php @@ -109,7 +109,7 @@ private function replace_picture_sources( $content ) { private function replace_img_sources( $content ) { $image_sources = $this->filter_images( $content ); foreach ( $image_sources as $image_source ) { - $content = Tiny_Picture::replace_image( $content, $image_source ); + $content = self::replace_image( $content, $image_source ); } return $content; } @@ -145,7 +145,7 @@ private function filter_pictures( $content ) { /** * Will add additional sourcesets to picture elements. * - * @param string $content the full page content + * @param string $content the full page content * @param Tiny_Source_Picture $source the picture element * * @return string the updated content including augmented picture elements @@ -159,7 +159,7 @@ private function replace_picture( $content, $source ) { /** * Will replace img elements with picture elements that (possibly) have additional formats. * - * @param string $content the full page content + * @param string $content the full page content * @param Tiny_Source_Image $source the picture element * * @return string the updated content including augmented picture elements diff --git a/src/class-tiny-plugin.php b/src/class-tiny-plugin.php index 820da686..91420d19 100644 --- a/src/class-tiny-plugin.php +++ b/src/class-tiny-plugin.php @@ -32,7 +32,8 @@ public static function jpeg_quality() { } public static function version() { - /* Avoid using get_plugin_data() because it is not loaded early enough + /* + Avoid using get_plugin_data() because it is not loaded early enough in xmlrpc.php. */ return self::VERSION; } @@ -111,7 +112,8 @@ public function ajax_init() { $this->get_method( 'mark_image_as_compressed' ) ); - /* When touching any functionality linked to image compressions when + /* + When touching any functionality linked to image compressions when uploading images make sure it also works with XML-RPC. See README. */ add_filter( 'wp_ajax_nopriv_tiny_rpc', @@ -788,7 +790,8 @@ public function add_dashboard_widget() { true ); - /* This might be deduplicated with the admin script localization, but + /* + This might be deduplicated with the admin script localization, but the order of including scripts is sometimes different. So in that case we need to make sure that the order of inclusion is correc.t */ wp_localize_script( @@ -850,6 +853,7 @@ public function friendly_user_name() { * Will clean up converted files (if any) when the original is deleted * * Hooked to the `delete_attachment` action. + * * @see https://developer.wordpress.org/reference/hooks/deleted_post/ * * @param [int] $post_id diff --git a/src/class-tiny-settings.php b/src/class-tiny-settings.php index d19e8765..294b26e9 100644 --- a/src/class-tiny-settings.php +++ b/src/class-tiny-settings.php @@ -221,7 +221,8 @@ protected function clear_api_key_pending() { } protected static function get_intermediate_size( $size ) { - /* Inspired by + /* + Inspired by http://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes */ global $_wp_additional_image_sizes; @@ -789,14 +790,12 @@ public function render_account_status() { if ( $this->get_api_key_pending() ) { $this->clear_api_key_pending(); } - } else { - if ( $this->get_api_key_pending() ) { + } elseif ( $this->get_api_key_pending() ) { $status->ok = true; $status->pending = true; $status->message = ( 'An email has been sent to activate your account' ); - } } include __DIR__ . '/views/account-status-connected.php'; } diff --git a/src/compatibility/as3cf/class-tiny-as3cf.php b/src/compatibility/as3cf/class-tiny-as3cf.php index 314f65e3..79d5e141 100644 --- a/src/compatibility/as3cf/class-tiny-as3cf.php +++ b/src/compatibility/as3cf/class-tiny-as3cf.php @@ -44,11 +44,11 @@ public function __construct( $settings ) { * Will verify if either the Lite or Pro version of AS3CF is active. */ public static function is_active() { - return Tiny_AS3CF::pro_is_active() || Tiny_AS3CF::lite_is_active(); + return self::pro_is_active() || self::lite_is_active(); } public static function remove_local_files_setting_enabled() { - if ( ! Tiny_AS3CF::is_active() ) { + if ( ! self::is_active() ) { return false; } $settings = get_option( 'tantan_wordpress_s3' ); diff --git a/src/views/account-status-connected.php b/src/views/account-status-connected.php index 4f8b1bff..ac2910db 100644 --- a/src/views/account-status-connected.php +++ b/src/views/account-status-connected.php @@ -51,23 +51,21 @@ $compressions ); } - } else { - if ( isset( $status->message ) ) { + } elseif ( isset( $status->message ) ) { echo esc_html__( 'Error', 'tiny-compress-images' ) . ': '; echo esc_html( $status->message, 'tiny-compress-images' ); - } else { - esc_html_e( - 'API status could not be checked, enable cURL for more information', - 'tiny-compress-images' - ); - } + } else { + esc_html_e( + 'API status could not be checked, enable cURL for more information', + 'tiny-compress-images' + ); } // End if(). ?>

Date: Fri, 15 May 2026 15:08:14 +0200 Subject: [PATCH 03/23] remove unused --- src/compatibility/as3cf/class-tiny-as3cf.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compatibility/as3cf/class-tiny-as3cf.php b/src/compatibility/as3cf/class-tiny-as3cf.php index 79d5e141..ca5af84a 100644 --- a/src/compatibility/as3cf/class-tiny-as3cf.php +++ b/src/compatibility/as3cf/class-tiny-as3cf.php @@ -62,7 +62,7 @@ public static function remove_local_files_setting_enabled() { * Registers hooks required for the AS3CF integration. */ public function add_hooks() { - add_action( 'as3cf_pre_upload_object', array( $this, 'as3cf_before_offload' ), 10, 2 ); + add_action( 'as3cf_pre_upload_object', array( $this, 'as3cf_before_offload' ), 10, 1 ); } /** @@ -72,10 +72,9 @@ public function add_hooks() { * * Will handle file before file is possibly offloaded * - * @param Item $as3cf_item - * @param array $args + * @param mixed $as3cf_item */ - public function as3cf_before_offload( $as3cf_item, $args ) { + public function as3cf_before_offload( $as3cf_item ) { if ( ! $this->tiny_settings->auto_compress_enabled() ) { return; } From 3cfdfc60af0c0a200cc0300d88a18e95a59795bb Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 15:16:17 +0200 Subject: [PATCH 04/23] remove unused --- src/class-tiny-logger.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class-tiny-logger.php b/src/class-tiny-logger.php index 6fc8f061..4345c526 100644 --- a/src/class-tiny-logger.php +++ b/src/class-tiny-logger.php @@ -72,7 +72,7 @@ public static function init() { 'pre_update_option_tinypng_logging_enabled', 'Tiny_Logger::on_save_log_enabled', 10, - 3 + 2 ); } @@ -113,7 +113,7 @@ public function get_log_file_path() { * * @return bool true if enabled */ - public static function on_save_log_enabled( $log_enabled, $old, $option ) { + public static function on_save_log_enabled( $log_enabled, $old ) { $instance = self::get_instance(); $was_enabled = 'on' === $old; $is_now_enabled = 'on' === $log_enabled; From b603f27c72fd62ba238a452ff62d36f5e4e2811f Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 15:17:51 +0200 Subject: [PATCH 05/23] non-translatable string --- src/views/compress-details.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/compress-details.php b/src/views/compress-details.php index b0e30f43..1c1c1a7d 100644 --- a/src/views/compress-details.php +++ b/src/views/compress-details.php @@ -105,7 +105,7 @@ - +
From d165ad5d78328ca8bf88852e0c0f9d0fe93ee3c4 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 15:19:39 +0200 Subject: [PATCH 06/23] non translatable strings --- src/views/account-status-connected.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/account-status-connected.php b/src/views/account-status-connected.php index ac2910db..085b1dca 100644 --- a/src/views/account-status-connected.php +++ b/src/views/account-status-connected.php @@ -4,7 +4,7 @@ ok ) { if ( isset( $status->message ) ) { - echo esc_html( $status->message, 'tiny-compress-images' ); + echo esc_html( $status->message ); } else { esc_html_e( 'Your account is connected', 'tiny-compress-images' ); } @@ -53,7 +53,7 @@ } } elseif ( isset( $status->message ) ) { echo esc_html__( 'Error', 'tiny-compress-images' ) . ': '; - echo esc_html( $status->message, 'tiny-compress-images' ); + echo esc_html( $status->message ); } else { esc_html_e( 'API status could not be checked, enable cURL for more information', From 35720e52f21d0eb27d084db0f7a65de030071227 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 21:56:12 +0200 Subject: [PATCH 07/23] use count instead of sizeof --- src/views/bulk-optimization.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/views/bulk-optimization.php b/src/views/bulk-optimization.php index 109afe38..a4ddd8e5 100644 --- a/src/views/bulk-optimization.php +++ b/src/views/bulk-optimization.php @@ -50,7 +50,7 @@ esc_html_e( 'This page is designed to bulk optimize all your images.', 'tiny-compress-images' ); echo ' '; esc_html_e( 'You do not seem to have uploaded any JPEG, PNG or WebP images yet.', 'tiny-compress-images' ); - } elseif ( 0 == sizeof( $active_tinify_sizes ) ) { + } elseif ( 0 == count( $active_tinify_sizes ) ) { esc_html_e( 'Based on your current settings, nothing will be optimized. There are no active sizes selected for optimization.', 'tiny-compress-images' ); } elseif ( 0 == $stats['available-unoptimized-sizes'] ) { /* translators: %s: friendly user name */ @@ -115,7 +115,7 @@

- 0 && sizeof( $active_tinify_sizes ) > 0 && $stats['available-unoptimized-sizes'] > 0 ) { ?> + 0 && count( $active_tinify_sizes ) > 0 && $stats['available-unoptimized-sizes'] > 0 ) { ?>

'; - for ( $i = 0; $i < sizeof( $active_tinify_sizes ); ++$i ) { + for ( $i = 0; $i < count( $active_tinify_sizes ); ++$i ) { $name = $active_tinify_sizes[ $i ]; if ( '0' == $name ) { echo '

  • - ' . esc_html__( 'Original image', 'tiny-compress-images' ) . '
  • '; @@ -150,7 +150,7 @@ ?>

    - 0 ) { ?> + 0 ) { ?> Date: Fri, 15 May 2026 21:58:28 +0200 Subject: [PATCH 08/23] unnecessary string concat --- src/views/compress-details.php | 2 +- src/views/optimization-chart.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/compress-details.php b/src/views/compress-details.php index 1c1c1a7d..d288e746 100644 --- a/src/views/compress-details.php +++ b/src/views/compress-details.php @@ -166,7 +166,7 @@ echo ''; echo ''; echo ( Tiny_Image::is_original( $size_name ) ? esc_html__( 'Original', 'tiny-compress-images' ) : esc_html( ucfirst( rtrim( $size_name, '_wr2x' ) ) ) ); - echo '' . ' '; + echo ''; if ( ! array_key_exists( $size_name, $active_sizes ) && ! Tiny_Image::is_retina( $size_name ) ) { echo '' . esc_html__( '(not in use)', 'tiny-compress-images' ) . ''; } elseif ( $size->missing() && ( Tiny_Settings::wr2x_active() || ! Tiny_Image::is_retina( $size_name ) ) ) { diff --git a/src/views/optimization-chart.php b/src/views/optimization-chart.php index 28e3dca3..4013b5f3 100644 --- a/src/views/optimization-chart.php +++ b/src/views/optimization-chart.php @@ -33,7 +33,7 @@ @keyframes shwoosh { from { - stroke-dasharray: + stroke-dasharray: } to { stroke-dasharray: From a94b69f2805e66c3c4ff0727a6dd8bada4aa6404 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 21:59:35 +0200 Subject: [PATCH 09/23] use count instead of sizeof --- src/class-tiny-bulk-optimization.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class-tiny-bulk-optimization.php b/src/class-tiny-bulk-optimization.php index 52542ccb..a5d7fd15 100644 --- a/src/class-tiny-bulk-optimization.php +++ b/src/class-tiny-bulk-optimization.php @@ -42,7 +42,7 @@ public static function get_optimization_statistics( $settings, $result = null ) if ( isset( $last_image['ID'] ) ) { $last_image_id = $last_image['ID']; } - } while ( sizeof( $result ) == self::PAGING_SIZE ); + } while ( count( $result ) == self::PAGING_SIZE ); } else { $stats = self::populate_optimization_statistics( $settings, $result, $stats ); } @@ -104,7 +104,7 @@ private static function populate_optimization_statistics( $settings, $result, $s $active_tinify_sizes = $settings->get_active_tinify_sizes(); $conversion_enabled = $settings->get_conversion_enabled(); - for ( $i = 0; $i < sizeof( $result ); $i++ ) { + for ( $i = 0; $i < count( $result ); $i++ ) { $wp_metadata = unserialize( (string) $result[ $i ]['meta_value'] ); $tiny_metadata = isset( $result[ $i ]['tiny_meta_value'] ) ? unserialize( (string) $result[ $i ]['tiny_meta_value'] ) : From 45b316f045e424a4dcc93c69d3e5ee27661fd8ad Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 22:09:38 +0200 Subject: [PATCH 10/23] error_log --- src/class-tiny-image.php | 2 +- src/class-tiny-logger.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/class-tiny-image.php b/src/class-tiny-image.php index 1a6576f5..8c7ceaf1 100644 --- a/src/class-tiny-image.php +++ b/src/class-tiny-image.php @@ -473,7 +473,7 @@ public function get_savings( $stats ) { public function get_statistics( $active_sizes, $active_tinify_sizes ) { if ( $this->statistics ) { - error_log( 'Strangely the image statistics are asked for again.' ); + Tiny_Logger::error( 'Strangely the image statistics are asked for again.' ); return $this->statistics; } diff --git a/src/class-tiny-logger.php b/src/class-tiny-logger.php index 4345c526..b50da5be 100644 --- a/src/class-tiny-logger.php +++ b/src/class-tiny-logger.php @@ -189,6 +189,7 @@ private function log( $level, $message, $context = array() ) { $context_str = ! empty( $context ) ? ' ' . wp_json_encode( $context ) : ''; $log_entry = "[{$timestamp}] [{$level_str}] {$message}{$context_str}" . PHP_EOL; + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( $log_entry, 3, $this->log_file_path ); } From a38d4e9cc1039397caa9bd558b33e552306ceb22 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 22:13:45 +0200 Subject: [PATCH 11/23] count and unnessary translation --- src/class-tiny-settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/class-tiny-settings.php b/src/class-tiny-settings.php index 294b26e9..8e1a253f 100644 --- a/src/class-tiny-settings.php +++ b/src/class-tiny-settings.php @@ -98,7 +98,7 @@ public function admin_init() { } catch ( Tiny_Exception $e ) { $this->notices->show( 'compressor_exception', - esc_html( $e->getMessage(), 'tiny-compress-images' ), + esc_html( $e->getMessage() ), 'error', false ); @@ -379,7 +379,7 @@ public function get_resize_options( $size_name ) { if ( $height > 0 ) { $options['height'] = $height; } - return sizeof( $options ) >= 2 ? $options : false; + return count( $options ) >= 2 ? $options : false; } /** @@ -687,8 +687,8 @@ public function render_compression_timing_radiobutton( } $id = sprintf( self::get_prefixed_name( 'compression_timing_%s' ), $value ); - $label = esc_html( $label, 'tiny-compress-images' ); - $desc = esc_html( $desc, 'tiny-compress-images' ); + $label = esc_html( $label ); + $desc = esc_html( $desc ); echo ''; echo ''; From 8cdef0a01306be29158f7c163ace6bda6975c417 Mon Sep 17 00:00:00 2001 From: tijmen Date: Fri, 15 May 2026 22:22:07 +0200 Subject: [PATCH 12/23] Log errors if inits fail --- src/class-tiny-settings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/class-tiny-settings.php b/src/class-tiny-settings.php index 8e1a253f..281a2a00 100644 --- a/src/class-tiny-settings.php +++ b/src/class-tiny-settings.php @@ -48,6 +48,7 @@ public function xmlrpc_init() { try { $this->init_compressor(); } catch ( Tiny_Exception $e ) { + Tiny_Logger::error( $e->getMessage() ); } } @@ -55,6 +56,7 @@ public function cli_init() { try { $this->init_compressor(); } catch ( Tiny_Exception $e ) { + Tiny_Logger::error( $e->getMessage() ); } } @@ -62,6 +64,7 @@ public function ajax_init() { try { $this->init_compressor(); } catch ( Tiny_Exception $e ) { + Tiny_Logger::error( $e->getMessage() ); } add_action( @@ -89,6 +92,7 @@ public function rest_init() { try { $this->init_compressor(); } catch ( Tiny_Exception $e ) { + Tiny_Logger::error( $e->getMessage() ); } } From 941560bb111c27d14578055072fa306911542cf2 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:13:06 +0200 Subject: [PATCH 13/23] remove prefix underscores --- src/class-tiny-image-size.php | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/class-tiny-image-size.php b/src/class-tiny-image-size.php index e174cf95..5186ef99 100644 --- a/src/class-tiny-image-size.php +++ b/src/class-tiny-image-size.php @@ -23,11 +23,11 @@ class Tiny_Image_Size { public $meta = array(); /* Used more than once and not trivial, so we are memoizing these */ - private $_exists; - private $_file_size; - private $_mime_type; - private $_duplicate = false; - private $_duplicate_of_size = ''; + private $exists; + private $file_size; + private $mime_type; + private $duplicate = false; + private $duplicate_of_size = ''; public function __construct( $filename = null ) { $this->filename = $filename; @@ -119,33 +119,33 @@ public function never_compressed() { } public function filesize() { - if ( is_null( $this->_file_size ) ) { + if ( is_null( $this->file_size ) ) { if ( $this->exists() ) { - $this->_file_size = filesize( $this->filename ); + $this->file_size = filesize( $this->filename ); } else { - $this->_file_size = 0; + $this->file_size = 0; } } - return $this->_file_size; + return $this->file_size; } public function mimetype() { - if ( is_null( $this->_mime_type ) ) { + if ( is_null( $this->mime_type ) ) { if ( $this->exists() ) { $file = file_get_contents( $this->filename ); - $this->_mime_type = Tiny_Helpers::get_mimetype( $file ); + $this->mime_type = Tiny_Helpers::get_mimetype( $file ); } else { - $this->_mime_type = 'application/octet-stream'; + $this->mime_type = 'application/octet-stream'; } } - return $this->_mime_type; + return $this->mime_type; } public function exists() { - if ( is_null( $this->_exists ) ) { - $this->_exists = $this->filename && file_exists( $this->filename ); + if ( is_null( $this->exists ) ) { + $this->exists = $this->filename && file_exists( $this->filename ); } - return $this->_exists; + return $this->exists; } private function same_size() { @@ -211,7 +211,7 @@ public function modified() { public function uncompressed() { return $this->exists() && - ! $this->is_duplicate() && + ! $this->isduplicate() && ! ( isset( $this->meta['output'] ) && $this->same_size() ); } @@ -227,17 +227,17 @@ public function resized() { ); } - public function mark_duplicate( $duplicate_size_name ) { - $this->_duplicate = true; - $this->_duplicate_of_size = $duplicate_size_name; + public function markduplicate( $duplicate_size_name ) { + $this->duplicate = true; + $this->duplicate_of_size = $duplicate_size_name; } - public function is_duplicate() { - return $this->_duplicate; + public function isduplicate() { + return $this->duplicate; } public function duplicate_of_size() { - return $this->_duplicate_of_size; + return $this->duplicate_of_size; } /** From 2561c4988787ca6ca85f9267b1c3215f0119e8fd Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:20:39 +0200 Subject: [PATCH 14/23] move count outside loops --- src/class-tiny-bulk-optimization.php | 6 ++++-- src/class-tiny-image-size.php | 2 +- src/views/bulk-optimization.php | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/class-tiny-bulk-optimization.php b/src/class-tiny-bulk-optimization.php index a5d7fd15..7dbb9a90 100644 --- a/src/class-tiny-bulk-optimization.php +++ b/src/class-tiny-bulk-optimization.php @@ -42,7 +42,8 @@ public static function get_optimization_statistics( $settings, $result = null ) if ( isset( $last_image['ID'] ) ) { $last_image_id = $last_image['ID']; } - } while ( count( $result ) == self::PAGING_SIZE ); + $result_count = count( $result ); + } while ( self::PAGING_SIZE == $result_count ); } else { $stats = self::populate_optimization_statistics( $settings, $result, $stats ); } @@ -104,7 +105,8 @@ private static function populate_optimization_statistics( $settings, $result, $s $active_tinify_sizes = $settings->get_active_tinify_sizes(); $conversion_enabled = $settings->get_conversion_enabled(); - for ( $i = 0; $i < count( $result ); $i++ ) { + $result_count = count( $result ); + for ( $i = 0; $i < $result_count; $i++ ) { $wp_metadata = unserialize( (string) $result[ $i ]['meta_value'] ); $tiny_metadata = isset( $result[ $i ]['tiny_meta_value'] ) ? unserialize( (string) $result[ $i ]['tiny_meta_value'] ) : diff --git a/src/class-tiny-image-size.php b/src/class-tiny-image-size.php index 5186ef99..99fca492 100644 --- a/src/class-tiny-image-size.php +++ b/src/class-tiny-image-size.php @@ -132,7 +132,7 @@ public function filesize() { public function mimetype() { if ( is_null( $this->mime_type ) ) { if ( $this->exists() ) { - $file = file_get_contents( $this->filename ); + $file = file_get_contents( $this->filename ); $this->mime_type = Tiny_Helpers::get_mimetype( $file ); } else { $this->mime_type = 'application/octet-stream'; diff --git a/src/views/bulk-optimization.php b/src/views/bulk-optimization.php index a4ddd8e5..b0aaebb2 100644 --- a/src/views/bulk-optimization.php +++ b/src/views/bulk-optimization.php @@ -137,7 +137,8 @@ } else { esc_html_e( 'These sizes are currently activated for optimization:', 'tiny-compress-images' ); echo '

      '; - for ( $i = 0; $i < count( $active_tinify_sizes ); ++$i ) { + $active_tinify_sizes_count = count( $active_tinify_sizes ); + for ( $i = 0; $i < $active_tinify_sizes_count; ++$i ) { $name = $active_tinify_sizes[ $i ]; if ( '0' == $name ) { echo '
    • - ' . esc_html__( 'Original image', 'tiny-compress-images' ) . '
    • '; From 136ddd8be9486799d2639a66ab1af8e14ff79fb3 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:25:34 +0200 Subject: [PATCH 15/23] use wp_safe_redirect --- src/class-tiny-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-tiny-plugin.php b/src/class-tiny-plugin.php index 91420d19..f6f4a52a 100644 --- a/src/class-tiny-plugin.php +++ b/src/class-tiny-plugin.php @@ -699,7 +699,7 @@ public function media_library_bulk_action() { $location = add_query_arg( 'm', $_REQUEST['m'], $location ); } - wp_redirect( admin_url( $location ) ); + wp_safe_redirect( admin_url( $location ) ); exit(); } From a8edd2f236d378833d353301868f7c507fd3bdd5 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:25:46 +0200 Subject: [PATCH 16/23] use maybe_unserialize --- src/class-tiny-bulk-optimization.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class-tiny-bulk-optimization.php b/src/class-tiny-bulk-optimization.php index 7dbb9a90..904adc5b 100644 --- a/src/class-tiny-bulk-optimization.php +++ b/src/class-tiny-bulk-optimization.php @@ -107,9 +107,9 @@ private static function populate_optimization_statistics( $settings, $result, $s $result_count = count( $result ); for ( $i = 0; $i < $result_count; $i++ ) { - $wp_metadata = unserialize( (string) $result[ $i ]['meta_value'] ); + $wp_metadata = maybe_unserialize( (string) $result[ $i ]['meta_value'] ); $tiny_metadata = isset( $result[ $i ]['tiny_meta_value'] ) ? - unserialize( (string) $result[ $i ]['tiny_meta_value'] ) : + maybe_unserialize( (string) $result[ $i ]['tiny_meta_value'] ) : array(); if ( ! is_array( $tiny_metadata ) ) { $tiny_metadata = array(); From ffc17cc9232af5cc31b5179946754ffbbf3f9a69 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:26:16 +0200 Subject: [PATCH 17/23] ignore phpcs warning --- src/class-tiny-compress-fopen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-tiny-compress-fopen.php b/src/class-tiny-compress-fopen.php index 9177d374..b63d0794 100644 --- a/src/class-tiny-compress-fopen.php +++ b/src/class-tiny-compress-fopen.php @@ -266,7 +266,7 @@ private function request_options( $method, $body = null, $headers = array() ) { 'header' => array_merge( $headers, array( - 'Authorization: Basic ' . base64_encode( 'api:' . $this->api_key ), + 'Authorization: Basic ' . base64_encode( 'api:' . $this->api_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Base64 encoding is required. 'User-Agent: ' . self::identifier(), 'Content-Type: multipart/form-data', ) From f62dc07bc10269e37709694977e89c1f87fccf0e Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:35:14 +0200 Subject: [PATCH 18/23] accidental rename of method --- src/class-tiny-image-size.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class-tiny-image-size.php b/src/class-tiny-image-size.php index 99fca492..f57694a6 100644 --- a/src/class-tiny-image-size.php +++ b/src/class-tiny-image-size.php @@ -211,7 +211,7 @@ public function modified() { public function uncompressed() { return $this->exists() && - ! $this->isduplicate() && + ! $this->is_duplicate() && ! ( isset( $this->meta['output'] ) && $this->same_size() ); } @@ -227,12 +227,12 @@ public function resized() { ); } - public function markduplicate( $duplicate_size_name ) { + public function mark_duplicate( $duplicate_size_name ) { $this->duplicate = true; $this->duplicate_of_size = $duplicate_size_name; } - public function isduplicate() { + public function is_duplicate() { return $this->duplicate; } From 26ab77ca1e94d381ee6f2900dbe0c4553682e6d3 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 14:36:37 +0200 Subject: [PATCH 19/23] add mock func --- test/helpers/wordpress.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/helpers/wordpress.php b/test/helpers/wordpress.php index 45e2406d..1ec1397e 100644 --- a/test/helpers/wordpress.php +++ b/test/helpers/wordpress.php @@ -106,6 +106,7 @@ public function __construct($vfs) $this->addMethod('insert_with_markers'); $this->addMethod('esc_html_e'); $this->addMethod('esc_html'); + $this->addMethod('maybe_unserialize'); $this->defaults(); $this->create_filesystem(); } @@ -582,6 +583,15 @@ public function insert_with_markers($filename, $marker, $insertion) return file_put_contents($filename, trim($content) . "\n") !== false; } + + /** + * Mocked function for https://developer.wordpress.org/reference/functions/maybe_unserialize/ + * + * @return mixed + */ + public function maybe_unserialize($value) { + return unserialize($value); + } } class WP_HTTP_Proxy From 718d7b898b2e459f50f04687e8c5157737ea85ea Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 15:27:06 +0200 Subject: [PATCH 20/23] fix spacing in resize text --- src/views/compress-details.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/compress-details.php b/src/views/compress-details.php index d288e746..6fdfa76c 100644 --- a/src/views/compress-details.php +++ b/src/views/compress-details.php @@ -177,7 +177,7 @@ echo '' . esc_html__( '(WP Retina 2x)', 'tiny-compress-images' ) . ''; } elseif ( $size->resized() ) { /* translators: %1$dx%2$d: resized image width x height */ - printf( '' . esc_html__( '(resized to %1$dx%2$d)', 'tiny-compress-images' ) . '', $size->meta['output']['width'], $size->meta['output']['height'] ); + printf( '' . esc_html__( ' (resized to %1$dx%2$d)', 'tiny-compress-images' ) . '', $size->meta['output']['width'], $size->meta['output']['height'] ); } echo ''; From c98e8861b92c313d40476f078f67711905d2d782 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 16:29:53 +0200 Subject: [PATCH 21/23] move whitespace --- src/views/compress-details.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/compress-details.php b/src/views/compress-details.php index 6fdfa76c..cdfe2efb 100644 --- a/src/views/compress-details.php +++ b/src/views/compress-details.php @@ -165,7 +165,7 @@ '; echo ''; - echo ( Tiny_Image::is_original( $size_name ) ? esc_html__( 'Original', 'tiny-compress-images' ) : esc_html( ucfirst( rtrim( $size_name, '_wr2x' ) ) ) ); + echo ( Tiny_Image::is_original( $size_name ) ? esc_html__( 'Original ', 'tiny-compress-images' ) : esc_html( ucfirst( rtrim( $size_name, '_wr2x' ) ) ) ); echo ''; if ( ! array_key_exists( $size_name, $active_sizes ) && ! Tiny_Image::is_retina( $size_name ) ) { echo '' . esc_html__( '(not in use)', 'tiny-compress-images' ) . ''; @@ -177,7 +177,7 @@ echo '' . esc_html__( '(WP Retina 2x)', 'tiny-compress-images' ) . ''; } elseif ( $size->resized() ) { /* translators: %1$dx%2$d: resized image width x height */ - printf( '' . esc_html__( ' (resized to %1$dx%2$d)', 'tiny-compress-images' ) . '', $size->meta['output']['width'], $size->meta['output']['height'] ); + printf( '' . esc_html__( '(resized to %1$dx%2$d)', 'tiny-compress-images' ) . '', $size->meta['output']['width'], $size->meta['output']['height'] ); } echo ''; From bbad456d926c246218a7ec4b2984e96c0797bb21 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 16:31:00 +0200 Subject: [PATCH 22/23] Move whitespace --- src/views/compress-details.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/compress-details.php b/src/views/compress-details.php index cdfe2efb..7693f25e 100644 --- a/src/views/compress-details.php +++ b/src/views/compress-details.php @@ -165,8 +165,8 @@ '; echo ''; - echo ( Tiny_Image::is_original( $size_name ) ? esc_html__( 'Original ', 'tiny-compress-images' ) : esc_html( ucfirst( rtrim( $size_name, '_wr2x' ) ) ) ); - echo ''; + echo ( Tiny_Image::is_original( $size_name ) ? esc_html__( 'Original', 'tiny-compress-images' ) : esc_html( ucfirst( rtrim( $size_name, '_wr2x' ) ) ) ); + echo ' '; if ( ! array_key_exists( $size_name, $active_sizes ) && ! Tiny_Image::is_retina( $size_name ) ) { echo '' . esc_html__( '(not in use)', 'tiny-compress-images' ) . ''; } elseif ( $size->missing() && ( Tiny_Settings::wr2x_active() || ! Tiny_Image::is_retina( $size_name ) ) ) { From 24a3eb6b3f7020d7cf5c2768639bcdeeaef9ef99 Mon Sep 17 00:00:00 2001 From: tijmen Date: Mon, 18 May 2026 16:34:22 +0200 Subject: [PATCH 23/23] Do not escale error messages before being outputted to html --- src/class-tiny-compress-client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class-tiny-compress-client.php b/src/class-tiny-compress-client.php index 2f3531d6..8c983ce6 100644 --- a/src/class-tiny-compress-client.php +++ b/src/class-tiny-compress-client.php @@ -98,7 +98,7 @@ protected function validate() { } throw new Tiny_Exception( - esc_html( $err->getMessage() ), + $err->getMessage(), get_class( $err ), $err->status ); @@ -165,7 +165,7 @@ protected function compress( $input, $resize_opts, $preserve_opts, $convert_to ) ); throw new Tiny_Exception( - esc_html( $err->getMessage() ), + $err->getMessage(), get_class( $err ), $err->status ); @@ -184,7 +184,7 @@ public function create_key( $email, $options ) { $this->last_error_code = $err->status; throw new Tiny_Exception( - esc_html( $err->getMessage() ), + $err->getMessage(), get_class( $err ), $err->status );