Repository navigation
Add core/media-query ability - #1098
jorgefilipecosta wants to merge 29 commits into
Conversation
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1098 +/- ##
=============================================
+ Coverage 81.53% 82.27% +0.73%
- Complexity 3071 3231 +160
=============================================
Files 129 131 +2
Lines 12253 12875 +622
=============================================
+ Hits 9991 10593 +602
- Misses 2262 2282 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tested in the browser console of the block editor, with the Custom Abilities and Excerpt Generation experiments on (the second one loads the abilities client modules): const { ready } = await import( '@wordpress/core-abilities' );
await ready;
const { executeAbility } = await import( '@wordpress/abilities' );
const run = ( input ) =>
executeAbility( 'core/media-query', input ).catch( ( error ) => ( { error: error.code } ) );
// A post and two attachments, the first one attached to the post.
const postId = 610;
const attachedId = 611;
const unattachedId = 612;
// A collection with the default fields.
console.log( 'list', await run( { include: [ attachedId, unattachedId ] } ) );
// One item, with the requested fields.
console.log( 'item', await run( { id: attachedId, fields: [ 'title_rendered', 'caption_raw', 'alt_text', 'post', 'filename', 'media_details' ] } ) );
// Filters, sorting and pages: the second of two matches.
console.log( 'filtered', await run( { media_type: [ 'image' ], mime_type: [ 'image/png' ], search: 'demo', orderby: 'title', order: 'asc', per_page: 1, page: 2, fields: [ 'id', 'title_rendered' ] } ) );
// The items attached to a post.
console.log( 'parent', await run( { parent: [ postId ], fields: [ 'id', 'post' ] } ) );
// Errors.
console.log( 'id with a query', await run( { id: attachedId, per_page: 1 } ) ); // ability_invalid_input
console.log( 'page too far', await run( { include: [ attachedId ], page: 99 } ) ); // media_post_invalid_page_number
console.log( 'relevance without a search', await run( { orderby: 'relevance' } ) ); // media_no_search_term_defined
console.log( 'missing item', await run( { id: 999999999 } ) ); // rest_ability_cannot_executeOutput:
|
|
@jorgefilipecosta note that I'm holding off on requesting reviews until this comes out of draft status |
|
Closing in favor of WordPress/abilities#5. |
What?
Closes #1062
Adds
core/media-query, a read-only ability for media library items.Why?
Agents can read posts, users, and settings through abilities, but not the media library.
How?
includes/Abilities/Media/Media.php, behind the Custom Abilities experiment./wp/v2/media: the posts controller'sget_items(),get_item(), and permission checks, and the attachments controller's query and fields. Error codes are REST's withmedia_in place ofrest_.excludeis ignored whenincludeis given;id, or a collection that returns{ media, total, total_pages }.search,media_type,mime_type,parent,author,include,excludeandstatus.orderbyandorder.pageandper_page.fieldspicks the fields, with a lean default set, andidis always returned.title,captionanddescriptionare flattened to*_rawand*_rendered. Asking for a raw field reads in the edit context, so a collection only lists the items the caller can edit.Differences from REST:
slug,offset,author_exclude,parent_exclude;search_columns,search_semantics,orderby=include_slugs;context,_fieldsandpassword.guid,type,class_list,featured_media,comment_status,ping_status,meta,template,permalink_template,generated_slug;register_rest_field()fields;missing_image_sizes,exif_orientation,image_quality,image_output_format,image_save_progressive).media_invalid_param(REST'srest_invalid_param);ability_invalid_permissions;linkandsource_urlare always strings._links, embedding, headers, orrest_*filters.Testing Instructions
npm run test:php -- --filter 'MediaTest|Gated_AbilitiesTest'npm run test:e2e -- tests/e2e/specs/abilities/core-media-query.spec.jsChangelog Entry