Skip to content

Conversation

@juah255
Copy link

@juah255 juah255 commented Dec 22, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

This PR resolves an issue where vendor dashboard store banner cropping was causing an error

Related Pull Request(s)

  • Full PR Link

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Fix: vendor dashboard store banner cropping error

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Improvements
    • Revamped image cropping component for more reliable and flexible behavior.
    • Refined logic that determines when cropping is required, avoiding unnecessary prompts for flexible sizing and matching-dimension images.
    • Expanded selection options: persistent instances, width/height targets, coordinate bounds, max dimensions and aspect-ratio support.
    • Preserved existing max-size constraints while introducing better default width handling for media frames.

✏️ Tip: You can customize this high-level summary in your review settings.

@juah255 juah255 self-assigned this Dec 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

📝 Walkthrough

Walkthrough

Replaced the CustomizeImageCropper with a new Cropper controller in the media frame, reworked cropping eligibility to use shouldBeCropped (treating flexible width/height as non-cropping), expanded imgSelectOptions with sizing/coordinate fields, and updated default width fallback to dokan.store_banner_dimension.

Changes

Cohort / File(s) Summary
Image cropper / media frame
assets/src/js/script.js
Replaced CustomizeImageCropper with Cropper in media controller usage and external constructor references; updated Cropper instantiation to accept imgSelectOptions and a width fallback from dokan.store_banner_dimension (fallback value changed).
Cropping decision & options
assets/src/js/script.js
Reworked cropping logic: replaced control.mustBeCropped(...) with shouldBeCropped (treats flex-width+flex-height as non-cropping; disables cropping when actual image equals initial dimensions); inverted canSkipCrop accordingly. Extended imgSelectOptions with instance, persistent, imageWidth, imageHeight, x1, y1, x2, y2, maxHeight, maxWidth, and aspectRatio.
Option propagation
assets/src/js/script.js
Ensured Cropper receives the expanded imgSelectOptions and a default width via fallback (uses dokan.store_banner_dimension with a provided fallback).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

🎉 QA Approved, Dev Review Done, Upcoming Release

Suggested reviewers

  • mrabbani
  • Aunshon

Poem

🐰 A new Cropper hops into view,

pixels aligned, coordinates true.
Flags decide what should be pared,
options opened, defaults shared.
I nibble bugs, then dance — hooray for you! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary fix: addressing a store banner cropping error in the vendor dashboard.
Description check ✅ Passed The description follows the template structure with all major sections present including objectives, changes proposed, linked issue, and changelog entry, though some optional sections lack detail.
Linked Issues check ✅ Passed The PR addresses the core requirement from issue #5265: fixing the image cropping error by replacing CustomizeImageCropper with Cropper and adding default width parameter.
Out of Scope Changes check ✅ Passed All changes in assets/src/js/script.js are directly related to fixing the store banner cropping error; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/vendor-dashboard-store-banner-cropping-error

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.

@juah255 juah255 added Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing labels Dec 22, 2025
Copy link
Contributor

@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

🧹 Nitpick comments (1)
assets/src/js/script.js (1)

177-187: Simplify the redundant condition in the cropping logic.

The second conditional at line 183 checks !shouldBeCropped, but this is redundant when the first condition (flexWidth && flexHeight) sets shouldBeCropped to false. Consider whether the condition should use else if to clarify that these are mutually exclusive paths, or restructure to remove the logical redundancy.

Since the second condition already assigns the same value in both cases, simplifying the logic would improve clarity without changing behavior.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60223f8 and 2bf1449.

📒 Files selected for processing (1)
  • assets/src/js/script.js
🧰 Additional context used
🧬 Code graph analysis (1)
assets/src/js/script.js (1)
assets/src/js/product-editor.js (3)
  • realHeight (1292-1292)
  • realWidth (1291-1291)
  • xInit (1293-1300)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (1, 3)
🔇 Additional comments (3)
assets/src/js/script.js (3)

170-173: LGTM: Variable declarations reorganized.

The variables are now declared upfront and assigned values later, which improves code clarity.


189-203: LGTM: Cropper options properly expanded.

The additional properties (instance, persistent, imageWidth, imageHeight, aspectRatio, maxHeight, maxWidth) are standard options for the WordPress image cropper and provide better control over the cropping interface.


346-346: Verify wp.media.controller.Cropper is available in the minimum WordPress version supported.

The wp.media.controller.Cropper class has been available since WordPress 4.2.0, while the wp.media.controller.CustomizeImageCropper is specifically for the WordPress Customizer context (available since 4.3.0). Before merging, confirm:

  1. That the plugin's minimum WordPress version supports 4.2.0 or higher
  2. That this resolves the cropping error mentioned in the PR

