From 10190af9e7de2a09e118f4d13c720d7d542b8294 Mon Sep 17 00:00:00 2001 From: Romario Date: Fri, 13 Jan 2023 15:28:00 -0500 Subject: [PATCH] Gate newsletter feature by using a filter --- .../jetpack/class.jetpack-gutenberg.php | 22 +++++++++++++------ .../extensions/blocks/subscriptions/utils.js | 5 ++--- .../plugins/jetpack/extensions/index.json | 1 - 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index a505ac4f741e5..7de28e4402eea 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -684,13 +684,13 @@ public static function enqueue_block_editor_assets() { $initial_state = array( 'available_blocks' => self::get_availability(), 'jetpack' => array( - 'is_active' => Jetpack::is_connection_ready(), - 'is_current_user_connected' => $is_current_user_connected, + 'is_active' => Jetpack::is_connection_ready(), + 'is_current_user_connected' => $is_current_user_connected, /** This filter is documented in class.jetpack-gutenberg.php */ - 'enable_upgrade_nudge' => apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false ), - 'is_private_site' => '-1' === get_option( 'blog_public' ), - 'is_coming_soon' => ( function_exists( 'site_is_coming_soon' ) && site_is_coming_soon() ) || (bool) get_option( 'wpcom_public_coming_soon' ), - 'is_offline_mode' => $status->is_offline_mode(), + 'enable_upgrade_nudge' => apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false ), + 'is_private_site' => '-1' === get_option( 'blog_public' ), + 'is_coming_soon' => ( function_exists( 'site_is_coming_soon' ) && site_is_coming_soon() ) || (bool) get_option( 'wpcom_public_coming_soon' ), + 'is_offline_mode' => $status->is_offline_mode(), /** * Enable the RePublicize UI in the block editor context. * @@ -701,7 +701,15 @@ public static function enqueue_block_editor_assets() { * * @param bool true Enable the RePublicize UI in the block editor context. Defaults to true. */ - 'republicize_enabled' => apply_filters( 'jetpack_block_editor_republicize_feature', true ), + 'republicize_enabled' => apply_filters( 'jetpack_block_editor_republicize_feature', true ), + /** + * Enable the Paid Newsletters feature in the block editor context. + * + * @since $$next_version$$ + * + * @param bool false Enable the Paid Newsletters feature in the block editor context. Defaults to false. + */ + 'is_newsletter_feature_enabled' => apply_filters( 'jetpack_subscriptions_newsletter_feature_enabled', false ), ), 'siteFragment' => $status->get_site_suffix(), 'adminUrl' => esc_url( admin_url() ), diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/utils.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/utils.js index d6793a2dda9f5..22ecdb63b0729 100644 --- a/projects/plugins/jetpack/extensions/blocks/subscriptions/utils.js +++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/utils.js @@ -1,3 +1,4 @@ +import { getJetpackData } from '@automattic/jetpack-shared-extension-utils'; import { Button, ToolbarButton } from '@wordpress/components'; import { _x, __ } from '@wordpress/i18n'; @@ -26,9 +27,7 @@ export const getPaidPlanLink = hasNewsletterPlans => { }; export const isNewsletterFeatureEnabled = () => { - return !! window?.Jetpack_Editor_Initial_State?.available_blocks[ - 'paid-newsletters-in-subscriptions' // We probably want to introduce a new "extension" instead of reusing this one. - ]; + return getJetpackData()?.jetpack?.is_newsletter_feature_enabled ?? false; }; export default function GetAddPaidPlanButton( { context = 'other', hasNewsletterPlans } ) { diff --git a/projects/plugins/jetpack/extensions/index.json b/projects/plugins/jetpack/extensions/index.json index 5222219f50b57..1f88a00ec913e 100644 --- a/projects/plugins/jetpack/extensions/index.json +++ b/projects/plugins/jetpack/extensions/index.json @@ -50,7 +50,6 @@ "amazon", "google-docs-embed", "launchpad-save-modal", - "paid-newsletters-in-subscriptions", "post-publish-promote-post-panel", "recipe", "videopress/video",