Fix media modal crash on WP 7.0 due to attachment filters wrapper change#399
Fix media modal crash on WP 7.0 due to attachment filters wrapper change#399
Conversation
WP core commit [61757] wrapped the media attachment filters <select>
and <label> in a container <div> for accessibility. This changed
toolbar.get('filters') from returning the AttachmentFilters view
directly to returning a wrapper View, causing customizeFilters()
to crash with "Cannot read properties of undefined (reading 'all')".
Resolve the actual AttachmentFilters view by checking whether the
returned view has a .filters property, and if not, traversing its
subviews to find the AttachmentFilters instance. This is compatible
with both WP < 7.0 and WP 7.0+.
Fixes #396
See https://core.trac.wordpress.org/ticket/64948
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #399 +/- ##
============================================
- Coverage 54.00% 52.65% -1.35%
Complexity 4423 4423
============================================
Files 298 298
Lines 39467 39475 +8
============================================
- Hits 21314 20786 -528
- Misses 18153 18689 +536
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WP core commit 61757 wrapped the media attachment filters
<select>and<label>in a container<div>for accessibility. This changedtoolbar.get('filters')from returning theAttachmentFiltersview directly to returning a wrapperwp.media.View, causingcustomizeFilters()to crash with:This broke the media modal for any SCF image/file field on WP 7.0.
The fix resolves the actual
AttachmentFiltersview by checking whether the returned view has a.filtersproperty. If not (WP 7.0+), it traverses the wrapper's subviews to find theAttachmentFiltersinstance. This is compatible with both WP < 7.0 and WP 7.0+.Tested on both WP 6.9.4 and WP 7.0-RC2 with the full E2E suite passing.
Fixes #396
See https://core.trac.wordpress.org/ticket/64948
Use of AI Tools
This PR was authored with assistance from Claude Code (Anthropic). The fix was developed after debugging the root cause using Playwright-based investigation of the media modal behavior on WP 7.0-RC2.