new wp.media.controller.Cropper({
imgSelectOptions: settings.calculateImageSelectOptions,
control: cropControl
suggestedWidth: dokan?.store_banner_dimension?.width || 5000
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for store_banner_dimension and related context
echo "=== Searching for store_banner_dimension usage ==="
rg -n "store_banner_dimension" --type=js --type=php -B 3 -A 3

echo ""
echo "=== Searching for file around line 348 in script.js ==="
fd -e js -n "script.js" -x wc -l {}

echo ""
echo "=== Checking if the file exists and getting context around line 348 ==="
if [ -f "assets/src/js/script.js" ]; then
  sed -n '340,360p' "assets/src/js/script.js"
fi

Repository: getdokan/dokan

Length of output: 10279


Inconsistent fallback value for suggestedWidth in media uploader.

The fallback value of 5000 on line 348 is inconsistent with the rest of the codebase. Line 343–344 immediately above uses dokan.store_banner_dimension.width without a fallback, and other parts of the codebase (Vue components, backend) consistently use 625 as the width default. Dokan's documented default store banner width is 625.

If dokan.store_banner_dimension.width can be undefined, the fallback should match the established default of 625 for consistency. If it's guaranteed to be defined from the backend, the optional chaining and fallback are unnecessary. Clarify which case applies and adjust accordingly.

🤖 Prompt for AI Agents
In assets/src/js/script.js around line 348, the media uploader uses a fallback
width of 5000 for suggestedWidth which conflicts with the rest of the codebase
and Dokan's documented default of 625; update this to use the consistent default
by replacing the 5000 fallback with 625, or remove the optional chaining +
fallback entirely if dokan.store_banner_dimension.width is guaranteed by the
backend (choose one approach and apply it consistently so suggestedWidth becomes
either dokan.store_banner_dimension.width || 625 or simply
dokan.store_banner_dimension.width).

@juah255 juah255 requested a review from mrabbani December 22, 2025 04:25
@mrabbani
Copy link
Member

@juah255 , Thanks for your PR.

Could you pls try to reproduce this issue in Old WP version e.i. 6.8 or older?

new wp.media.controller.Cropper({
imgSelectOptions: settings.calculateImageSelectOptions,
control: cropControl
suggestedWidth: dokan?.store_banner_dimension?.width || 5000
Copy link
Member

Choose a reason for hiding this comment

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

Pls replace the 5000 with the default value of Dokan Settings.

@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Dec 29, 2025
Copy link
Contributor

@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: 0

♻️ Duplicate comments (1)
assets/src/js/script.js (1)

348-348: Fallback value should be 625 to match Dokan's documented default.

The fallback was changed from 5000 to 500, but as previously noted, Dokan's documented default store banner width is 625. Additionally, lines 343-344 access dokan.store_banner_dimension without optional chaining or fallbacks, creating an inconsistency.

🔎 Suggested fix
-            suggestedWidth: dokan?.store_banner_dimension?.width || 500
+            suggestedWidth: dokan?.store_banner_dimension?.width || 625

Or, for consistency with lines 343-344, if dokan.store_banner_dimension.width is guaranteed to be defined:

-            suggestedWidth: dokan?.store_banner_dimension?.width || 500
+            suggestedWidth: dokan.store_banner_dimension.width
🧹 Nitpick comments (1)
assets/src/js/script.js (1)

177-187: Consider simplifying the cropping eligibility logic.

The current two-step approach works correctly but has some redundancy. The !shouldBeCropped check on line 183 is always true when the first if block was executed.

🔎 Suggested simplification
-      var shouldBeCropped = true;
-      
-      if (flexWidth && flexHeight) {
-        shouldBeCropped = false;
-      }
-      
-      if (!shouldBeCropped || (realWidth === xInit && realHeight === yInit)) {
-        shouldBeCropped = false;
-      }
-      
-      controller.set('canSkipCrop', !shouldBeCropped);
+      var shouldBeCropped = !(flexWidth && flexHeight) && 
+                            !(realWidth === xInit && realHeight === yInit);
+      
+      controller.set('canSkipCrop', !shouldBeCropped);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf1449 and c534df8.

📒 Files selected for processing (1)
  • assets/src/js/script.js
🧰 Additional context used
🧬 Code graph analysis (1)
assets/src/js/script.js (1)
assets/src/js/product-editor.js (3)
  • realHeight (1292-1292)
  • realWidth (1291-1291)
  • xInit (1293-1300)
🔇 Additional comments (2)
assets/src/js/script.js (2)

189-203: LGTM!

The expanded imgSelectOptions object properly configures the cropper with appropriate dimension constraints and coordinate boundaries for the store banner.


346-350: Good fix: Switching to the standard Cropper controller.

Using wp.media.controller.Cropper instead of CustomizeImageCropper is the correct approach for the vendor dashboard context, as CustomizeImageCropper is designed specifically for the WordPress Customizer and may have dependencies or behaviors that cause errors outside that context.

However, suggestedWidth should not be passed directly to the Cropper controller. According to WordPress media API design, suggestedWidth and suggestedHeight are UI hints meant for the Library controller state—they help the media frame decide whether cropping is necessary. The Cropper controller accepts imgSelectOptions (confirmed), but suggestedWidth passed to the Cropper itself will likely be ignored or cause unexpected behavior. Remove suggestedWidth from the Cropper initialization on line 349.

@juah255 juah255 added Needs: Dev Review It requires a developer review and approval and removed Needs: Author Reply labels Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants