Opened 7 weeks ago
Closed 4 days ago
#64948 closed defect (bug) (fixed)
Media Modal: Can no longer set attachment filters
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Media | Keywords: | has-patch commit dev-reviewed fixed-major |
| Focuses: | javascript | Cc: |
Description
I have a plugin which modifies the media library modal by removing some of the attachment filters. It does so by getting a handle for the toolbar, and then doing
var filters = toolbar.get( 'filters' );
if ( this.get( 'type' ) == 'image' ) {
// update all
filters.filters.all.text = acf.__( 'All images' );
// remove some filters
delete filters.filters.audio;
delete filters.filters.video;
delete filters.filters.image;
}
etc.
This is no longer working as of [61757] -- filters.filters is now undefined.
The reason for this is that [61757] wrapped the media attachment filters <select> and its <label> in a container <div> for accessibility purposes. However, this changes the return value of toolbar.get('filters') from the AttachmentFilters view instance to the wp.media.View corresponding to the <div>, breaking plugins that rely on this to customize the media library filters.
Attachments (2)
Change History (18)
#1
@
7 weeks ago
- Focuses javascript added
- Owner set to joedolson
- Status changed from new to accepted
This ticket was mentioned in PR #11415 on WordPress/wordpress-develop by @joedolson.
6 weeks ago
#3
- Keywords has-patch added
This change reverts the modifications to the JS API in the media modal so that filters can be modified, and insteads implements the visible labels using CSS.
This results in a more complex CSS to modify, since the lack of a wrapper complicates the layout, but avoids breaking access to the filters in 3rd party code.
Trac ticket: https://core.trac.wordpress.org/ticket/64948
## Use of AI Tools
None.
This ticket was mentioned in PR #11426 on WordPress/wordpress-develop by @kapilpaul.
6 weeks ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/64948
## Use of AI Tools
@joedolson commented on PR #11426:
6 weeks ago
#5
This looks to be a duplicate of https://github.com/WordPress/wordpress-develop/pull/11415; can you indicate how this is different?
This ticket was mentioned in Slack in #core-test by gaisma22. View the logs.
4 weeks ago
#7
@
4 weeks ago
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/11415
Environment
- WordPress: 7.1-alpha-62161-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 146.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Code Snippets 3.9.5
- Test Reports 1.2.1
Steps taken
- Add the following PHP snippet to your active theme's
functions.phpor via Code Snippets plugin to simulate accessing the filters.
add_action( 'admin_footer', function () {
if ( ! did_action( 'wp_enqueue_media' ) ) {
return;
}
?>
<script>
jQuery( document ).ready( function ( $ ) {
if ( ! wp || ! wp.media || ! wp.media.view || ! wp.media.view.AttachmentsBrowser ) {
return;
}
var OrigBrowser = wp.media.view.AttachmentsBrowser;
wp.media.view.AttachmentsBrowser = OrigBrowser.extend( {
createToolbar: function () {
OrigBrowser.prototype.createToolbar.apply( this, arguments );
var toolbar = this.toolbar;
var filters = toolbar.get( 'filters' );
console.log( '[Ticket 64948] toolbar.get("filters"):', filters );
console.log( '[Ticket 64948] filters.filters:', filters && filters.filters );
// Simulate what affected plugins do:
if ( filters && typeof filters.filters !== 'undefined' ) {
console.info( '[Ticket 64948] PASS: filters.filters is accessible.' );
} else {
console.error( '[Ticket 64948] FAIL: filters.filters is undefined.' );
}
}
} );
} );
</script>
<?php
} );
- Navigate to any post/page editor or the Media Library
- Click Add Media to open the media modal
- Observe the browser console
- Confirm that
filters.filtersis undefined - Apply the patch and repeat steps 2-4
- Observe the browser console again
- Confirm that
toolbar.get("filters")andfilters.filtersare accessible - ✅ Patch is solving the problem.
Expected result
- Plugins that customize media library filters by accessing
toolbar.get("filters")should continue to work correctly, and no errors related tofilters.filtersbeingundefinedshould appear in the browser console.
Screenshots/Screencast with results
@audrasjb commented on PR #11426:
2 weeks ago
#8
Closing in favor of #11415.
#9
@
13 days ago
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/11415
Environment
- WordPress: 7.1-alpha-62161-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: MySQL
- Browser: Chrome
- OS: Windows
- Theme: Twenty Twenty-Five
- Plugins:
- Code Snippets 3.9.5
- Test Reports 1.2.1
- MU Plugins: None
Steps to Reproduce (Before Patch)
- Add the following snippet to
functions.phpor via Code Snippets:
add_action( 'admin_footer', function () {
if ( ! did_action( 'wp_enqueue_media' ) ) {
return;
}
?>
<script>
jQuery( document ).ready( function ( $ ) {
if ( ! wp || ! wp.media || ! wp.media.view || ! wp.media.view.AttachmentsBrowser ) {
return;
}
var OrigBrowser = wp.media.view.AttachmentsBrowser;
wp.media.view.AttachmentsBrowser = OrigBrowser.extend( {
createToolbar: function () {
OrigBrowser.prototype.createToolbar.apply( this, arguments );
var toolbar = this.toolbar;
var filters = toolbar.get( 'filters' );
console.log( '[Ticket 64948] toolbar.get("filters"):', filters );
console.log( '[Ticket 64948] filters.filters:', filters && filters.filters );
if ( filters && typeof filters.filters !== 'undefined' ) {
console.info( '[Ticket 64948] PASS: filters.filters is accessible.' );
} else {
console.error( '[Ticket 64948] FAIL: filters.filters is undefined.' );
}
}
} );
} );
</script>
<?php
} );
- Open any post/page editor or Media Library
- Click "Add Media"
- Check the browser console
Actual Result (Before Patch)
toolbar.get('filters')returns an objectfilters.filtersis undefined- Console output:
FAIL: filters.filters is undefined
Steps After Applying Patch
- Apply the patch from PR #11415
- Repeat the steps above
Result (After Patch)
toolbar.get('filters')is accessiblefilters.filtersis properly defined- Console output:
PASS: filters.filters is accessible
Expected Result
Plugins relying on toolbar.get('filters') should be able to access filters.filters without encountering undefined, ensuring backward compatibility for media library customizations.
Conclusion
- ✅ Patch successfully resolves the issue
- ✅ Restores expected behavior for plugin integrations
- ✅ No regressions observed during testing
This ticket was mentioned in Slack in #core by jorbin. View the logs.
5 days ago
#11
@
5 days ago
- Keywords commit added
https://github.com/WordPress/wordpress-develop/pull/11415/ has an approval and test reports, so I think this is good to move forward.
@joedolson commented on PR #11415:
4 days ago
#12
I actually changed that intentionally; so that's as intended.
#14
@
4 days ago
- Keywords dev-feedback added
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for dev review to commit to the 7.0 branch.


As per today's bug scrub:
@joedolson is this one still on your radar?