Skip to content

Subscriptions: add "Send as email" toggle#34592

Merged
simison merged 3 commits intotrunkfrom
add/dont-email-to-subs-toggle
Dec 15, 2023
Merged

Subscriptions: add "Send as email" toggle#34592
simison merged 3 commits intotrunkfrom
add/dont-email-to-subs-toggle

Conversation

@simison
Copy link
Copy Markdown
Member

@simison simison commented Dec 12, 2023

Resolves Automattic/wp-calypso#44263
Resolves #10876

Adds "Send as email" toggle:

(FYI Below screenshots are outdated)

Screenshot 2023-12-12 at 15 08 01

Proposed changes:

  • Adds a toggle to disable email sending post-by-post basis.
  • Register the meta, and sync the setting to WP.com

The feature pre-existed before Gutenberg, so the backend was already handled in Jetpack.

Previously the toggle was "negated", i.e. checking it to "not send email". Clearer UX is to do something when toggle is enabled, hence the meta and toggle handling seem a bit backwards.

TODO: PR needs some minor work in pre/post-publish panel copies and to check if post was published previously.
image
image
image

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  • Create a new post

  • In post settings, leave toggle enabled and publish the post.

  • Note pre-publish panel toggle — you can try change it, go back to post panel, etc.

  • Note copy at pre-publish panel.

  • Post gets sent as an email

  • The toggle should be disabled now and in truthy setting (the email was already sent)
    image

  • Create another post, leave toggle disabled and publish the post

  • Note copy at pre-publish panel.

  • No email was sent

  • The toggle should be disabled now and in falsy setting (no way to send email now that post was published)

@simison simison added the [Status] Needs Review This PR is ready for review. label Dec 12, 2023
@simison simison changed the title Add/dont email to subs toggle Subscriptions: add "Send as email" toggle Dec 12, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 12, 2023

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 WordPress.com Simple 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, and enable the add/dont-email-to-subs-toggle branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/dont-email-to-subs-toggle
    

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 github-actions bot added [Block] Subscribe [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Dec 12, 2023
@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 Team 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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for January 9, 2024 (scheduled code freeze on January 8, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@simison simison requested review from jeherve and lezama and removed request for lezama December 12, 2023 13:26
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This setting felt flaky, so commented it out. If it doesn't work, we can remove for now and add back in separate PR.

Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This works well for me, but I don't know if the wording for that setting is clear enough. At first, I thought the toggle was related to the preview email below:

image
  • Maybe there should be a separator between the 2?
  • Maybe the parts that do not apply anymore get removed when you toggle off the email?
Screenshot 2023-12-12 at 18 17 37
  • What if instead of a toggle, we had a "none" option as a radio, something like this?
image

@simison
Copy link
Copy Markdown
Member Author

simison commented Dec 12, 2023

@jeherve thanks! Yep, we're working still on the wording and structure of the pre-publish and post-publish panels for this 👍 It definitely needs some adjustments.

@simison
Copy link
Copy Markdown
Member Author

simison commented Dec 12, 2023

What if instead of a toggle, we had a "none" option as a radio, something like this?

That panel controls access, which is somewhat separate from whom we send the emails, albeit very related. I.e. the access also affects how you see blog posts, posts in the Reader, etc. Hence the setting should be separate.

@lezama lezama force-pushed the add/dont-email-to-subs-toggle branch 2 times, most recently from 58863bb to 79cc12d Compare December 13, 2023 00:15
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that this was old meta field I'm re-using for backwards compatibility, but it was never registered like this:

https://github.com/search?q=repo%3AAutomattic%2Fjetpack%20_jetpack_dont_email_post_to_subs&type=code

@simison simison force-pushed the add/dont-email-to-subs-toggle branch from fbaf854 to d43f61f Compare December 15, 2023 09:29
lezama
lezama previously approved these changes Dec 15, 2023
Copy link
Copy Markdown
Contributor

@lezama lezama left a comment

Choose a reason for hiding this comment

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

Tested and works great and everything makes much more sense than before.

Feel free to keep polishing but Approving in case you want to merge 😄

const showMisconfigurationWarning = getShowMisconfigurationWarning( postVisibility, accessLevel );

{ shouldLoadSubscriptionPlaceholder && (
const isSendEmailEnabled = useSelect( select => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In a follow-up, I'd like this in a re-usable React hook.

return (
<ToggleControl
checked={ isSendEmailEnabled }
disabled={ isPostPublished || ! canEdit }
Copy link
Copy Markdown
Member Author

@simison simison Dec 15, 2023

Choose a reason for hiding this comment

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

In a follow-up we should check if the post was published already previously and set the toggle disabled. Prior art:

/**
* Save a flag when a post was ever published.
*
* It saves the post meta when the post was published and becomes a draft.
* Then this meta is used to hide subscription messaging in Publish panel.
*
* @param string $new_status Tthe "new" post status of the transition when saved.
* @param string $old_status The "old" post status of the transition when saved.
* @param object $post obj The post object.
*/
public function maybe_set_first_published_status( $new_status, $old_status, $post ) {
$was_post_ever_published = get_post_meta( $post->ID, '_jetpack_post_was_ever_published', true );
if ( ! $was_post_ever_published && 'publish' === $old_status && 'draft' === $new_status ) {
update_post_meta( $post->ID, '_jetpack_post_was_ever_published', true );
}
}

// Subscriptions will not be triggered for a post that was already published in the past.
const shouldLoadSubscriptionPlaceholder = useSelect( select => {
const meta = select( editorStore ).getEditedPostAttribute( 'meta' );
return ! isModuleActive && ! isLoadingModules && ! meta?.jetpack_post_was_ever_published;
} );

I tried it briefly but it felt flaky, so better in separate PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@simison simison enabled auto-merge (squash) December 15, 2023 12:57
@simison simison merged commit 4c9a552 into trunk Dec 15, 2023
@simison simison deleted the add/dont-email-to-subs-toggle branch December 15, 2023 13:00
@github-actions github-actions bot removed [Status] Needs Review This PR is ready for review. [Status] In Progress labels Dec 15, 2023
@github-actions github-actions bot added this to the jetpack/13.0 milestone Dec 15, 2023
@jeherve jeherve added the [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Subscribe [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Newsletter: allow not send blog post as an email Subscriptions: add Gutenberg support on option to toggle email delivery on a per-post basis

3 participants