Skip to content

Image Studio: register _jetpack_feature_clip_id post meta#48640

Merged
saroshaga merged 4 commits intotrunkfrom
rsm-2685-feature-clip-post-meta
May 11, 2026
Merged

Image Studio: register _jetpack_feature_clip_id post meta#48640
saroshaga merged 4 commits intotrunkfrom
rsm-2685-feature-clip-post-meta

Conversation

@saroshaga
Copy link
Copy Markdown
Contributor

@saroshaga saroshaga commented May 8, 2026

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.

  • Registered for post only (pages can be added later if there's a use case).
  • Gated behind the existing is_image_studio_enabled() check, so behaviour is unchanged on sites where Image Studio is off.
  • show_in_rest: true exposes 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.
  • Auth callback defers to current_user_can( 'edit_post', $post_id ).
  • Sanitised through absint.

This is the server-side half. The post-editor sidebar that consumes this meta lands in a sibling Calypso PR.

Testing instructions

  1. Enable Image Studio on a test site (Premium+ on WordPress.com, or any Jetpack-connected site with AI features available).
  2. Authenticate as a user who can edit posts and request a post:
    curl -s -u 'user:app-password' https://YOURSITE/wp-json/wp/v2/posts/123 | jq '.meta'
    
    Expect "_jetpack_feature_clip_id": 0 for posts without a clip.
  3. Write a value:
    curl -s -u 'user:app-password' -X POST -H 'content-type: application/json' \
      -d '{"meta":{"_jetpack_feature_clip_id":42}}' \
      https://YOURSITE/wp-json/wp/v2/posts/123 | jq '.meta._jetpack_feature_clip_id'
    
    Expect 42. Re-read the post and confirm it persisted.
  4. As a Subscriber (no edit_post on that post) repeat step 3 — REST should respond 403 rest_cannot_update.
  5. POST a non-integer (e.g. "abc"); expect it to round-trip as 0 (absint).
  6. Disable Image Studio (add_filter( 'jetpack_ai_enabled', '__return_false' ) on a non-WPCOM dev site) and confirm _jetpack_feature_clip_id no 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 with edit_post capability on the target post and only readable through the standard core REST posts endpoint as part of the existing meta payload.

Test plan checklist

  • On a site with Image Studio enabled (Atomic / WordPress.com / self-hosted with Jetpack), GET /wp-json/wp/v2/posts/{id} returns meta._jetpack_feature_clip_id (defaults to 0).
  • 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 without edit_post.
  • On a site where Image Studio is disabled, the meta key is not exposed over REST.
  • Non-integer payloads are coerced to 0 via absint.
  • Anonymous (logged-out) requests cannot write the meta.

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the rsm-2685-feature-clip-post-meta branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack rsm-2685-feature-clip-post-meta

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Extension] Image Studio [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels May 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 2, 2026
    • Code freeze: June 1, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 8, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 8, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/extensions/plugins/image-studio/image-studio.php 162/176 (92.05%) 0.27% 1 ❤️‍🩹

Full summary · PHP report · JS report

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id post meta on init when Image Studio is enabled, with REST exposure, sanitization via absint, and an auth callback based on edit_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,
Comment on lines +189 to +200
/**
* 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.
saroshaga added 2 commits May 8, 2026 19:00
- 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.
Copy link
Copy Markdown
Contributor

@aagam-shah aagam-shah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@saroshaga saroshaga merged commit 9141f11 into trunk May 11, 2026
83 of 85 checks passed
@saroshaga saroshaga deleted the rsm-2685-feature-clip-post-meta branch May 11, 2026 09:08
@github-actions github-actions Bot added this to the jetpack/15.9 milestone May 11, 2026
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Extension] Image Studio [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants