From 4b1f2ffa257ecf218abb2a5b8e89e1b0c44b1eb6 Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Tue, 14 Apr 2026 10:40:35 +0800 Subject: [PATCH 1/4] fix: get lesser between wp threshold and user max dimension --- src/admin/class-script-loader.php | 5 +++++ src/shared/converters/index.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/admin/class-script-loader.php b/src/admin/class-script-loader.php index 8b67131..d04ef04 100644 --- a/src/admin/class-script-loader.php +++ b/src/admin/class-script-loader.php @@ -77,6 +77,10 @@ public static function enqueue_cimo_assets() { // Get current settings $settings = get_option( 'cimo_options', [] ); + // Expose threshold for WP Core's big image scaling. + // Can be false when auto scaling is disabled. + $threshold = apply_filters( 'big_image_size_threshold', 2560 ); + // Localize script with REST API URL, nonce, and settings wp_localize_script( 'cimo-script', @@ -100,6 +104,7 @@ public static function enqueue_cimo_assets() { 'svgUpload' => isset( $settings['svg_upload'] ) ? (int) $settings['svg_upload'] : 0, 'svgOptimizationEnabled' => isset( $settings['svg_optimization_enabled'] ) ? (int) $settings['svg_optimization_enabled'] : 1, 'stealthModeEnabled' => isset( $settings['stealth_mode_enabled'] ) ? (int) $settings['stealth_mode_enabled'] : 0, + 'wpScalingThreshold' => $threshold, ] ); diff --git a/src/shared/converters/index.js b/src/shared/converters/index.js index 7a58c50..b3769e3 100644 --- a/src/shared/converters/index.js +++ b/src/shared/converters/index.js @@ -38,6 +38,16 @@ export const getFileConverter = _file => { } if ( file.type.startsWith( 'image/' ) ) { + const max = parseFloat( window.cimoSettings?.maxImageDimension || 0 ) + const wp = parseFloat( window.cimoSettings?.wpScalingThreshold || 0 ) + + // Determine the final max dimension to use for conversion, + // prioritizing the lower of the two thresholds if both are set. + // 0 means no max dimension. + const finalMaxDimension = max && wp + ? Math.min( max, wp ) + : max || wp || 0 + // If the browser doesn't support webp, then we can't convert it. if ( ! isFormatSupported( 'webp' ) ) { return new NullConverter( file ) @@ -46,7 +56,7 @@ export const getFileConverter = _file => { return new ImageConverter( file, { format: 'webp', quality: window.cimoSettings?.webpQuality || 0.8, - maxDimension: window.cimoSettings?.maxImageDimension || 0, + maxDimension: finalMaxDimension, } ) } } From 51f17f2b111f299ab239c641fe26a8df95344b0e Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Fri, 17 Apr 2026 10:34:40 +0800 Subject: [PATCH 2/4] fix: change of placeholder and description for image max dimension --- src/admin/js/page/admin-settings.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/admin/js/page/admin-settings.js b/src/admin/js/page/admin-settings.js index 270f000..636df5e 100644 --- a/src/admin/js/page/admin-settings.js +++ b/src/admin/js/page/admin-settings.js @@ -591,8 +591,9 @@ const AdminSettings = () => { label={ __( 'Maximum Image Dimension', 'cimo-image-optimizer' ) } type="number" value={ settings.maxImageDimension } + placeholder="2560" onChange={ value => handleInputChange( 'maxImageDimension', value ) } - help={ __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to disable resizing. We recommend a value of 1920px.', 'cimo-image-optimizer' ) } + help={ __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to use the WordPress maximum dimension (2560px). We recommend a value of 1920px.', 'cimo-image-optimizer' ) } __next40pxDefaultSize /> From 7c64227471ccef6c782872f1f459c22e791222d6 Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Mon, 20 Apr 2026 10:41:38 +0800 Subject: [PATCH 3/4] fix: dynamic help based on wp scaling threshold --- src/admin/js/page/admin-settings.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/admin/js/page/admin-settings.js b/src/admin/js/page/admin-settings.js index 636df5e..9f5d675 100644 --- a/src/admin/js/page/admin-settings.js +++ b/src/admin/js/page/admin-settings.js @@ -593,7 +593,13 @@ const AdminSettings = () => { value={ settings.maxImageDimension } placeholder="2560" onChange={ value => handleInputChange( 'maxImageDimension', value ) } - help={ __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to use the WordPress maximum dimension (2560px). We recommend a value of 1920px.', 'cimo-image-optimizer' ) } + help={ sprintf( + __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to %s. We recommend a value of 1920px.', 'cimo-image-optimizer' ), + window.cimoSettings?.wpScalingThreshold + ? sprintf( __( "use WordPress's default auto-scaling at %spx", 'cimo-image-optimizer' ), window.cimoSettings.wpScalingThreshold ) + : __( 'disable auto-scaling', 'cimo-image-optimizer' ) + ) } + __next40pxDefaultSize /> From b99dff775dcf28427a996d7d3c5fc61d69e32a0c Mon Sep 17 00:00:00 2001 From: bfintal Date: Mon, 20 Apr 2026 21:42:21 +0800 Subject: [PATCH 4/4] sometimes do not show 2650 placeholder --- src/admin/class-admin.php | 1 + src/admin/js/page/admin-settings.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/admin/class-admin.php b/src/admin/class-admin.php index eb584e0..e46e357 100644 --- a/src/admin/class-admin.php +++ b/src/admin/class-admin.php @@ -118,6 +118,7 @@ public function register_settings() { 'show_in_rest' => [ 'schema' => [ 'type' => 'object', + 'additionalProperties' => true, // If we upgrade or downgrade, the settings can possibly show as null. Prevent this. 'properties' => [ // General settings 'optimize_all_media' => [ diff --git a/src/admin/js/page/admin-settings.js b/src/admin/js/page/admin-settings.js index 9f5d675..5ab23b2 100644 --- a/src/admin/js/page/admin-settings.js +++ b/src/admin/js/page/admin-settings.js @@ -591,7 +591,7 @@ const AdminSettings = () => { label={ __( 'Maximum Image Dimension', 'cimo-image-optimizer' ) } type="number" value={ settings.maxImageDimension } - placeholder="2560" + placeholder={ settings.disableWpScaling === 1 ? '2560' : undefined } onChange={ value => handleInputChange( 'maxImageDimension', value ) } help={ sprintf( __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to %s. We recommend a value of 1920px.', 'cimo-image-optimizer' ),