Repository navigation
Sharing & Likes: Serve the template placements through the REST API - #53732
Merged
Merged
Conversation
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.
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
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! |
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.
Code Coverage SummaryCoverage changed in 5 files.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/settingsgainssharing_buttons_auto_addandlikes_auto_add. Each is a list holdingbefore_content,after_content, or nothing, and saves throughTemplate_Placements::update(), the options' only writer.block_call_to_action: a block theme with the block available, and the legacy feature off.likes_auto_addalso 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.after_contentby the writer.wpcom/v2/sharing-likes/statusgainspage_template_editor_urlnext tosite_editor_url: the Site Editor link to the theme'spagetemplate, or an empty string when the theme has none.types.tsknows 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_Placementskeepsafter_contentwhen it's given both. Doing that silently over REST would let the screen show a save that never happened. The schema'smaxItems: 1refuses it instead, so the error is core'srest_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.
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:
sharing_buttons_auto_addandlikes_auto_addare both there, as empty lists.[ 'after_content' ]. View a single post and a page: the Sharing Buttons block shows after the content on both.[ 'before_content', 'after_content' ]the same way. It's refused with a 400, and reading the settings again still gives[ 'after_content' ].await wp.apiFetch( { path: '/wpcom/v2/sharing-likes/status' } ).page_template_editor_urlopens the Pages template in the Site Editor.wp jetpack module activate sharedaddy), and read the settings again.sharing_buttons_auto_addis gone, and aPUTwith it is refused withrest_sharing_likes_setting_unavailable.add_filter( 'rsm_jetpack_ui_modernization_sharing_likes', '__return_true' );in an mu-plugin),JetpackScriptData.sharing_likeson Settings > Sharing carries both keys andpage_template_editor_url.