Skip to content

Subscription Site: Allow to add Subscribe block at the end of each post#35458

Merged
pkuliga merged 35 commits into
trunkfrom
update/subscription-site-first-toggle
Feb 28, 2024
Merged

Subscription Site: Allow to add Subscribe block at the end of each post#35458
pkuliga merged 35 commits into
trunkfrom
update/subscription-site-first-toggle

Conversation

@pkuliga

@pkuliga pkuliga commented Feb 6, 2024

Copy link
Copy Markdown
Contributor

Related to peKye1-EA-p2

Proposed changes:

It:

  • adds a toggle to the Newsletter settings to render the Subscribe block at the end of each post. Decided to not implement the parent toggle at this point since I'm not sure we would need it

Screenshot 2024-02-26 at 22 12 51

  • renders the Subscribe block at the end of each post when the above toggle is on

Screenshot 2024-02-26 at 22 11 43

The feature is behind the feature flag and if you want to enable it you need to go into your sandbox mu-plugins, and add the following line to your 0-sandbox.php file:

add_filter( 'jetpack_subscription_site_enabled', '__return_true' );

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:

Prerequisites

You need to have Jetpack Newsletter module enabled.

Feature flag disabled

  1. Open WP Admin, the Home page of your blog, and the post page of your blog, and make sure there are no suspicious warnings/notices in the server error log
  2. Open the Newsletter settings and make sure the "Add Subscribe block at the end of each post" toggle is not visible
  3. Open the post page of your blog and make sure there is no Subscribe block below it (unless you added it there by yourself 😄)

Feature flag enabled

  1. Enable the feature flag (described in this PR changes section how to do it)
  2. Repeat steps 1-3 from the"Feature flag disabled" section with a difference that in step 2 the "Add Subscribe block at the end of each post" toggle should be actually visible
  3. Enable the toggle
  4. Open the post page of your blog and make sure there is a Subscribe block at the end of the post
  5. Play with some different options, like disable the"Add Subscribe block at the end of each post" toggle or even disable the Newsletter module completely and make sure it's working as expected.

@github-actions

github-actions Bot commented Feb 6, 2024

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 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 update/subscription-site-first-toggle branch.

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

    bin/jetpack-downloader test jetpack update/subscription-site-first-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 [Feature] WPCOM API [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Admin Page React-powered dashboard under the Jetpack menu labels Feb 6, 2024
@github-actions

github-actions Bot commented Feb 6, 2024

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 March 5, 2024 (scheduled code freeze on March 4, 2024).

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

Comment thread projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss Outdated
Comment thread projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php Outdated
@pkuliga pkuliga changed the title Subscriptions: Make site a subscription site Subscription Site: Allow to add Subscribe block at the end of each post Feb 7, 2024
@pkuliga pkuliga added [Status] Needs Review This PR is ready for review. [Status] Needs Team Review Obsolete. Use Needs Review instead. labels Feb 7, 2024
Comment on lines +122 to +129
.wp-block-jetpack-subscriptions__subscribe_post_end {
margin: 2em auto !important;
gap: 0 !important;

& > p {
margin-bottom: 0.8em !important;
}
}

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.

Those custom styles are used only for classic themes.

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.

Might be worth a comment to clarify it's for classic themes and in what scenario. Hard to know otherwise.

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 idea, added the comment.

disableInSiteConnectionMode
module={ subscriptions }
>
<p>Enable automatic insertion of the Subscribe block into the theme</p>

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.

Decided to not wrap it with __ to not bother translators since it still may change.

'jetpack_subscriptions_subscribe_post_end_enabled',
] ) }
onChange={ handleSubscribePostEndToggleChange }
label="End of each post"

@pkuliga pkuliga Feb 26, 2024

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.

No __ as well for the same reason as above.

