Skip to content

fix: get lesser between wp threshold and user max dimension#44

Open
Arukuen wants to merge 4 commits intodevelopfrom
fix/43-metadata-fix-on-scale
Open

fix: get lesser between wp threshold and user max dimension#44
Arukuen wants to merge 4 commits intodevelopfrom
fix/43-metadata-fix-on-scale

Conversation

@Arukuen
Copy link
Copy Markdown
Contributor

@Arukuen Arukuen commented Apr 14, 2026

fixes #43

Summary by CodeRabbit

  • New Features

    • Settings now respect WordPress’s image auto-scaling threshold in addition to the app’s max image dimension.
    • Maximum Image Dimension field shows a 2560 placeholder when WP scaling is disabled; help text now explains using the WP threshold when available.
  • Bug Fixes

    • Image resizing uses the more restrictive value between the app setting and the WordPress threshold.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Exposes WordPress's big_image_size_threshold (default 2560) to frontend JS via localized cimoSettings, computes a final max image dimension client-side by taking the lower non-zero value between the plugin setting and WP threshold, and updates admin UI placeholder/help text accordingly.

Changes

Cohort / File(s) Summary
Admin script loader
src/admin/class-script-loader.php
Localizes wpScalingThreshold (from apply_filters('big_image_size_threshold', 2560)) into cimoSettings passed to cimo-script.
Frontend converter logic
src/shared/converters/index.js
Parses window.cimoSettings.maxImageDimension and window.cimoSettings.wpScalingThreshold, computes the lower non-zero value as finalMaxDimension, and passes it as maxDimension into ImageConverter.
Admin settings UI & REST schema
src/admin/js/page/admin-settings.js, src/admin/class-admin.php
Adds placeholder="2560" and dynamic help text for the "Maximum Image Dimension" control (uses wpScalingThreshold when present). Also adds additionalProperties: true to the show_in_rest.schema for cimo_options.

Sequence Diagram(s)

sequenceDiagram
    participant PHP as "Admin PHP\n(class-script-loader.php)"
    participant Browser as "Browser\n(admin UI)"
    participant CimoScript as "Frontend JS\n(cimo-script)"
    participant Converter as "Image Converter\n(src/shared/converters)"

    PHP->>CimoScript: localize cimoSettings { maxImageDimension, wpScalingThreshold }
    Browser->>CimoScript: load cimo-script (reads cimoSettings for UI/help)
    Browser->>Converter: user triggers conversion/upload
    CimoScript->>Converter: convert(image, cimoSettings)
    Converter->>Converter: parse values -> finalMax = min(non-zero values) or fallback
    Converter->>Converter: call ImageConverter with maxDimension = finalMax
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Feat: bulk optimization #34 — Modifies ImageConverter behavior/options; closely related to changes that compute/pass a final maxDimension to the converter.

Poem

🐰 I nibble at thresholds, gentle and neat,
Two numbers compete where pixels meet.
The smaller one wins, trims edges just right,
Metadata balanced, snug and light. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: computing the minimum between WordPress' scaling threshold and the user's configured maximum dimension to fix metadata mismatches when WordPress Automatic Image Scaling is enabled.
Linked Issues check ✅ Passed The changes successfully implement the core requirement from issue #43: Cimo now uses the lesser of WordPress' 2560px threshold and the user's max dimension to ensure metadata matches the final served image.
Out of Scope Changes check ✅ Passed All changes are directly related to addressing the linked issue: retrieving the WP threshold via filters, computing the minimum dimension for ImageConverter, updating UI placeholders and help text, and adjusting REST schema compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/43-metadata-fix-on-scale

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

🤖 Pull request artifacts

file commit
pr44-cimo-44-merge.zip b99dff7

github-actions Bot added a commit that referenced this pull request Apr 14, 2026
@bfintal
Copy link
Copy Markdown
Contributor

bfintal commented Apr 16, 2026

@Arukuen Please add:

  • placeholder for the maximum resize dimensions in Cimo settings
  • Adjust also the description for this setting to say that the WordPress maximum dimension of 2560 is used

