Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/admin/class-script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
]
);

Expand Down
3 changes: 2 additions & 1 deletion src/admin/js/page/admin-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) }
Comment on lines +594 to +596
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Help text can mislead when WP auto-scaling is disabled or filtered off.

The new help text unconditionally tells users that leaving the field empty falls back to "the WordPress maximum dimension (2560px)", but that is not always true:

  • When the user turns off "WordPress Automatic Image Scaling" (line 495-501), WordPress disables its big-image threshold, and apply_filters('big_image_size_threshold', 2560) can return false (as acknowledged by the comment in src/admin/class-script-loader.php). In that case wpScalingThreshold localizes to false/0, and the converter's finalMaxDimension becomes 0 → no resize at all.
  • A site filter can also override big_image_size_threshold to a value other than 2560, making the hardcoded "2560" copy and placeholder inaccurate.

Consider either (a) making the placeholder/help text reflect the actual window.cimoSettings.wpScalingThreshold value and omit the WP fallback wording when it's falsy, or (b) clarifying that the fallback only applies when WP automatic image scaling is enabled.

✏️ Example adjustment
-								placeholder="2560"
+								placeholder={ window.cimoSettings?.wpScalingThreshold ? String( window.cimoSettings.wpScalingThreshold ) : '' }
 								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={ window.cimoSettings?.wpScalingThreshold
+									? 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 use the WordPress maximum dimension (%dpx). We recommend a value of 1920px.', 'cimo-image-optimizer' ), window.cimoSettings.wpScalingThreshold )
+									: __( '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' )
+								}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/admin/js/page/admin-settings.js` around lines 594 - 596, The
help/placeholder text around the maxImageDimension input is misleading because
it always states the WP fallback is 2560px; update the UI to read the actual
localized value and conditionally change wording: read
window.cimoSettings.wpScalingThreshold and if truthy use that value in the
placeholder/help (e.g., "Leave empty to use WordPress maximum dimension (Xpx)"),
otherwise remove the fallback wording and clearly state that leaving it empty
will disable resizing (or no WP auto-scaling) — adjust the component rendering
where maxImageDimension, handleInputChange, and the help prop are set so the
placeholder/help reflect wpScalingThreshold and the behavior of
finalMaxDimension when wpScalingThreshold is falsy.

__next40pxDefaultSize
/>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/shared/converters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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,
} )
}
}
Expand Down
Loading