Repository navigation
Fix the All Media count in caption and document pickers - #2258
Conversation
The media sidebar's All Media count passed the picker's type filter to wp/v2/media as media_type. That arg only accepts whole types (image, video, text, application, audio), so pickers limited to exact MIME types (the video editor's caption picker, the Document block) got a 400 and showed All Media 0. Entries with a slash now go to mime_type; whole types stay on media_type. Fixes #2239
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
mismatched_plugin_name | Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM". |
0 |
trademarked_term | The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name. |
📁 assets/build/css/main.css (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedStylesScope | This style is being loaded in all contexts. |
📁 assets/src/libs/analytics.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/10/28/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
📁 assets/build/js/main.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/10/28/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
The first version sent exact MIME types to wp/v2/media as mime_type, but that route only takes a list there from WordPress 6.9, and GoDAM supports 6.5. On 6.5 to 6.8 the list was dropped and All Media showed every file. A filter with exact MIME types now asks admin-ajax query-attachments, the query the picker's own grid runs, which reads the list on every supported version. No filter and whole types still use the REST route as before. The helper now also reads the frame or URL filter itself, so the tests cover the wiring from the open picker to the request.
admin-ajax.php registers core's query-attachments action for POST requests only; a GET answered 400.
Code review —
|
…x URL A filter of more than one whole type (image and video) sent media_type=image,video, which the REST route rejects before WordPress 6.9. Send it to query-attachments, like exact MIME types. With no admin-ajax URL on the page, fall back to the REST route's mime_type instead of posting to wp-admin/undefined.
|
Thanks @KMchaudhary. Fixed in 9ed4073; tests 9 of 9 pass, and the two new ones fail on the previous commit.
|
Re-review — commit
|
| # | Finding | Status |
|---|---|---|
| 1 | Multiple whole types → 400 → All Media 0 | ✅ Fixed — routing is now hasExactType || types.length > 1, so multi-type filters go to query-attachments |
| 2 | new URL(undefined, …) → bogus ajax URL |
✅ Fixed — guarded on ajaxUrl, with a REST mime_type fallback |
| 3 | No tests for the two riskiest paths | ✅ Fixed — added multi-whole-type and no-ajax-URL tests |
| 4 | Obscure join→split flatten |
✅ Fixed — now flatMap((e) => String(e).split(',')) |
| 5 | Builder couples to global state via default param | Left as-is — a reasonable call; it keeps the single call site in folders.js trivial |
One minor note, not blocking: the new !ajaxUrl fallback sends mime_type: types (a list), which wp/v2/media only accepts from WP 6.9 — so on 6.5–6.8 without an admin-ajax URL a multi/exact filter would still 400. That combination is effectively unreachable (admin pages always expose ajaxurl/wp.ajax), and the comment already flags it as 6.9+, so it reads as an intentional best-effort last resort. Single exact types still degrade fine there.
No new issues introduced. LGTM. 👍
Automated re-review (high effort).
No code change.
Review packet
In one line: the media picker's All Media count now works when the picker only allows caption files or documents, instead of failing with a 400 and showing 0. Fixes #2239.
1. Criteria and proof
video,image) still use the REST route as before; more than one type goes toquery-attachments2. Before and after
Same four steps on both runs, on godam-dev with one test .vtt caption file in the library (removed after). Left pane: the video editor's caption picker. Right pane: the Document block's picker, then the plain Media Library page as an untouched control.
▶ Video (16 s): B1, before, on 2.5.1. Caption picker: All Media 0, and the count request fails with 400. Document picker: All Media 0, also 400. Media Library page: 71.
▶ Play the video
▶ Video (14 s): V2, after, with this PR. Caption picker: All Media 1. Document picker: All Media 4 (the 4 documents in the library). Both count requests return 200. Media Library page: still 71.
▶ Play the video
3. Tests
pages/media-library/data/utilities.test.js, 9 tests forgetAllMediaCountRequest:query-attachmentsPOST and never goes tomedia_typevideoand[ 'image' ]stay on the REST route asmedia_typequery-attachmentstogetherimage,video) goes toquery-attachments, sincemedia_typetakes one value before WordPress 6.9mime_typepost_mime_typeURL parammedia_type), the tests fail (the two added after review fail on the first version of this PR too). For example, "counts exact MIME types through a query-attachments POST" getswp/v2/mediawithmedia_type.4. Risk flags
No risk flags fired on #2258. Nothing in the diff touched the watched areas.
5. Independent review
mime_typelist. That only works from WordPress 6.9, and GoDAM supports 6.5. On 6.5 to 6.8 the list is dropped and All Media shows every filequery-attachments, which takes a list on every version (commits 6620909, ee80ed6). Checked on WordPress 6.8.11video/*would count everythingquery-attachmentshandles them the way the picker's own grid doespost_mime_type=allin the URL still gives a 4006. Not verified
The Media Library page's own type filters (Documents, Spreadsheets, Archives) were not clicked through. They pass lists of exact types, the same input the Document picker sends.
On WordPress 6.8 I checked only the request this PR makes, not the GoDAM UI. On a throwaway 6.8.11 site with 1 caption file and 1 image:
media_type=text/vtt,...mime_type=text/vtt,...query-attachmentsPOST withtext/vtt,...Multisite.
7. Scope
None.
What changed
The All Media count used WordPress's
wp/v2/mediaroute with the picker's type list inmedia_type. That filter only takes whole types (image,video,text,application,audio) and answers 400 to exact file types such astext/vtt. The route takes a list of exact types (mime_type) only from WordPress 6.9.Now a filter with exact file types is counted through admin-ajax
query-attachments. That's the same query the picker's grid runs, so the count matches the files the picker lists, on every WordPress version GoDAM supports. A filter of more than one type goes there too. With no filter, or one whole type, the count still comes from the REST route as before.pages/media-library/data/utilities.js: newgetAllMediaCountRequest()picks the route and builds the request. admin-ajax only registersquery-attachmentsfor POST, so that request is a POST.pages/media-library/redux/api/folders.js:getAllMediaCountuses it. The folder and Uncategorized counts sendpost_mime_typeto GoDAM's own routes, which already accept exact types, so they are unchanged.This has been broken since 1.10.0 (#1353). The branch starts from the 2.5.0 commit that main and develop share, so it can target either without a rebase.