github-actions Bot added a commit that referenced this pull request Apr 17, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/admin/js/page/admin-settings.js`:
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 578a78bb-b491-47c5-852f-7d7c71f5794a

📥 Commits

Reviewing files that changed from the base of the PR and between 4b1f2ff and 51f17f2.

📒 Files selected for processing (1)
  • src/admin/js/page/admin-settings.js

Comment thread src/admin/js/page/admin-settings.js Outdated
Comment thread src/admin/js/page/admin-settings.js Outdated
github-actions Bot added a commit that referenced this pull request Apr 20, 2026
github-actions Bot added a commit that referenced this pull request Apr 20, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/admin/js/page/admin-settings.js`:
- Around line 594-601: The placeholder currently uses a hardcoded '2560' and the
help text nests sprintf, causing inconsistent/unsplittable translations; update
the input's placeholder prop to use the dynamic
window.cimoSettings?.wpScalingThreshold (or undefined when falsy) so it matches
the help text logic, and refactor the help prop to choose between two complete,
self-contained translated sentences (one when wpScalingThreshold is truthy and
one when falsy) instead of nesting sprintf calls; adjust the JSX around
settings.disableWpScaling and handleInputChange('maxImageDimension', ...)
accordingly, and remove the stray blank line inside the JSX attributes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79c1e9f3-1a62-4963-b280-50b82c41a7a3

📥 Commits

Reviewing files that changed from the base of the PR and between 7c64227 and b99dff7.

📒 Files selected for processing (2)
  • src/admin/class-admin.php
  • src/admin/js/page/admin-settings.js
✅ Files skipped from review due to trivial changes (1)
  • src/admin/class-admin.php

Comment on lines +594 to +601
placeholder={ settings.disableWpScaling === 1 ? '2560' : undefined }
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={ 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' )
) }
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

Placeholder should use wpScalingThreshold and avoid split translations.

Two issues in this block:

  1. Placeholder is hardcoded to '2560' while the help text uses the dynamic window.cimoSettings?.wpScalingThreshold. If a site filters big_image_size_threshold to a non-default value, the placeholder and help will disagree. Use the localized value for both (and fall back to hiding the placeholder when the threshold is falsy, consistent with the branching already done for the help text).

  2. Nested sprintf splits a sentence across two translatable strings. Translators see an isolated fragment ("use WordPress's default auto-scaling at %spx") with no surrounding context, and word order can't be rearranged for languages that need it. Prefer two complete, self-contained sentences selected by a single conditional.

✏️ Suggested adjustment
-								placeholder={ settings.disableWpScaling === 1 ? '2560' : undefined }
+								placeholder={ settings.disableWpScaling === 1 && window.cimoSettings?.wpScalingThreshold
+									? String( window.cimoSettings.wpScalingThreshold )
+									: 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' ),
-									window.cimoSettings?.wpScalingThreshold
-										? sprintf( __( "use WordPress's default auto-scaling at %spx", 'cimo-image-optimizer' ), window.cimoSettings.wpScalingThreshold )
-										: __( 'disable auto-scaling', 'cimo-image-optimizer' )
-								) }
+								help={ window.cimoSettings?.wpScalingThreshold
+									? sprintf(
+										/* translators: %d is the WordPress big_image_size_threshold in pixels. */
+										__( "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 WordPress's default auto-scaling at %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 auto-scaling. We recommend a value of 1920px.', 'cimo-image-optimizer' )
+								}

Also note the stray blank line at 602 inside the JSX attributes — safe to remove.

🤖 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 - 601, The placeholder
currently uses a hardcoded '2560' and the help text nests sprintf, causing
inconsistent/unsplittable translations; update the input's placeholder prop to
use the dynamic window.cimoSettings?.wpScalingThreshold (or undefined when
falsy) so it matches the help text logic, and refactor the help prop to choose
between two complete, self-contained translated sentences (one when
wpScalingThreshold is truthy and one when falsy) instead of nesting sprintf
calls; adjust the JSX around settings.disableWpScaling and
handleInputChange('maxImageDimension', ...) accordingly, and remove the stray
blank line inside the JSX attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When Wordpress Automatic Image Scaling is ON, the file size in metadata does not match with the final.

2 participants