diff --git a/projects/plugins/jetpack/changelog/add-shield-memberships-blocks-for-unconnected-jetpack-sites b/projects/plugins/jetpack/changelog/add-shield-memberships-blocks-for-unconnected-jetpack-sites deleted file mode 100644 index 8b74c16792da3..0000000000000 --- a/projects/plugins/jetpack/changelog/add-shield-memberships-blocks-for-unconnected-jetpack-sites +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: bugfix - -Do not register Memberships blocks when the site is not connected to Jetpack diff --git a/projects/plugins/jetpack/extensions/blocks/donations/donations.php b/projects/plugins/jetpack/extensions/blocks/donations/donations.php index 8b5966abe76bd..b59b63f760733 100644 --- a/projects/plugins/jetpack/extensions/blocks/donations/donations.php +++ b/projects/plugins/jetpack/extensions/blocks/donations/donations.php @@ -19,16 +19,12 @@ * registration if we need to. */ function register_block() { - - require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; - if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { - Blocks::jetpack_register_block( - __DIR__, - array( - 'render_callback' => __NAMESPACE__ . '\render_block', - ) - ); - } + Blocks::jetpack_register_block( + __DIR__, + array( + 'render_callback' => __NAMESPACE__ . '\render_block', + ) + ); } add_action( 'init', __NAMESPACE__ . '\register_block' ); diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php index 2f699aac62294..642575b7aec03 100644 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php +++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php @@ -22,7 +22,7 @@ function register_block() { } require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; - if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { + if ( \Jetpack_Memberships::is_enabled_jetpack_recurring_payments() ) { Blocks::jetpack_register_block( __DIR__, array( diff --git a/projects/plugins/jetpack/extensions/blocks/premium-content/premium-content.php b/projects/plugins/jetpack/extensions/blocks/premium-content/premium-content.php index d8449eb44d4b8..484bfa4898a61 100644 --- a/projects/plugins/jetpack/extensions/blocks/premium-content/premium-content.php +++ b/projects/plugins/jetpack/extensions/blocks/premium-content/premium-content.php @@ -25,21 +25,17 @@ * registration if we need to. */ function register_block() { - - require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; - if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { - Blocks::jetpack_register_block( - __DIR__, - array( - 'render_callback' => __NAMESPACE__ . '\render_block', - 'provides_context' => array( - 'premium-content/planId' => 'selectedPlanId', // Deprecated. - 'premium-content/planIds' => 'selectedPlanIds', - 'isPremiumContentChild' => 'isPremiumContentChild', - ), - ) - ); - } + Blocks::jetpack_register_block( + __DIR__, + array( + 'render_callback' => __NAMESPACE__ . '\render_block', + 'provides_context' => array( + 'premium-content/planId' => 'selectedPlanId', // Deprecated. + 'premium-content/planIds' => 'selectedPlanIds', + 'isPremiumContentChild' => 'isPremiumContentChild', + ), + ) + ); register_post_meta( 'post', diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php b/projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php index 6d46ab39ff9a1..710a40eed2cbd 100644 --- a/projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php +++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php @@ -8,8 +8,10 @@ namespace Automattic\Jetpack\Extensions\Subscriptions; use Automattic\Jetpack\Blocks; +use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service; use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service; +use Automattic\Jetpack\Status; use Automattic\Jetpack\Status\Host; use Jetpack; use Jetpack_Gutenberg; @@ -43,9 +45,10 @@ function register_block() { return; } - require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; - if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { - + if ( + ( defined( 'IS_WPCOM' ) && IS_WPCOM ) + || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) + ) { Blocks::jetpack_register_block( __DIR__, array( diff --git a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php index c6fc04b58c971..70e1567f3c036 100644 --- a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php +++ b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php @@ -7,9 +7,7 @@ */ use Automattic\Jetpack\Blocks; -use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service; -use Automattic\Jetpack\Status; use Automattic\Jetpack\Status\Host; use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS; use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_TIER_ID_SETTINGS; @@ -176,7 +174,7 @@ public static function get_instance() { self::$instance->register_init_hook(); // Yes, `pro-plan` with a dash, `jetpack_personal` with an underscore. Check the v1.5 endpoint to verify. $wpcom_plan_slug = defined( 'ENABLE_PRO_PLAN' ) ? 'pro-plan' : 'personal-bundle'; - self::$required_plan = ( new Host() )->is_wpcom_simple() ? $wpcom_plan_slug : 'jetpack_personal'; + self::$required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? $wpcom_plan_slug : 'jetpack_personal'; } return self::$instance; @@ -745,21 +743,7 @@ public static function user_can_view_post( $post_id = null ) { * @return bool */ public static function is_enabled_jetpack_recurring_payments() { - $api_available = ( new Host() )->is_wpcom_simple() || Jetpack::is_connection_ready(); - return $api_available; - } - - /** - * Whether to enable the blocks in the editor. - * All Monetize blocks (except Simple Payments) need an active connecting and a user with at least `edit_posts` capability - * - * @return bool - */ - public static function should_enable_monetize_blocks_in_editor() { - $manager = new Connection_Manager( 'jetpack' ); - $jetpack_ready_and_user_connected = $manager->is_connected() && $manager->is_user_connected(); - $is_offline_mode = ( new Status() )->is_offline_mode(); - $api_available = ( new Host() )->is_wpcom_simple() || ( $jetpack_ready_and_user_connected && ! $is_offline_mode ); + $api_available = ( ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || Jetpack::is_connection_ready() ); return $api_available; }