Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable frontend preview for paid blocks requiring upgrade #18102

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Dec 16, 2020

Fixes 158-gh-Automattic/view-design and 157-gh-Automattic/view-design and 175-gh-Automattic/view-design.

Changes proposed in this Pull Request:

This PR re-enables frontend previews for paid blocks requiring an upgrade. If a block is unavailable due to not meeting plan requirements and the current user is an admin, the block will still be rendered on the frontend with an upgrade banner identical to the one that appears in the editor.

Screen Shot 2020-12-18 at 4 11 30 PM

It also refactors the existing UpgradePlanBanner used in the editor to pull out as much common code as possible into a generic Nudge component that can be server-side-rendered.

Jetpack product discussion

Internal reference: pcjTuq-8U-p2

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

  • TBD

Testing instructions:

This requires re-testing across all the scenarios: wpcom and Jetpack, with and without the required plan, and with and without Stripe connected.

Follow testing instructions on #17907.

Note: the wp-env scripts will not sync changes to class.jetpack-gutenberg.php or class-blocks.php. These may need to be manually synced to their respective files in the sandbox.

In order to test on free Jetpack sites, you will need to turn on the jetpack_block_editor_enable_upgrade_nudge filter locally.

Proposed changelog entry for your changes:

  • TBD

@stacimc stacimc self-assigned this Dec 16, 2020
@github-actions github-actions bot added the [Status] Needs Package Release This PR made changes to a package. Let's update that package now. label Dec 16, 2020
@jetpackbot
Copy link

jetpackbot commented Dec 16, 2020

Scheduled Jetpack release: January 12, 2021.
Scheduled code freeze: January 4, 2021

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 52c185b

@@ -32,6 +31,7 @@ function register_block() {
FEATURE_NAME,
array(
'render_callback' => __NAMESPACE__ . '\render_block',
'enable_preview' => true,
Copy link
Contributor Author

@stacimc stacimc Dec 16, 2020

Choose a reason for hiding this comment

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

I would love suggestions for a better name for this option.

Copy link
Member

Choose a reason for hiding this comment

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

enable_frontend_preview might be slightly more explanatory?

&& apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false )
/** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
&& apply_filters( 'jetpack_show_promotions', true )
&& ! is_feed()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last two conditions here were part of the original check for rendering a frontend upgrade nudge. I am looking for more context to see if they are still needed, particularly the jetpack_show_promotions filter.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing any usage of the jetpack_show_promotions filter across the Jetpack or WordPress.com codebase. I suspect this is a global way to turn off all promotional notifications across Jetpack. It's possible that this is being used by hosts somewhere though, so best to leave it in.

Copy link
Member

Choose a reason for hiding this comment

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

jetpack_block_editor_enable_upgrade_nudge is the current way we enable the display of upgrade nudges on WordPress.com. Do we still need this with this work?

&& apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false )
/** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
&& apply_filters( 'jetpack_show_promotions', true )
&& ! is_feed()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing any usage of the jetpack_show_promotions filter across the Jetpack or WordPress.com codebase. I suspect this is a global way to turn off all promotional notifications across Jetpack. It's possible that this is being used by hosts somewhere though, so best to leave it in.

&& apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false )
/** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
&& apply_filters( 'jetpack_show_promotions', true )
&& ! is_feed()
Copy link
Member

Choose a reason for hiding this comment

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

jetpack_block_editor_enable_upgrade_nudge is the current way we enable the display of upgrade nudges on WordPress.com. Do we still need this with this work?

// Stripe connection nudge.
if ( ! membership_checks() && current_user_can_edit() ) {
$stripe_nudge = render_stripe_nudge();
$stripe_nudge = render_stripe_nudge;
Copy link
Member

Choose a reason for hiding this comment

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

Missing ().

@@ -32,6 +31,7 @@ function register_block() {
FEATURE_NAME,
array(
'render_callback' => __NAMESPACE__ . '\render_block',
'enable_preview' => true,
Copy link
Member

Choose a reason for hiding this comment

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

enable_frontend_preview might be slightly more explanatory?

@stacimc
Copy link
Contributor Author

stacimc commented Dec 16, 2020

jetpack_block_editor_enable_upgrade_nudge is the current way we enable the display of upgrade nudges on WordPress.com. Do we still need this with this work?

This enables upgrade nudges in the editor, yes. It was part of the original conditional for displaying frontend upgrade nudges as well, so I included it in the first pass. I think you're right and it can be removed -- my thinking is:

If upgrade nudges in the editor weren't enabled, the user wouldn't have been able to insert the block at all, so we should never end up in a scenario where we're rendering a paid block on the frontend of a free site that does not support nudges.

Previously the Upgrade nudges were managed by the Premium Content
blocks' render_callbacks. This will not work if the plan_check is
enabled in the block at registration, because the render callback
is wrapped in an availability check and won't be called.

This commit abstracts the logic up a level. If the availability
check fails, instead of returning immediately, we now check to
see if upgrade nudges are enabled and the user is an admin. If so,
we render an upgrade nudge in addition to the ouptut of the block's
render_callback.

The logic for rendering the upgrade nudges can also be removed
from the Premium Content block now.
Adds an optional argument to `jetpack_register_block` to enable
rendering a preview on the frontend for admins when upgrade nudges
are enabled.
@stacimc stacimc force-pushed the update/enable-upgrade-nudge-on-frontend branch from ce5ff8e to 16b5b3c Compare December 16, 2020 21:40
@jeherve jeherve added [Status] In Progress [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Dec 17, 2020
@jeherve
Copy link
Member

jeherve commented Dec 17, 2020

Somewhat related: #14893, #18054.

Internal reference: pcjTuq-8U-p2

@stacimc stacimc changed the title WIP: Add option to enable frontend preview for paid blocks requiring upgrade Add option to enable frontend preview for paid blocks requiring upgrade Dec 17, 2020
@stacimc stacimc marked this pull request as ready for review December 17, 2020 18:03
Refactors the frontend upgrade nudge to a reusable SSR-rendable
nudge that is used by the UpgradePlanBanner (the nudge used in the
editor).
@stacimc stacimc changed the title Add option to enable frontend preview for paid blocks requiring upgrade Enable frontend preview for paid blocks requiring upgrade Dec 18, 2020
@stacimc stacimc changed the title Enable frontend preview for paid blocks requiring upgrade [WIP] Enable frontend preview for paid blocks requiring upgrade Jan 6, 2021
@stacimc
Copy link
Contributor Author

stacimc commented Jan 8, 2021

Closing in favor of #18239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Status] Needs Package Release This PR made changes to a package. Let's update that package now. Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants