Skip to content

Social: Default per-network mode from connection templates#48721

Open
gmjuhasz wants to merge 1 commit into
trunkfrom
fix/social-482-per-network-template-default
Open

Social: Default per-network mode from connection templates#48721
gmjuhasz wants to merge 1 commit into
trunkfrom
fix/social-482-per-network-template-default

Conversation

@gmjuhasz
Copy link
Copy Markdown
Contributor

Fixes SOCIAL-482

Proposed changes

  • Default per-network customization on when Message Templates are enabled and any loaded connection has a non-empty custom template.
  • Persist _wpas_customize_per_network: true when this default applies, so a post shared/reloaded after defaulting remains in per-network mode.
  • Keep the implementation lean: _wpas_customize_per_network is a boolean, so an explicit saved false cannot be distinguished from the default false on reload. A separate override flag could preserve "turned off despite custom template" across reloads, but this PR avoids that extra state because it does not seem worth it currently.

Related product discussion/links

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

No.

Testing instructions

  • Ensure Message Templates are enabled.
  • In the Social admin page, save a custom template for one connection.
  • Open a new or existing post that has not saved per-network customization as true; verify Customize each is selected by default.
  • Clear the custom connection template, then open a post without per-network customization saved; verify Same for all remains selected.
  • Run pnpm --filter @automattic/jetpack-publicize test -- _inc/hooks/use-per-network-customization/test/index.test.ts.
  • Run pnpm --filter @automattic/jetpack-publicize test.
  • Run pnpm --filter @automattic/jetpack-publicize typecheck.

@gmjuhasz gmjuhasz added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels May 12, 2026
@gmjuhasz gmjuhasz self-assigned this May 12, 2026
@gmjuhasz gmjuhasz added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels May 12, 2026
@gmjuhasz gmjuhasz requested a review from manzoorwanijk May 12, 2026 14:26
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 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 fix/social-482-per-network-template-default branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/social-482-per-network-template-default

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!

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 updates Jetpack Social’s editor behavior to automatically default into per-network customization mode when Message Templates are enabled and at least one connected account has a non-empty custom template, and persists that default in post meta so it survives reloads.

Changes:

  • Add template-based defaulting logic to usePerNetworkCustomization, persisting _wpas_customize_per_network: true when the default applies.
  • Track “default disabled for this editor session” state so users can toggle back to “Same for all” without immediately re-defaulting.
  • Extend hook test coverage for the new defaulting and session-disable behavior, plus add a changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
projects/packages/publicize/changelog/social-482-per-network-template-default Adds a changelog entry describing the behavioral fix.
projects/packages/publicize/_inc/hooks/use-per-network-customization/index.ts Implements template-driven default per-network mode and persists the meta flag when applicable.
projects/packages/publicize/_inc/hooks/use-per-network-customization/test/index.test.ts Adds tests validating defaulting behavior, blank-template behavior, and session-level disable.

Significance: patch
Type: fixed

Social: Default per-network customization to on only when a custom connection template exists.
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/publicize/_inc/hooks/use-per-network-customization/index.ts 34/39 (87.18%) 5.04% 0 💚

Full summary · PHP report · JS report

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

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

There is a use-case which doesn't work as expected. Please see the inline comment.

Comment on lines -33 to +45
const isEnabled = useSelect( select => {
const isMetaEnabled = useSelect( select => {
const meta = select( editorStore ).getEditedPostAttribute( 'meta' );

return Boolean( meta?.[ CUSTOMIZE_PER_NETWORK_KEY ] );
}, [] );
const shouldUseTemplateDefault =
templatesEnabled && hasConnectionTemplate && ! isMetaEnabled && ! templateDefaultDisabled;
const isEnabled = isMetaEnabled || shouldUseTemplateDefault;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This logic here is a bit problematic. If I try this combination:

  • Set the template for a connection
  • Switch to global mode
  • Save the post and reload
  • Open the preview mode

The toggle switches to per-network mode and you cannot switch back to global mode.

I think it should be

const isMetaEnabled = useSelect( select => {
	const meta = select( editorStore ).getEditedPostAttribute( 'meta' );

	return meta?.[ CUSTOMIZE_PER_NETWORK_KEY ];
}, [] );

const shouldUseTemplateDefault =
	isMetaEnabled ?? ( templatesEnabled && hasConnectionTemplate && ! templateDefaultDisabled );
const isEnabled = isMetaEnabled ?? shouldUseTemplateDefault;

But, we could organize that code better inside a useMemo using a bail-early approach.

That said, do you think we should pass the default value from the backend?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, after someone explicitly switches back to global, reload should not default them back into per-network. I think the cleanest fix is to keep the default logic client-side, but add a small persisted “user has explicitly chosen this toggle” flag so we can distinguish default false from user-saved false.

On the backend, that default is static, while this behavior depends on current connection templates. Making it dynamic there is awkward and broader than this issue.

What do you think?

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk May 12, 2026

Choose a reason for hiding this comment

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

I agree. The main idea here is to respect isMetaEnabled

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

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Publicize Now Jetpack Social, auto-sharing [Package] Publicize [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants