From e447276d086416961f0ad7535edc71a61adc2272 Mon Sep 17 00:00:00 2001
From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com>
Date: Tue, 8 Oct 2024 09:56:51 -0600
Subject: [PATCH] Add/jetpack blocks add connection nudge where missing
(#39647)
* changelog
* Add connection nudges to all payment blocks
* Check for current user connection instead of connected owner
---
...k-blocks-add-connection-nudge-where-missing | 4 ++++
.../extensions/blocks/donations/edit.js | 11 ++++++++++-
.../extensions/blocks/payment-buttons/edit.js | 18 ++++++++++++++++++
.../blocks/payment-buttons/payment-buttons.php | 7 +------
.../extensions/blocks/payments-intro/edit.js | 15 ++++++++++++++-
.../jetpack/extensions/blocks/paywall/edit.js | 16 ++++++++++++++++
.../extensions/blocks/premium-content/edit.js | 17 ++++++++++++++++-
.../memberships/class-jetpack-memberships.php | 7 ++-----
8 files changed, 81 insertions(+), 14 deletions(-)
create mode 100644 projects/plugins/jetpack/changelog/add-jetpack-blocks-add-connection-nudge-where-missing
diff --git a/projects/plugins/jetpack/changelog/add-jetpack-blocks-add-connection-nudge-where-missing b/projects/plugins/jetpack/changelog/add-jetpack-blocks-add-connection-nudge-where-missing
new file mode 100644
index 0000000000000..35fd26f8a588e
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/add-jetpack-blocks-add-connection-nudge-where-missing
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Add connection nudge for blocks that are missing it
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/edit.js b/projects/plugins/jetpack/extensions/blocks/donations/edit.js
index 4339c7f902121..c4bd4b1c24598 100644
--- a/projects/plugins/jetpack/extensions/blocks/donations/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/donations/edit.js
@@ -1,8 +1,10 @@
import { Spinner } from '@automattic/jetpack-components';
+import { useConnection } from '@automattic/jetpack-connection';
import { useBlockProps } from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
+import ConnectBanner from '../../shared/components/connect-banner';
import { StripeNudge } from '../../shared/components/stripe-nudge';
import { SUPPORTED_CURRENCIES } from '../../shared/currencies';
import getConnectUrl from '../../shared/get-connect-url';
@@ -20,6 +22,7 @@ const Edit = props => {
const blockProps = useBlockProps();
const [ loadingError, setLoadingError ] = useState( '' );
const [ products, setProducts ] = useState( [] );
+ const { isUserConnected } = useConnection();
const { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );
const post = useSelect( select => select( 'core/editor' ).getCurrentPost(), [] );
@@ -134,7 +137,13 @@ const Edit = props => {
let content;
- if ( loadingError ) {
+ if ( ! isUserConnected ) {
+ content = (
+
+ );
+ } else if ( loadingError ) {
content = ;
} else if ( stripeConnectUrl ) {
// Need to connect Stripe first
diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/edit.js b/projects/plugins/jetpack/extensions/blocks/payment-buttons/edit.js
index e2c1a9cdf66ed..8fafcde092f69 100644
--- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/edit.js
@@ -1,8 +1,11 @@
+import { useConnection } from '@automattic/jetpack-connection';
import { BlockControls, useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
+import { __ } from '@wordpress/i18n';
import clsx from 'clsx';
+import ConnectBanner from '../../shared/components/connect-banner';
import StripeConnectToolbarButton from '../../shared/components/stripe-connect-toolbar-button';
import { StripeNudge } from '../../shared/components/stripe-nudge';
import { store as membershipProductsStore } from '../../store/membership-products';
@@ -11,6 +14,7 @@ const ALLOWED_BLOCKS = [ 'jetpack/recurring-payments' ];
function PaymentButtonsEdit( { clientId, attributes } ) {
const { layout, fontSize } = attributes;
+ const { isUserConnected } = useConnection();
const { connectUrl, isApiConnected } = useSelect( select => {
const { getConnectUrl, isApiStateConnected } = select( membershipProductsStore );
return {
@@ -71,6 +75,20 @@ function PaymentButtonsEdit( { clientId, attributes } ) {
// will then be positioned in relation to this.
delete innerBlocksProps.id;
delete innerBlocksProps[ 'data-block' ];
+
+ if ( ! isUserConnected ) {
+ return (
+
+
+
+ );
+ }
+
return (
{ showStripeConnectAction && (
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 ce91746b8e13d..c21c1681c5e69 100644
--- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php
+++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php
@@ -17,13 +17,8 @@
* registration if we need to.
*/
function register_block() {
- if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! \Jetpack::is_connection_ready() ) {
- return;
- }
-
require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
- if ( \Jetpack_Memberships::is_enabled_jetpack_recurring_payments() &&
- \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
+ if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
Blocks::jetpack_register_block(
__DIR__,
array(
diff --git a/projects/plugins/jetpack/extensions/blocks/payments-intro/edit.js b/projects/plugins/jetpack/extensions/blocks/payments-intro/edit.js
index d3d6cab72bc05..2c8e3aed82afc 100644
--- a/projects/plugins/jetpack/extensions/blocks/payments-intro/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/payments-intro/edit.js
@@ -1,3 +1,4 @@
+import { useConnection } from '@automattic/jetpack-connection';
import { InnerBlocks, store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';
import { cloneBlock, createBlock, getBlockType, registerBlockVariation } from '@wordpress/blocks';
import { Placeholder } from '@wordpress/components';
@@ -5,6 +6,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { get } from 'lodash';
+import ConnectBanner from '../../shared/components/connect-banner';
import PaymentsIntroBlockPicker from './block-picker';
import PaymentsIntroPatternPicker from './pattern-picker';
import defaultVariations from './variations';
@@ -24,6 +26,8 @@ export default function JetpackPaymentsIntroEdit( { name, clientId } ) {
};
} );
+ const { isUserConnected } = useConnection();
+
const { replaceBlock, selectBlock, updateSettings } = useDispatch( blockEditorStore );
const maybeMakeBlockVisible = useCallback(
@@ -67,7 +71,16 @@ export default function JetpackPaymentsIntroEdit( { name, clientId } ) {
let content;
- if ( ! hasInnerBlocks && displayVariations ) {
+ if ( ! isUserConnected ) {
+ content = (
+
+ );
+ } else if ( ! hasInnerBlocks && displayVariations ) {
content = (
select( editorStore ).getCurrentPostType(), [] );
const accessLevel = useAccessLevel( postType );
+ const { isUserConnected } = useConnection();
const { stripeConnectUrl, hasTierPlans } = useSelect( select => {
const { getNewsletterTierProducts, getConnectUrl } = select( 'jetpack/membership-products' );
@@ -43,6 +46,19 @@ function PaywallEdit() {
setAccess( value );
}
+ if ( ! isUserConnected ) {
+ return (
+
+
+
+ );
+ }
+
const getText = key => {
switch ( key ) {
case accessOptions.subscribers.key:
diff --git a/projects/plugins/jetpack/extensions/blocks/premium-content/edit.js b/projects/plugins/jetpack/extensions/blocks/premium-content/edit.js
index 392a25706df91..f8a38e134caf4 100644
--- a/projects/plugins/jetpack/extensions/blocks/premium-content/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/premium-content/edit.js
@@ -1,9 +1,11 @@
+import { useConnection } from '@automattic/jetpack-connection';
import { store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';
import { Disabled, Placeholder, Spinner } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { select, useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
+import ConnectBanner from '../../shared/components/connect-banner';
import ProductManagementControls from '../../shared/components/product-management-controls';
import { PRODUCT_TYPE_SUBSCRIPTION } from '../../shared/components/product-management-controls/constants';
import { StripeNudge } from '../../shared/components/stripe-nudge';
@@ -12,7 +14,6 @@ import Blocks from './_inc/blocks';
import Context from './_inc/context';
import './editor.scss';
import ViewSelector from './_inc/view-selector';
-
/**
* Tab definitions
*
@@ -61,6 +62,7 @@ function Edit( { clientId, isSelected, attributes, setAttributes } ) {
const [ selectedTab, selectTab ] = useState( tabs[ WALL_TAB ] );
const blockProps = useBlockProps();
+ const { isUserConnected } = useConnection();
const setSelectedProductIds = productIds => setAttributes( { selectedPlanIds: productIds } );
@@ -100,6 +102,19 @@ function Edit( { clientId, isSelected, attributes, setAttributes } ) {
const isSmallViewport = useViewportMatch( 'medium', '<' );
+ if ( ! isUserConnected ) {
+ return (
+
+
+
+ );
+ }
+
return (
{ ! isPreview && (
diff --git a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php
index 214ac57f15bc6..3c07b2642153b 100644
--- a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php
+++ b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php
@@ -7,7 +7,6 @@
*/
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;
@@ -751,7 +750,7 @@ public static function is_enabled_jetpack_recurring_payments() {
/**
* 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
+ * All Monetize blocks (except Simple Payments) need a user with at least `edit_posts` capability
*
* @return bool
*/
@@ -762,10 +761,8 @@ public static function should_enable_monetize_blocks_in_editor() {
}
- $manager = new Connection_Manager( 'jetpack' );
- $jetpack_ready_and_connected = $manager->is_connected() && $manager->has_connected_owner();
$is_offline_mode = ( new Status() )->is_offline_mode();
- $enable_monetize_blocks_in_editor = ( new Host() )->is_wpcom_simple() || ( $jetpack_ready_and_connected && ! $is_offline_mode );
+ $enable_monetize_blocks_in_editor = ( new Host() )->is_wpcom_simple() || ( ! $is_offline_mode );
return $enable_monetize_blocks_in_editor;
}