Media: Add a settings dialog to the Media Library toolbar. - #12932
Media: Add a settings dialog to the Media Library toolbar.#12932t-hamano wants to merge 19 commits into
Conversation
The "Infinite Scrolling" personal option could only be reached from the user profile screen, far from the grid it affects. This adds a toggle next to the search field in the attachments browser toolbar that opens a modal dialog with that option, in both the grid and the media modal. The dialog is a native `dialog` element opened with `showModal()`, so the focus trap, the Escape handling, the backdrop and the focus restore on close come from the platform rather than from a hand-rolled implementation. Keyboard events are kept from reaching the media modal, whose own Escape handler and focus manager would otherwise fight the dialog. Toggling the checkbox saves the preference over Ajax and applies it in place: `wp.media.view.Attachments` can now bind and unbind its scroll handler after creation, and `wp.media.view.AttachmentsBrowser` swaps the Load more view in and out, so no page reload is needed. Both views now read the setting at creation time instead of capturing it when the module loads. The toggle is not rendered when a `media_library_infinite_scrolling` filter callback overrides the user preference, since the control would have no effect. Co-Authored-By: Claude <noreply@anthropic.com>
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Allows space for the media library settings toggle.
Improves experience for voice control
|
I pushed a few minor visual tweaks and changed the I noticed that the modal is not actually restricting focus, so that will need to be adjusted, but this is going in a direction that I think is viable. |
There was a problem hiding this comment.
Pull request overview
Adds a Media Library toolbar control that opens a native HTML <dialog> for editing per-user Media Library preferences (starting with infinite scrolling), and wires those preference changes through AJAX to update behavior immediately in the attachments browser.
Changes:
- Adds a toolbar “settings” toggle and
<dialog>templates for Media Library settings. - Introduces a new core AJAX action to persist the user’s infinite scrolling preference.
- Updates media views (Attachments/AttachmentsBrowser) and CSS to support toggling between infinite scrolling and “Load more” without a reload.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wp-includes/media.php | Exposes filtered vs user preference values and passes dialog config (nonce, state) to JS. |
| src/wp-includes/media-template.php | Adds Underscore templates for the settings toggle and <dialog> UI. |
| src/wp-includes/css/media-views.css | Styles the settings toggle/dialog and adjusts load-more visibility behavior. |
| src/wp-admin/includes/ajax-actions.php | Adds wp_ajax_set_media_library_settings() handler to save the preference. |
| src/wp-admin/css/media.css | Adjusts grid toolbar layout to accommodate the new toggle in narrow viewports. |
| src/wp-admin/admin-ajax.php | Registers set-media-library-settings as a core POST AJAX action. |
| src/js/media/views/library-settings.js | Implements the toolbar control, dialog open/close behavior, and AJAX save. |
| src/js/media/views/attachments/browser.js | Listens for preference changes and swaps infinite-scroll vs load-more UI live. |
| src/js/media/views/attachments.js | Makes infinite scrolling togglable after initialization; cleans up scroll bindings. |
| src/js/_enqueues/wp/media/views.js | Registers the new LibrarySettings view in the media views bundle. |
| Gruntfile.js | Adds build mapping for the new library-settings.js file. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ensures isFiltered compares like types when a callback returns 0/1.
Covers nonce failure, missing capability, the missing value and the stored preference.
Overview
WordPress core does not yet seem to have an API for rendering what are known as popovers. This PR instead attempts to render a settings dialog for the media library using the HTML native
dialogelement.Use of AI Tools
Note
This PR is a prototype. Almost all of the code in this PR was generated by Claude. If we find the approach taken in this PR to be reasonable, I would like to review all of the code.
Screenshots