@pkuliga pkuliga added the [Status] Needs Team Review Obsolete. Use Needs Review instead. label Feb 26, 2024
'attrs' => $attrs,
'innerBlocks' => array( $hooked_block ),
'innerContent' => array(
'<div class="wp-block-group">

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.

If we still need the group block for layout purposes, let's use the full block markup version:

<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">

</div>
<!-- /wp:group -->

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.

Oh I see now, it comes from the above array with core/group etc. Do we then still need the div or doesn't that get generated on its own?

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.

It looks like it's redundant but it seems it's needed. It's not getting generated automatically, the same for:

<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"300"}},"className":"has-text-align-center"} -->
<p class="has-text-align-center" style="font-style:normal;font-weight:300">

If you look at our themes, for example: https://github.com/Automattic/themes/blob/trunk/lettre/templates/index.html you'll find similar things.

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.

simison
simison previously approved these changes Feb 27, 2024

@simison simison left a comment

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.

Let's get this in 👍

I didn't test with latest WP trunk, and instead only had latest trunk of Gutenberg plugin. Hence the wrapper blocks didn't work for me, and the result wasn't good looking.

We could add Gutenberg & WP core version checks to ensure the feature works well? Jetpack itself supports two previous WP versions.

Feature flag worked well for toggle and the hook.

Another thing that might require likes/sharing to be blocks is that would make sense for subscribe block be above those buttons:

Screenshot 2024-02-27 at 12 37 20

<p class="has-text-align-center" style="font-style:normal;font-weight:300">
<em>Aliquam a ullamcorper lorem<br>Integer at tempus nibh</em>
</p>
<!-- /wp:paragraph -->',

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.

I thought the Subscribe block would come here but is that also getting automatically added by the hook itself?

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.

It's passd by innerBlocks:

'innerBlocks'  => array( $hooked_block ),
'innerContent' => array(
	'<div class="wp-block-group">
		<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"300"}},"className":"has-text-align-center"} -->
		<p class="has-text-align-center" style="font-style:normal;font-weight:300">
			<em>Aliquam a ullamcorper lorem<br>Integer at tempus nibh</em>
		</p>
		<!-- /wp:paragraph -->',
	null,
	'</div>',

and it's automatically inserted into the innerContent.

@simison

simison commented Feb 27, 2024

Copy link
Copy Markdown
Member

* @return bool
*/
protected function is_subscription_site_feature_enabled() {
return (bool) apply_filters( 'jetpack_subscription_site_enabled', false );

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.

You'll want to add a docblock for this filter, so the codex parser can pick it up.

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.

Not sure why we need it but added. This is a feature flag and we don't want to expose it.

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.

@jeherve fine to keep the filter internal? We wouldn't want to use filter deprecation when removing it.

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.

I suppose that would be okay. I guess I'm just a bit weary of filters that are temporary but that end up staying for some time. :)

Let's maybe add a short comment saying that the filter is temporary?

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.

Added :)

Comment on lines +94 to +107
add_filter(
'hooked_block_types',
function ( $hooked_blocks, $relative_position, $anchor_block ) {
if ( $anchor_block === 'core/post-content' && $relative_position === 'after' ) {
$hooked_blocks[] = 'jetpack/subscriptions';
}

return $hooked_blocks;
},
10,
3
);

add_filter(

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.

Since those are brand new hooks that have changed a bit since WordPress 6.4 came out, I personally opted to gate the auto-addition to WP 6.5+, see #35905

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 idea, added, thanks!

@pkuliga pkuliga requested review from jeherve and simison February 27, 2024 21:04

@jeherve jeherve left a comment

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.

Looks like you may need one more update to latest trunk to fix the build issues that were brought by #36004.

@pkuliga pkuliga merged commit bbde201 into trunk Feb 28, 2024
@pkuliga pkuliga deleted the update/subscription-site-first-toggle branch February 28, 2024 10:00
@github-actions github-actions Bot added this to the jetpack/13.2 milestone Feb 28, 2024
@github-actions github-actions Bot removed [Status] In Progress [Status] Needs Team Review Obsolete. Use Needs Review instead. labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin Page React-powered dashboard under the Jetpack menu [Block] Subscribe [Block] Subscriber Login [Feature] WPCOM API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants