Image Studio: register _jetpack_feature_clip_id post meta#48640
Image Studio: register _jetpack_feature_clip_id post meta#48640
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
There was a problem hiding this comment.
Pull request overview
This PR adds server-side support for Image Studio “feature clips” by registering a new post meta key (_jetpack_feature_clip_id) for posts, exposing it through the WordPress REST API so the editor UI can read/write the attachment ID for a generated clip.
Changes:
- Register
_jetpack_feature_clip_idpost meta oninitwhen Image Studio is enabled, with REST exposure, sanitization viaabsint, and an auth callback based onedit_post. - Add PHPUnit coverage for the new meta key constant, registration behavior, and auth callback behavior.
- Add a Jetpack changelog entry describing the new meta field.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/plugins/jetpack/extensions/plugins/image-studio/image-studio.php | Defines the meta key constant and registers the gated post meta with REST exposure and permission checks. |
| projects/plugins/jetpack/tests/php/extensions/plugins/image-studio/Image_Studio_Test.php | Adds unit tests covering meta key constant, registration, gating, and auth callback behavior. |
| projects/plugins/jetpack/changelog/add-feature-clip-post-meta | Adds changelog entry for the new feature clip post meta. |
| 'type' => 'integer', | ||
| 'description' => 'Attachment ID of the generated video clip designated as this post\'s feature clip.', | ||
| 'single' => true, | ||
| 'show_in_rest' => true, |
| /** | ||
| * Permission check for writing the feature clip meta on a given post. | ||
| * | ||
| * @param bool $allowed Whether the user is allowed (unused — recomputed here). | ||
| * @param string $meta_key Meta key being checked. | ||
| * @param int $object_id Post ID. | ||
| * @return bool | ||
| */ | ||
| function feature_clip_meta_auth_callback( $allowed, $meta_key, $object_id ) { | ||
| unset( $allowed, $meta_key ); | ||
| return current_user_can( 'edit_post', (int) $object_id ); | ||
| } |
| Significance: patch | ||
| Type: enhancement | ||
|
|
||
| Image Studio: register a `_jetpack_feature_clip_id` post meta that links a generated video clip to its post. Stored as the attachment ID, exposed over REST so the post editor can read/write it. |
- Register meta with `default => 0` so REST always returns a deterministic integer for posts that haven't generated a clip. - Clarify the auth_callback docblock: it gates both reads and writes, not just writes. - Add a unit test asserting the default surfaces from get_post_meta(). - Capitalize the changelog entry verb to match the surrounding entries.
Summary
Registers a new post meta —
_jetpack_feature_clip_id— that links a generated video clip to its post. Stored as the attachment ID; the URL is resolved client-side via the Media Library so renames/deletes/replacements stay consistent without duplicating data.postonly (pages can be added later if there's a use case).is_image_studio_enabled()check, so behaviour is unchanged on sites where Image Studio is off.show_in_rest: trueexposes the field on/wp-json/wp/v2/posts/{id}so the post editor can read and write it via standard REST without a dedicated endpoint.current_user_can( 'edit_post', $post_id ).absint.This is the server-side half. The post-editor sidebar that consumes this meta lands in a sibling Calypso PR.
Testing instructions
"_jetpack_feature_clip_id": 0for posts without a clip.42. Re-read the post and confirm it persisted.edit_poston that post) repeat step 3 — REST should respond403 rest_cannot_update."abc"); expect it to round-trip as0(absint).add_filter( 'jetpack_ai_enabled', '__return_false' )on a non-WPCOM dev site) and confirm_jetpack_feature_clip_idno longer appears in the REST response.Does this pull request change what data or activity we track or use?
Yes — minimally. This PR introduces a new post meta,
_jetpack_feature_clip_id, that stores a single integer (a Media Library attachment ID) per post. No tracking events, no PII, no third-party data flows. The meta is only writable by users withedit_postcapability on the target post and only readable through the standard core RESTpostsendpoint as part of the existingmetapayload.Test plan checklist
GET /wp-json/wp/v2/posts/{id}returnsmeta._jetpack_feature_clip_id(defaults to0).POST /wp-json/wp/v2/posts/{id}with{ meta: { _jetpack_feature_clip_id: 123 } }persists for editors of that post and rejects (403) for users withoutedit_post.0viaabsint.🤖 Generated with Claude Code