Social: default share-message meta to the saved template server-side#48634
Merged
Social: default share-message meta to the saved template server-side#48634
Conversation
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! |
Code Coverage SummaryCoverage changed in 8 files. Only the first 5 are listed here.
|
81179e1 to
0536252
Compare
40e6067 to
0536252
Compare
0536252 to
ac621c8
Compare
…OCIAL-479) Move template-fallback responsibility from the editor to the server so the editor can render `_wpas_mess` and `connection.message` verbatim instead of mirroring the renderer's fallback chain client-side. An empty stored value now cleanly means "user explicitly cleared", and the renderer (WPCOM extractor) handles the actual template substitution at share time. - `class-publicize-base.php`: in `register_post_meta()`, resolve the share-message default from `Settings::get_message_template()` once on init priority 20 (gated on `Current_Plan::supports( 'social-message-templates' )`) and pass it as `register_meta`'s `'default'`. Avoids hooking `default_post_metadata`, which fires on every unset post-meta lookup across the request. Falls back to `''` on non-template sites — the legacy extractor would otherwise treat a raw template as literal share text. - `class-connections-post-field.php`: default `connection.message` to the connection's own `template` (when set) regardless of per-network mode, so the editor receives the connection-template fallback up front. Without this, `syncConnections` (which fires on per-network toggle) would treat `connection.message === undefined` as "uncustomized" and silently copy the post-level share message over the connection's own template. Per-network override `message`, when present, still takes precedence. No fallback to the saved global template here — that's the post-level `_wpas_mess`'s job, with the editor's `connection.message ?? globalMessage` chain bridging the two. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…AL-479) `connection.message` and the post-level `globalMessage` are now server-side defaulted to the appropriate template (parent commit), so the editor-side fallback chains in `useRenderMessageItems` and `useConnectionPreviewData` collapse to "use connection.message in per-network mode, otherwise globalMessage" with a `?? globalMessage` guard for connections that have neither override nor connection template. The `messageTemplate` selector reads and the `hasConnectionMessage`/`connection.template` branching in both hooks are gone. The two hooks must agree exactly so `currentRenderItem.message` matches `baseMessage` and `isDebouncingRenderedMessage` doesn't stay stuck true after toggling per-network → global; the simplified expression is identical in both call sites. Test fixture in `useConnectionPreviewData` updated to drop the now- absent `messageTemplate` mock entry from the chained `useSelect` sequence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
) The two prior commits move template-fallback responsibility to the server, so the editor's customization forms can render the meta verbatim and stop reaching for the saved template option. global.tsx: drop the `useSocialMediaMessage` + `messageTemplate` read + `shareMessage || messageTemplate` pre-fill. SharePostForm's default already wires `useSocialMediaMessage` internally, and an empty `shareMessage` is the right thing to display now that the renderer handles the fallback. per-network.tsx: drop the `connection.template ?? globalMessage` fallback chain, the `messageTemplate` read, and the three-way help text. Display rule collapses to `connection.message ?? globalMessage` — `connection.message` is server-defaulted to the connection's own template when no override exists, and globalMessage covers the no- template case. Help text becomes a single sentence; the editor no longer needs to know which template tier will apply. use-per-network-customization.ts: rework `syncConnections`. The "uncustomized" outer guard switches from `connection.message === undefined` to `connection.media_source !== undefined` — message is now server-defaulted to `connection.template`, so it no longer indicates customization, but media fields are only written when the user (or a prior sync) has explicitly set them. The `! connection.template` skip from 8d92d39 is preserved so the post-level share message doesn't overwrite the connection-template contribution to `connection.message`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ac621c8 to
a132811
Compare
…AL-479) In per-network mode, fall back to the saved site message template (not `globalMessage` / `_wpas_mess`) when the connection has no per-post override and no connection-template default. The form itself is bound strictly to `connection.message` — the site-template fallback is applied only at preview-render time, so the field stays editable and a cleared value is preserved as `''`. - `per-network.tsx`: drop the `connection.message ?? globalMessage` chain; bind the field to `connection.message ?? ''`. Cleared messages stay cleared. - `useRenderMessageItems` / `useConnectionPreviewData`: read `siteMessageTemplate` from the social store and use it as the per-network fallback in `connection.message ?? siteMessageTemplate`. Global mode keeps `globalMessage`. Both hooks compute the same chain so `currentRenderItem.message` matches `baseMessage` and `isDebouncingRenderedMessage` doesn't get stuck. - `useRenderMessageItems`: combine the two `useSelect` calls (connections + siteMessageTemplate) into one for clarity. Test fixture switches to a `mockSelect` helper that returns the merged shape. - `useConnectionPreviewData` test: extend the chained `useSelect` mock with the new `messageTemplate` slot. - `per-network.test.tsx`: assert the new no-fallback form rule (cleared / unset connection.message → empty field, not globalMessage). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
gmjuhasz
approved these changes
May 11, 2026
Contributor
gmjuhasz
left a comment
There was a problem hiding this comment.
It tests well with all the mentioned scenarios
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.
Closes SOCIAL-481.
Proposed changes
Move template-fallback responsibility for the share-message and per-connection message from the editor to the server, so the editor renders the meta verbatim and an empty stored value is correctly interpreted as "fall back to the template" by the renderer.
The field can now actually be cleared without snapping back to the template — the bug introduced by SOCIAL-479's editor-side pre-fill — and the editor's customization forms / preview render hooks no longer need to know about templates at all.
class-publicize-base.php—register_post_meta()resolves the share-message default fromSettings::get_message_template()once oninitpriority 20 (gated onCurrent_Plan::supports( 'social-message-templates' )) and passes it asregister_meta's'default'. Avoids the hot-path cost of hookingdefault_post_metadata. Falls back to''on non-template sites — the legacy extractor would otherwise treat a raw template as literal share text.class-connections-post-field.php— defaultsconnection.messageto the connection's owntemplate(when set) regardless of per-network mode, so the editor receives the connection-template fallback up front. Without this,syncConnections(which fires on per-network toggle) would treatconnection.message === undefinedas "uncustomized" and silently copy the post-level share message over the connection's own template. Per-network overridemessage, when present, still takes precedence.useRenderMessageItems/useConnectionPreviewData— drop themessageTemplateselector reads and theconnection.message ?? connection.template ?? globalMessagefallback chain. Both hooks collapse to "useconnection.messagein per-network mode, otherwiseglobalMessage", with a?? globalMessageguard for connections that have neither override nor template.customization-forms/global.tsx— drop theuseSocialMediaMessage+messageTemplateread and theshareMessage || messageTemplatepre-fill.SharePostForm's default already wiresuseSocialMediaMessageinternally, and an emptyshareMessageis now the right thing to display.customization-forms/per-network.tsx— drop the three-way help text and theconnection.template ?? globalMessagefallback chain. Display rule collapses toconnection.message ?? globalMessage, and the help text becomes a single sentence.use-per-network-customization.ts— reworksyncConnections. The "uncustomized" outer guard switches fromconnection.message === undefinedtoconnection.media_source !== undefined— message is now server-defaulted toconnection.template, so it no longer indicates customization, but media fields are only written when the user (or a prior sync) has explicitly set them. The! connection.templateskip from the prior commit chain is preserved so the post-level share message doesn't overwrite the connection-template contribution toconnection.message.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Set up a test site with the message-templates feature enabled and at least two social connections.
Test it along with 215588-ghe-Automattic/wpcom
Site-wide template fallback (global mode):
{title} — read more at {url}).Per-connection template fallback:
Hey FB folks: {title}).syncConnections doesn't overwrite per-connection templates:
Non-template-mode sites unaffected:
{title}literal injection), and shares fall back to the post title as before.Before / After