Developer Integration API#67
Conversation
📝 WalkthroughWalkthroughCimo now provides a frontend enqueue helper, a ChangesDeveloper integration
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Integrator
participant window.cimo.optimizeFiles
participant optimizeFileConverters
participant UploadControl
Integrator->>window.cimo.optimizeFiles: provide files before upload
window.cimo.optimizeFiles->>optimizeFileConverters: resolve converters and optimize
optimizeFileConverters-->>window.cimo.optimizeFiles: optimized files and metadata
window.cimo.optimizeFiles-->>Integrator: return results
Integrator->>UploadControl: upload result files
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@DEVELOPER.md`:
- Around line 12-16: Update the documentation around the cimo_enqueue_assets
example to explicitly require registering selector filters before enqueueing
Cimo assets. Ensure the documented order places all selector filter registration
ahead of the wp_enqueue_scripts hook that calls cimo_enqueue_assets(), so
localized selectors use the custom values.
- Around line 24-28: Update the optimizeFiles example in DEVELOPER.md to wrap
the await and subsequent filesToUpload mapping in an async function, preserving
the existing behavior and making the snippet valid in a classic script.
In `@src/admin/js/public-api.js`:
- Around line 5-7: Update the comment above the public optimizeFiles assignment
to document that the API returns an array of objects shaped as {file, metadata},
with file as a File and metadata possibly null, rather than raw File objects.
Keep the window.cimo.optimizeFiles assignment unchanged.
🪄 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: b5658e52-1162-41c3-9c0c-12918c9f32c5
📒 Files selected for processing (9)
DEVELOPER.mdcimo.phpsrc/admin/class-script-loader.phpsrc/admin/js/index.jssrc/admin/js/media-manager/allowed-locations.jssrc/admin/js/media-manager/drop-zone.jssrc/admin/js/media-manager/select-files.jssrc/admin/js/optimize-files.jssrc/admin/js/public-api.js
fixes #65
Adds developer integration support for Cimo pre-upload optimization.
window.cimo.optimizeFiles(files, { showProgress })so plugins/themes can optimizeFile/FileListobjects before running their own upload flow.Behavior
How To Test
1. Test Frontend Enqueue
In a custom PHP plugin, enqueue Cimo assets on a frontend page:
Visit the frontend page and run this in the browser console:
Expected:
window.cimoSettingsis available.window.cimois available.window.cimo.optimizeFilesis a function.2. Test PHP Selector Filters
In the custom PHP plugin, add selector locations:
Visit the frontend page and run:
Expected:
window.cimoSettings.selectFilesAllowedLocationsincludes.my-plugin-uploader.window.cimoSettings.dropZoneAllowedLocationsincludes.my-plugin-dropzone.3. Test Automatic File Input Interception
Add this Custom HTML to the frontend page:
Select an image from the input.
Expected:
.my-plugin-uploaderwas added through the PHP filter.webp.4. Test
window.cimo.optimizeFilesRun this in the frontend browser console:
Expected:
resultsis an array of{ file, metadata }.results.map(result => result.file).Summary by CodeRabbit