Skip to content

Sharing & Likes: Serve the template placements through the REST API - #53732

Merged
jeherve merged 3 commits into
trunkfrom
add/sharing-likes-placements-rest
Oct 19, 2026
Merged

jeherve merged 3 commits into
trunkfrom
add/sharing-likes-placements-rest

Conversation

@jeherve

@jeherve jeherve commented Oct 16, 2026

Copy link
Copy Markdown
Member

Fixes CM-975

Proposed changes

#53413 added two options saying where the Sharing Buttons and Like blocks go in block theme templates, but only WP-CLI can set them so far. This lets the React Settings > Sharing screen read and save them, and gives it a Site Editor link to the page template.

  • wpcom/v2/sharing-likes/settings gains sharing_buttons_auto_add and likes_auto_add. Each is a list holding before_content, after_content, or nothing, and saves through Template_Placements::update(), the options' only writer.
  • Each key is only offered while its section is in block_call_to_action: a block theme with the block available, and the legacy feature off. likes_auto_add also needs a site that can show Likes, so a connected site in offline mode doesn't get it. Anywhere else the key is missing from reads, and a write that carries it is refused before anything is saved, as with every other setting.
  • A write with both sides is refused, rather than quietly trimmed to after_content by the writer.
  • wpcom/v2/sharing-likes/status gains page_template_editor_url next to site_editor_url: the Site Editor link to the theme's page template, or an empty string when the theme has none.
  • Both reach the screen's script data through the existing routes, and types.ts knows about them.

Nothing in the UI uses them yet; the placement cards come in CM-976.

Rationale

Only in block_call_to_action. The routes only offer what the screen shows, which is what keeps them from bringing the legacy buttons back on a site that moved to the blocks. These two keys are the first settings only the React screen shows (the PHP screen keeps its Site Editor link until it retires in CM-945), so the package's AGENTS.md now ties that rule to the section variants instead of the PHP screen. Since they're only offered where the legacy feature is already off, they can't reopen it.

Both sides are refused. Core can't hook one block both before and after the post content (see #53413), so Template_Placements keeps after_content when it's given both. Doing that silently over REST would let the screen show a save that never happened. The schema's maxItems: 1 refuses it instead, so the error is core's rest_invalid_param.

A separate page link. One card covers posts and pages. The cards' "Preview and edit" link keeps opening the single template, and CM-976 will use the page link in a line under the cards, for owners who want to change pages on their own. It's looked up and memoised like the single template link.

PUT /wp-json/wpcom/v2/sharing-likes/settings
{ "sharing_buttons_auto_add": [ "after_content" ] }
→ 200, { …, "sharing_buttons_auto_add": [ "after_content" ], "likes_auto_add": [] }

PUT /wp-json/wpcom/v2/sharing-likes/settings
{ "sharing_buttons_auto_add": [ "before_content", "after_content" ] }
→ 400 rest_invalid_param, nothing saved

Related product discussion/links

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

No.

Testing instructions

On a connected Jetpack site running a block theme (Twenty Twenty-Five works), with the Sharing and Likes modules off:

  • Open the block editor on any post, then your browser console, and read the settings:
    await wp.apiFetch( { path: '/wpcom/v2/sharing-likes/settings' } )
    sharing_buttons_auto_add and likes_auto_add are both there, as empty lists.
  • Save one:
    await wp.apiFetch( { path: '/wpcom/v2/sharing-likes/settings', method: 'PUT', data: { sharing_buttons_auto_add: [ 'after_content' ] } } )
    The response says [ 'after_content' ]. View a single post and a page: the Sharing Buttons block shows after the content on both.
  • Send [ 'before_content', 'after_content' ] the same way. It's refused with a 400, and reading the settings again still gives [ 'after_content' ].
  • Read the status with await wp.apiFetch( { path: '/wpcom/v2/sharing-likes/status' } ). page_template_editor_url opens the Pages template in the Site Editor.
  • Turn the Sharing module on (wp jetpack module activate sharedaddy), and read the settings again. sharing_buttons_auto_add is gone, and a PUT with it is refused with rest_sharing_likes_setting_unavailable.
  • With the React screen on (add_filter( 'rsm_jetpack_ui_modernization_sharing_likes', '__return_true' ); in an mu-plugin), JetpackScriptData.sharing_likes on Settings > Sharing carries both keys and page_template_editor_url.

Fixes CM-975

The React screen needs to read and save where the Sharing Buttons and
Like blocks go in block theme templates (CM-972) before it can replace
its "Open Site Editor" button with placement cards (CM-976).

`settings` gains `sharing_buttons_auto_add` and `likes_auto_add`, saved
through `Template_Placements::update()`. Each is offered only while its
section is in `block_call_to_action`, where the legacy feature is off
for good, so the keys cannot reopen it. `likes_auto_add` also needs
`likes_supported()`: offline mode reaches that variant, but the screen
then says a connection is needed and the hooks add nothing. The schema
caps each list at one item, because core inserts a block hooked on both
sides of one anchor only before it. A write with both is refused rather
than quietly trimmed by the writer, so the screen never shows a save
that did not happen.

`status` gains `page_template_editor_url`, the Site Editor link for the
theme's `page` template, empty when there is none, so the screen can
tell owners how to change pages on their own.

The REST rule in AGENTS.md said the routes offer what the PHP screen
shows. These keys exist on the React screen only, since the PHP screen
retires with CM-945, so the rule now names the section variants instead.
@jeherve jeherve added Enhancement Changes to an existing feature — removing, adding, or changing parts of it Docs [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Package] Sharing Likes labels Oct 16, 2026
@jeherve jeherve self-assigned this Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 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/sharing-likes-placements-rest branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/sharing-likes-placements-rest

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!

The invalid-placement test only checked for a 400, which the "setting
unavailable" refusal also returns, so it would keep passing if its setup
stopped offering the settings. It now asserts `rest_invalid_param`.

The variant test's docblock said an unrestricted setting would hook a
block next to the legacy buttons, which `Hooked_Blocks` already
prevents; the real cost is a placement that lies idle and switches on
unasked later.

Drop rows no mutation tells apart from another: the reversed "both
sides" pair, a null row the existing null test covers, and a "classic
theme" row that only exercised the suite's unresolvable theme. The
single template link assertion now checks the link points at `single`.

The README no longer says no screen sets the placement options.
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 5 files.

File Coverage Δ% Δ Uncovered
projects/packages/sharing-likes/src/settings/class-environment.php 25/41 (60.98%) -4.88% 2 ❤️‍🩹
projects/packages/sharing-likes/src/rest/class-settings-controller.php 159/159 (100.00%) 0.00% 0 💚
projects/packages/sharing-likes/src/rest/class-status-controller.php 87/87 (100.00%) 0.00% 0 💚
projects/packages/sharing-likes/src/settings/class-likes-section.php 102/103 (99.03%) -0.03% 0 💚
projects/packages/sharing-likes/src/settings/class-sharing-section.php 58/58 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

@jeherve
jeherve merged commit 5b07007 into trunk Oct 19, 2026
88 checks passed
@jeherve
jeherve deleted the add/sharing-likes-placements-rest branch October 19, 2026 15:44
@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 Review This PR is ready for review. labels Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Sharing Likes [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.

1 participant