Skip to content

Social: Add image focal point data model and picker in the media section#49580

Draft
gmjuhasz wants to merge 1 commit into
trunkfrom
add/social-image-focal-point-data-model
Draft

Social: Add image focal point data model and picker in the media section#49580
gmjuhasz wants to merge 1 commit into
trunkfrom
add/social-image-focal-point-data-model

Conversation

@gmjuhasz

Copy link
Copy Markdown
Contributor

Fixes SOCIAL-503

Proposed changes

  • Add a focal point data model to jetpack_social_options (_wpas_options) post meta: image_focal_points: { [attachment_id]: { x, y } } — one point per image, keyed by attachment ID. Consumers look up the image they are processing; a missing key means unset. REST schema validates coordinates (0–1) via patternProperties and rejects unknown keys.
  • Add a MediaFocalPoint component to the media section (v2), wrapping FocalPointPicker from @wordpress/components. It replaces the static preview for real image attachments and commits on drag end only, rounded to 2 decimals.
  • The picker renders in both global and per-network/controlled mode — the point is a property of the image, not the connection, so it reads/writes the post-level map directly via use-post-meta (new imageFocalPoints value and updateImageFocalPoint( attachmentId, point ) helper). Hidden for SIG (attachment id 0) and video.
  • Switching media never clears the map: each image keeps its own entry, so toggling between images restores their points.
  • The UI is gated behind the social-image-focal-point feature (rolled out via a WordPress.com-side flag; sticker-driven, off everywhere by default). The data model is intentionally ungated.

This is PR 1 of 4 for the focal-point based social image generation project (SOCIAL-422). Follow-ups render the point in social previews (SOCIAL-504), wire drag-to-adjust into the preview modal (SOCIAL-505), and serve focal-cropped og:image variants (SOCIAL-506).

Related product discussion/links

  • SOCIAL-422 (project), SOCIAL-503 (this PR) — design discussion and mockups are linked from there.
  • WordPress.com-side rollout flag: 223008-ghe-Automattic/wpcom

Does this pull request change what data or activity we track or use?

No. New post meta stores user-selected focal point coordinates per image; no new tracking events.

Testing instructions

Requires a site with paid Social features (the media section is gated on them) and the social-image-focal-point feature. Until the wpcom flag PR deploys and a sticker is applied, you can test by temporarily returning true from the siteHasFeature( features.IMAGE_FOCAL_POINT ) check in media-section-v2/index.tsx.

  • Run jetpack build packages/publicize and load a post in the block editor.
  • Set a featured image and open the Jetpack Social sidebar → Media section: the image should render inside a focal point picker (draggable dot + Left/Top % inputs) instead of the static thumbnail.
  • Drag the dot and release. In the console, wp.data.select( 'core/editor' ).getEditedPostAttribute( 'meta' ).jetpack_social_options.image_focal_points should show { <attachment_id>: { x, y } } with 2-decimal values, written only on release.
  • Save the draft and reload: the dot stays where you left it.
  • Pick a different image via Select → From Media Library, set a different point, then switch back to the featured image: each image remembers its own point.
  • Select "Social image template" (SIG) or a video: plain preview, no picker.
  • Enable per-network customization and open Customize & preview: the per-network media section shows the picker too, and a point set there is the same post-level value (not per connection).
  • With the feature check returning false (default), the media section behaves exactly as on trunk.
  • jetpack test js packages/publicize and jetpack test php packages/publicize cover the picker visibility, map merging, and the REST schema round-trip/validation.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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 add/social-image-focal-point-data-model branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/social-image-focal-point-data-model

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

Copy link
Copy Markdown
Contributor

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!

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/publicize/_inc/hooks/use-post-meta/index.js 30/31 (96.77%) 0.35% 0 💚
projects/packages/publicize/src/class-publicize-base.php 317/642 (49.38%) 1.80% 0 💚
projects/packages/publicize/src/class-publicize.php 58/256 (22.66%) 0.78% -2 💚
projects/packages/publicize/_inc/components/media-section-v2/index.tsx 89/103 (86.41%) 8.96% -9 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/publicize/_inc/components/media-section-v2/media-focal-point.tsx 6/6 (100.00%) 💚

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant