PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | extensions/blocks/subscriptions/subscriptions.php +209 -105 13.5.2 → 16.3-a.7 View file →
@@ -7,18 +7,21 @@
7 7
8 8 namespace Automattic\Jetpack\Extensions\Subscriptions;
9 9
10 10 use Automattic\Jetpack\Blocks;
11 -use Automattic\Jetpack\Connection\Manager as Connection_Manager;
12 11 use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service;
13 12 use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service;
14 -use Automattic\Jetpack\Status;
13 +use Automattic\Jetpack\Modules;
15 14 use Automattic\Jetpack\Status\Host;
16 -use Jetpack;
15 +use Automattic\Jetpack\Status\Request;
17 16 use Jetpack_Gutenberg;
18 17 use Jetpack_Memberships;
19 18 use Jetpack_Subscriptions_Widget;
20 19
20 +if ( ! defined( 'ABSPATH' ) ) {
21 + exit( 0 );
22 +}
23 +
21 24 require_once __DIR__ . '/class-jetpack-subscription-site.php';
22 25 require_once __DIR__ . '/constants.php';
23 26 require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
24 27
@@ -29,8 +32,9 @@
29 32 const DEFAULT_BORDER_WEIGHT_VALUE = 1;
30 33 const DEFAULT_FONTSIZE_VALUE = '16px';
31 34 const DEFAULT_PADDING_VALUE = 15;
32 35 const DEFAULT_SPACING_VALUE = 10;
36 +const DEFAULT_BUTTON_WIDTH = 'auto';
33 37
34 38 /**
35 39 * Registers the block for use in Gutenberg
36 40 * This is done via an action so that we can disable
@@ -44,17 +48,24 @@
44 48 \WPForTeams\is_wpforteams_site( get_current_blog_id() ) ) {
45 49 return;
46 50 }
47 51
48 - if (
49 - ( defined( 'IS_WPCOM' ) && IS_WPCOM )
50 - || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() )
51 - ) {
52 + /*
53 + * Do not proceed if the newsletter feature (Subscriptions module) is not enabled
54 + */
55 + if ( ! ( new Modules() )->is_active( 'subscriptions' ) ) {
56 + return;
57 + }
58 +
59 + require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
60 +
61 + if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
52 62 Blocks::jetpack_register_block(
53 63 __DIR__,
54 64 array(
55 - 'render_callback' => __NAMESPACE__ . '\render_block',
56 - 'supports' => array(
65 + 'render_callback' => __NAMESPACE__ . '\render_block',
66 + 'render_email_callback' => __NAMESPACE__ . '\render_email',
67 + 'supports' => array(
57 68 'spacing' => array(
58 69 'margin' => true,
59 70 'padding' => true,
60 71 ),
@@ -63,42 +74,37 @@
63 74 )
64 75 );
65 76 }
66 77
67 - /*
68 - * If the Subscriptions module is not active,
69 - * do not make any further changes on the site.
70 - */
71 - if ( ! Jetpack::is_module_active( 'subscriptions' ) ) {
72 - return;
73 - }
74 -
75 - /**
76 - * Do not proceed if the newsletter feature is not enabled
77 - * or if the 'Jetpack_Memberships' class does not exists.
78 - */
79 - if ( ! class_exists( '\Jetpack_Memberships' ) ) {
80 - return;
81 - }
82 -
83 78 register_post_meta(
84 79 'post',
85 80 META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS,
86 81 array(
87 - 'show_in_rest' => true,
88 - 'single' => true,
89 - 'type' => 'string',
90 - 'auth_callback' => function () {
82 + 'show_in_rest' => true,
83 + 'single' => true,
84 + 'type' => 'string',
85 + // The REST schema already rejects non-strings, but non-REST writers
86 + // (importers, XML-RPC, WP-CLI, direct update_post_meta, sync) only pass
87 + // through sanitize_meta(). Coerce anything that isn't a string to ''
88 + // ("everybody") so a corrupt value can't be persisted and later fatal the
89 + // strict string-typed access checks.
90 + 'sanitize_callback' => function ( $value ) {
91 + return is_string( $value ) ? $value : '';
92 + },
93 + 'auth_callback' => function () {
91 94 return wp_get_current_user()->has_cap( 'edit_posts' );
92 95 },
93 96 )
94 97 );
95 98
99 + // The meta is a "don't send" flag, so invert the blog option (which defaults to true = "send").
100 + $dont_email_default = ! get_option( 'wpcom_newsletter_send_default', true );
101 +
96 102 register_post_meta(
97 103 'post',
98 104 META_NAME_FOR_POST_DONT_EMAIL_TO_SUBS,
99 105 array(
100 - 'default' => false,
106 + 'default' => $dont_email_default,
101 107 'show_in_rest' => true,
102 108 'single' => true,
103 109 'type' => 'boolean',
104 110 'auth_callback' => function () {
@@ -142,8 +148,10 @@
142 148 array(
143 149 META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS,
144 150 META_NAME_FOR_POST_DONT_EMAIL_TO_SUBS,
145 151 META_NAME_CONTAINS_PAYWALLED_CONTENT,
152 + META_NAME_FOR_POST_TIER_ID_SETTINGS,
153 + META_NAME_CONTAINS_PAID_CONTENT,
146 154 )
147 155 );
148 156 }
149 157 );
@@ -157,11 +165,8 @@
157 165
158 166 // Hide existing comments
159 167 add_filter( 'get_comment', __NAMESPACE__ . '\maybe_gate_existing_comments' );
160 168
161 - // Gate the excerpt for a post
162 - add_filter( 'get_the_excerpt', __NAMESPACE__ . '\jetpack_filter_excerpt_for_newsletter', 10, 2 );
163 -
164 169 // Add a 'Newsletter' column to the Edit posts page
165 170 // We only display the "Newsletter" column if we have configured the paid newsletter plan
166 171 if ( defined( 'WP_ADMIN' ) && WP_ADMIN && Jetpack_Memberships::has_configured_plans_jetpack_recurring_payments( 'newsletter' ) ) {
167 172 add_action( 'manage_post_posts_columns', __NAMESPACE__ . '\register_newsletter_access_column' );
@@ -183,9 +188,9 @@
183 188 }
184 189 );
185 190
186 191 // If called via REST API, we need to register later in the lifecycle
187 - if ( ( new Host() )->is_wpcom_platform() && ! jetpack_is_frontend() ) {
192 + if ( ( new Host() )->is_wpcom_platform() && ! Request::is_frontend() ) {
188 193 add_action(
189 194 'restapi_theme_init',
190 195 function () {
191 196 Jetpack_Subscription_Site::init()->handle_subscribe_block_placements();
@@ -235,9 +240,10 @@
235 240 }
236 241
237 242 $access_level = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
238 243
239 - $is_paywalled = false;
244 + // A Paywall block gates the post whatever the stored access level; see Jetpack_Memberships::get_post_access_level().
245 + $is_paywalled = has_block( \Automattic\Jetpack\Extensions\Paywall\BLOCK_NAME, $post );
240 246 switch ( $access_level ) {
241 247 case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS_ALL_TIERS:
242 248 case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS:
243 249 case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_SUBSCRIBERS:
@@ -261,9 +267,9 @@
261 267 if ( NEWSLETTER_COLUMN_ID !== $column_id ) {
262 268 return;
263 269 }
264 270
265 - $access_level = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
271 + $access_level = Jetpack_Memberships::get_post_access_level( $post_id );
266 272
267 273 switch ( $access_level ) {
268 274 case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS_ALL_TIERS:
269 275 echo esc_html__( 'Paid Subscribers (all plans)', 'jetpack' );
@@ -289,11 +295,11 @@
289 295 echo '<style id="jetpack-newsletter-newsletter-access-column"> table.fixed .column-newsletter_access { width: 10%; } </style>';
290 296 }
291 297
292 298 /**
293 - * Determine the amount of folks currently subscribed to the blog, splitted out in email_subscribers & social_followers & paid_subscribers
299 + * Determine the amount of folks currently subscribed to the blog, splitted out in total_subscribers, email_subscribers, social_followers & paid_subscribers.
294 300 *
295 - * @return array containing ['value' => ['email_subscribers' => 0, 'paid_subscribers' => 0, 'social_followers' => 0]]
301 + * @return array containing ['value' => ['total_subscribers' => 0, 'email_subscribers' => 0, 'paid_subscribers' => 0, 'social_followers' => 0]]
296 302 */
297 303 function fetch_subscriber_counts() {
298 304 $subs_count = 0;
299 305 if ( is_wpcom() ) {
@@ -311,9 +317,10 @@
311 317 $subs_count = array(
312 318 'status' => 'failed',
313 319 'code' => $xml->getErrorCode(),
314 320 'message' => $xml->getErrorMessage(),
315 - 'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : array(
321 + 'value' => $subs_count['value'] ?? array(
322 + 'total_subscribers' => 0,
316 323 'email_subscribers' => 0,
317 324 'social_followers' => 0,
318 325 'paid_subscribers' => 0,
319 326 ),
@@ -339,11 +346,11 @@
339 346 function get_subscriber_count( $include_social_followers ) {
340 347 $counts = fetch_subscriber_counts();
341 348
342 349 if ( $include_social_followers ) {
343 - $subscriber_count = $counts['value']['email_subscribers'] + $counts['value']['social_followers'];
350 + $subscriber_count = $counts['value']['total_subscribers'] + $counts['value']['social_followers'];
344 351 } else {
345 - $subscriber_count = $counts['value']['email_subscribers'];
352 + $subscriber_count = $counts['value']['total_subscribers'];
346 353 }
347 354 return $subscriber_count;
348 355 }
349 356
@@ -489,15 +496,15 @@
489 496 $submit_button_styles .= sprintf( 'color: %s;', get_attribute( $attributes, 'customTextColor' ) );
490 497 }
491 498
492 499 if ( has_attribute( $attributes, 'buttonWidth' ) ) {
493 - $submit_button_wrapper_styles .= sprintf( 'width: %s;', get_attribute( $attributes, 'buttonWidth' ) );
500 + $submit_button_wrapper_styles .= sprintf( 'width: %s;', get_attribute( $attributes, 'buttonWidth', DEFAULT_BUTTON_WIDTH ) );
494 501 $submit_button_wrapper_styles .= 'max-width: 100%;';
495 502
496 503 // Account for custom margins on inline forms.
497 504 $submit_button_styles .= true === get_attribute( $attributes, 'buttonOnNewLine' )
498 - ? sprintf( 'width: calc(100%% - %dpx);', get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE ) )
499 - : 'width: 100%;';
505 + ? 'width: 100%;'
506 + : sprintf( 'width: calc(100%% - %dpx);', get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE ) );
500 507 }
501 508
502 509 $font_size = get_attribute( $attributes, 'customFontSize', DEFAULT_FONTSIZE_VALUE );
503 510 $style = sprintf( 'font-size: %s%s;', $font_size, is_numeric( $font_size ) ? 'px' : '' );
@@ -510,9 +517,8 @@
510 517
511 518 $submit_button_styles .= $style;
512 519 $email_field_styles .= $style;
513 520
514 - $button_spacing = get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE );
515 521 if ( ! $is_button_only_style ) {
516 522 $button_spacing = get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE );
517 523 if ( true === get_attribute( $attributes, 'buttonOnNewLine' ) ) {
518 524 $submit_button_styles .= sprintf( 'margin-top: %dpx;', $button_spacing );
@@ -542,9 +548,9 @@
542 548 $submit_button_styles .= $style;
543 549 $email_field_styles .= $style;
544 550 }
545 551
546 - if ( ! jetpack_is_frontend() ) {
552 + if ( ! Request::is_frontend() ) {
547 553 $background_color_style = get_attribute_color( 'buttonBackgroundColor', $attributes, '#113AF5' /* default lettre theme color */ );
548 554 $text_color_style = get_attribute_color( 'textColor', $attributes, '#FFFFFF' );
549 555 $submit_button_styles .= sprintf( ' background-color: %s; color: %s;', $background_color_style, $text_color_style );
550 556 }
@@ -629,8 +635,15 @@
629 635 return null;
630 636 }
631 637
632 638 /**
639 + * Is the Jetpack_Memberships class loaded.
640 + */
641 +function is_jetpack_memberships_loaded(): bool {
642 + return class_exists( '\Jetpack_Memberships' );
643 +}
644 +
645 +/**
633 646 * Subscriptions block render callback.
634 647 *
635 648 * @param array $attributes Array containing the block attributes.
636 649 *
@@ -637,13 +650,13 @@
637 650 * @return string
638 651 */
639 652 function render_block( $attributes ) {
640 653 // If the Subscriptions module is not active, don't render the block.
641 - if ( ! Jetpack::is_module_active( 'subscriptions' ) ) {
654 + if ( ! ( new Modules() )->is_active( 'subscriptions' ) ) {
642 655 return '';
643 656 }
644 657
645 - if ( class_exists( '\Jetpack_Memberships' ) ) {
658 + if ( is_jetpack_memberships_loaded() ) {
646 659 // We only want the sites that have newsletter feature enabled to be graced by this JavaScript.
647 660 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
648 661 } else {
649 662 Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME );
@@ -648,12 +661,17 @@
648 661 } else {
649 662 Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME );
650 663 }
651 664
665 + if ( ! class_exists( 'Jetpack_Subscriptions_Widget' ) ) {
666 + return '';
667 + }
668 +
669 + // Prefill the email field with the current user's email if they are logged in via Memberships premium content token
652 670 $subscribe_email = Jetpack_Memberships::get_current_user_email();
653 671
654 - /** This filter is documented in \Automattic\Jetpack\Forms\ContactForm\Contact_Form */
655 - if ( is_wpcom() || false !== apply_filters( 'jetpack_auto_fill_logged_in_user', false ) ) {
672 + // If no email, then prefill the email field with the current user's email if they are logged in
673 + if ( empty( $subscribe_email ) ) {
656 674 $current_user = wp_get_current_user();
657 675 if ( ! empty( $current_user->user_email ) ) {
658 676 $subscribe_email = $current_user->user_email;
659 677 }
@@ -672,37 +690,44 @@
672 690 // We want to disencourage including social count as it's misleading.
673 691 $include_social_followers = isset( $attributes['includeSocialFollowers'] ) ? (bool) get_attribute( $attributes, 'includeSocialFollowers' ) : true;
674 692
675 693 $data = array(
676 - 'widget_id' => Jetpack_Subscriptions_Widget::$instance_count,
677 - 'subscribe_email' => $subscribe_email,
678 - 'is_paid_subscriber' => get_attribute( $attributes, 'isPaidSubscriber', false ),
679 - 'wrapper_attributes' => get_block_wrapper_attributes(
694 + 'widget_id' => Jetpack_Subscriptions_Widget::$instance_count,
695 + 'subscribe_email' => $subscribe_email,
696 + 'is_paid_subscriber' => get_attribute( $attributes, 'isPaidSubscriber', false ),
697 + 'wrapper_attributes' => get_block_wrapper_attributes(
680 698 array(
681 699 'class' => $classes['block_wrapper'],
682 700 )
683 701 ),
684 - 'subscribe_placeholder' => get_attribute( $attributes, 'subscribePlaceholder', __( 'Type your email…', 'jetpack' ) ),
685 - 'submit_button_text' => get_attribute( $attributes, 'submitButtonText', __( 'Subscribe', 'jetpack' ) ),
686 - 'submit_button_text_subscribed' => get_attribute( $attributes, 'submitButtonTextSubscribed', __( 'Subscribed', 'jetpack' ) ),
687 - 'submit_button_text_upgrade' => get_attribute( $attributes, 'submitButtonTextUpgrade', __( 'Upgrade subscription', 'jetpack' ) ),
688 - 'success_message' => get_attribute(
702 + 'subscribe_placeholder' => get_attribute( $attributes, 'subscribePlaceholder', __( 'Type your email…', 'jetpack' ) ),
703 + 'submit_button_text' => get_attribute( $attributes, 'submitButtonText', __( 'Subscribe', 'jetpack' ) ),
704 + 'submit_button_text_subscribed' => get_attribute( $attributes, 'submitButtonTextSubscribed', __( 'Subscribed', 'jetpack' ) ),
705 + 'submit_button_text_upgrade' => get_attribute( $attributes, 'submitButtonTextUpgrade', __( 'Upgrade subscription', 'jetpack' ) ),
706 + 'success_message' => get_attribute(
689 707 $attributes,
690 708 'successMessage',
691 709 esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm' to start subscribing.", 'jetpack' )
692 710 ),
693 - 'show_subscribers_total' => (bool) get_attribute( $attributes, 'showSubscribersTotal' ),
694 - 'subscribers_total' => get_subscriber_count( $include_social_followers ),
695 - 'referer' => esc_url_raw(
711 + 'show_subscribers_total' => (bool) get_attribute( $attributes, 'showSubscribersTotal' ),
712 + 'subscribers_total' => get_attribute( $attributes, 'showSubscribersTotal' ) ? get_subscriber_count( $include_social_followers ) : 0,
713 + 'referer' => esc_url_raw(
696 714 ( is_ssl() ? 'https' : 'http' ) . '://' . ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : '' ) .
697 715 ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' )
698 716 ),
699 - 'source' => 'subscribe-block',
700 - 'app_source' => get_attribute( $attributes, 'appSource', null ),
701 - 'class_name' => get_attribute( $attributes, 'className' ),
717 + 'source' => 'subscribe-block',
718 + 'app_source' => get_attribute( $attributes, 'appSource', null ),
719 + 'class_name' => get_attribute( $attributes, 'className' ),
720 + 'selected_newsletter_categories' => get_attribute( $attributes, 'selectedNewsletterCategoryIds', array() ),
721 + 'preselected_newsletter_categories' => get_attribute( $attributes, 'preselectNewsletterCategories', false ),
702 722 );
703 723
704 - if ( ! jetpack_is_frontend() ) {
724 + // Only render the email version in non-frontend contexts.
725 + if ( is_feed() || wp_is_xml_request() ||
726 + ( defined( 'REST_REQUEST' ) && REST_REQUEST && ! wp_is_json_request() ) ||
727 + ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
728 + ( defined( 'WP_CLI' ) && WP_CLI ) ||
729 + wp_is_jsonp_request() ) {
705 730 return render_for_email( $data, $styles );
706 731 }
707 732
708 733 return render_for_website( $data, $classes, $styles );
@@ -772,9 +797,9 @@
772 797 style="<?php echo esc_attr( $styles['submit_button_wrapper'] ); ?>"
773 798 <?php endif; ?>
774 799 >
775 800 <a
776 - href="<?php echo esc_url( 'https://wordpress.com/read/site/subscription/' . $blog_id ); ?>"
801 + href="<?php echo esc_url( 'https://wordpress.com/reader/site/subscription/' . $blog_id ); ?>"
777 802 <?php if ( ! empty( $classes['submit_button'] ) ) : ?>
778 803 class="<?php echo esc_attr( $classes['submit_button'] ); ?>"
779 804 <?php endif; ?>
780 805 <?php if ( ! empty( $styles['submit_button'] ) ) : ?>
@@ -809,8 +834,9 @@
809 834 '<input
810 835 required="required"
811 836 type="email"
812 837 name="email"
838 + autocomplete="email"
813 839 %1$s
814 840 style="%2$s"
815 841 placeholder="%3$s"
816 842 value="%4$s"
@@ -857,8 +883,12 @@
857 883
858 884 if ( ! empty( $tier_id ) ) {
859 885 echo '<input type="hidden" name="tier_id" value="' . esc_attr( $tier_id ) . '"/>';
860 886 }
887 +
888 + if ( $data['preselected_newsletter_categories'] && ! empty( $data['selected_newsletter_categories'] ) ) {
889 + echo '<input type="hidden" name="selected_newsletter_categories" value="' . esc_attr( implode( ',', $data['selected_newsletter_categories'] ) ) . '"/>';
890 + }
861 891 ?>
862 892 <button type="submit"
863 893 <?php if ( ! empty( $classes['submit_button'] ) ) : ?>
864 894 class="<?php echo esc_attr( $classes['submit_button'] ); ?>"
@@ -912,26 +942,56 @@
912 942 return $html;
913 943 }
914 944
915 945 /**
916 - * Filter excerpts looking for subscription data.
946 + * WooCommerce Email Editor render callback for the subscriptions block.
917 947 *
918 - * @param string $excerpt The extrapolated excerpt string.
919 - * @param \WP_Post $post The current post being processed (in `get_the_excerpt`).
948 + * @param string $block_content The block content.
949 + * @param array $parsed_block The parsed block data.
950 + * @param object $rendering_context The email rendering context.
920 951 *
921 - * @return mixed
952 + * @return string
922 953 */
923 -function jetpack_filter_excerpt_for_newsletter( $excerpt, $post = null ) {
924 - // The blogmagazine theme is overriding WP core `get_the_excerpt` filter and only passing the excerpt
925 - // TODO: Until this is fixed, return the excerpt without gating. See https://github.com/Automattic/jetpack/pull/28102#issuecomment-1369161116
926 - if ( $post && str_contains( $post->post_content, '<!-- wp:jetpack/subscriptions -->' ) ) {
927 - $excerpt .= sprintf(
928 - // translators: %s is the permalink url to the current post.
929 - __( "<p><a href='%s'>View post</a> to subscribe to site newsletter.</p>", 'jetpack' ),
930 - get_post_permalink()
931 - );
954 +function render_email( $block_content, array $parsed_block, $rendering_context ) {
955 + if ( ! isset( $parsed_block['attrs'] ) || ! is_array( $parsed_block['attrs'] ) || ! function_exists( '\Automattic\Jetpack\Extensions\Button\render_email' ) || ! class_exists( '\Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks\Button' ) ) {
956 + return '';
932 957 }
933 - return $excerpt;
958 +
959 + // Map subscription block attributes to button block attributes
960 + $button_attributes = array(
961 + 'text' => ! empty( $parsed_block['attrs']['submitButtonText'] ) ? sanitize_text_field( $parsed_block['attrs']['submitButtonText'] ) : __( 'Subscribe', 'jetpack' ),
962 + 'url' => get_post_permalink(),
963 + 'element' => 'a',
964 + // Map background colors
965 + 'backgroundColor' => $parsed_block['attrs']['buttonBackgroundColor'] ?? null,
966 + 'customBackgroundColor' => $parsed_block['attrs']['customButtonBackgroundColor'] ?? null,
967 + // Map text colors
968 + 'textColor' => $parsed_block['attrs']['textColor'] ?? null,
969 + 'customTextColor' => $parsed_block['attrs']['customTextColor'] ?? null,
970 + // Map borders
971 + 'borderRadius' => $parsed_block['attrs']['borderRadius'] ?? 0,
972 + 'borderWeight' => $parsed_block['attrs']['borderWeight'] ?? 1,
973 + 'borderColor' => $parsed_block['attrs']['borderColor'] ?? null,
974 + 'customBorderColor' => $parsed_block['attrs']['customBorderColor'] ?? null,
975 + // Map typography
976 + 'fontSize' => $parsed_block['attrs']['fontSize'] ?? null,
977 + 'customFontSize' => $parsed_block['attrs']['customFontSize'] ?? null,
978 + // Map spacing
979 + 'padding' => $parsed_block['attrs']['padding'] ?? null,
980 + );
981 +
982 + // Create a mock button block structure
983 + $button_parsed_block = array(
984 + 'attrs' => $button_attributes,
985 + 'email_attrs' => $parsed_block['email_attrs'] ?? array(),
986 + );
987 +
988 + // Call the Jetpack button's email rendering
989 + return \Automattic\Jetpack\Extensions\Button\render_email(
990 + $block_content,
991 + $button_parsed_block,
992 + $rendering_context
993 + );
934 994 }
935 995
936 996 /**
937 997 * Gate access to posts
@@ -956,9 +1016,9 @@
956 1016 }
957 1017 return $the_content;
958 1018 }
959 1019
960 - $paywalled_content = get_paywall_content( $post_access_level ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1020 + $paywalled_content = get_paywall_content();
961 1021
962 1022 if ( has_block( \Automattic\Jetpack\Extensions\Paywall\BLOCK_NAME ) ) {
963 1023 if ( strpos( $the_content, \Automattic\Jetpack\Extensions\Paywall\BLOCK_HTML ) ) {
964 1024 return strstr( $the_content, \Automattic\Jetpack\Extensions\Paywall\BLOCK_HTML, true ) . $paywalled_content;
@@ -1037,12 +1097,11 @@
1037 1097
1038 1098 /**
1039 1099 * Returns paywall content blocks
1040 1100 *
1041 - * @param string $post_access_level The newsletter access level.
1042 1101 * @return string
1043 1102 */
1044 -function get_paywall_content( $post_access_level ) {
1103 +function get_paywall_content() {
1045 1104 if ( Jetpack_Memberships::user_is_pending_subscriber() ) {
1046 1105 return get_paywall_blocks_subscribe_pending();
1047 1106 }
1048 1107 if ( doing_filter( 'get_the_excerpt' ) ) {
@@ -1047,9 +1106,9 @@
1047 1106 }
1048 1107 if ( doing_filter( 'get_the_excerpt' ) ) {
1049 1108 return '';
1050 1109 }
1051 - return get_paywall_blocks( $post_access_level );
1110 + return get_paywall_blocks();
1052 1111 }
1053 1112
1054 1113 /**
1055 1114 * Returns the current URL.
@@ -1131,22 +1190,22 @@
1131 1190
1132 1191 /**
1133 1192 * Returns paywall content blocks if user is not authenticated
1134 1193 *
1135 - * @param string $newsletter_access_level The newsletter access level.
1136 1194 * @return string
1137 1195 */
1138 -function get_paywall_blocks( $newsletter_access_level ) {
1196 +function get_paywall_blocks() {
1139 1197 $custom_paywall = apply_filters( 'jetpack_custom_paywall_blocks', false );
1140 1198 if ( ! empty( $custom_paywall ) ) {
1141 1199 return $custom_paywall;
1142 1200 }
1143 - if ( ! jetpack_is_frontend() ) { // emails
1201 +
1202 + if ( ! Request::is_frontend() ) { // emails
1144 1203 return get_paywall_simple();
1145 1204 }
1205 +
1146 1206 require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
1147 - // Only display paid texts when Stripe is connected and the post is marked for paid subscribers
1148 - $is_paid_post = $newsletter_access_level === 'paid_subscribers' && Jetpack_Memberships::has_connected_account();
1207 + $is_paid_post = is_paid_post();
1149 1208 $is_paid_subscriber = Jetpack_Memberships::user_is_paid_subscriber();
1150 1209
1151 1210 $access_heading = $is_paid_subscriber
1152 1211 ? esc_html__( 'Upgrade to continue reading', 'jetpack' )
@@ -1153,11 +1212,13 @@
1153 1212 : esc_html__( 'Subscribe to continue reading', 'jetpack' );
1154 1213
1155 1214 $subscribe_text = $is_paid_post
1156 1215 // translators: %s is the name of the site.
1157 - ? $is_paid_subscriber
1158 - ? esc_html__( 'Upgrade to get access to the rest of this post and other exclusive content.', 'jetpack' )
1159 - : esc_html__( 'Become a paid subscriber to get access to the rest of this post and other exclusive content.', 'jetpack' )
1216 + ? (
1217 + $is_paid_subscriber
1218 + ? esc_html__( 'Upgrade to get access to the rest of this post and other exclusive content.', 'jetpack' )
1219 + : esc_html__( 'Become a paid subscriber to get access to the rest of this post and other exclusive content.', 'jetpack' )
1220 + )
1160 1221 // translators: %s is the name of the site.
1161 1222 : esc_html__( 'Subscribe to get access to the rest of this post and other subscriber-only content.', 'jetpack' );
1162 1223
1163 1224 $login_block = '';
@@ -1233,8 +1294,36 @@
1233 1294 return false;
1234 1295 }
1235 1296
1236 1297 /**
1298 + * Returns `true` if the post is a paid post.
1299 + */
1300 +function is_paid_post(): bool {
1301 + require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
1302 +
1303 + // Make sure Stripe is connected and the post is marked for paid subscribers.
1304 + if ( Jetpack_Memberships::has_connected_account() && is_jetpack_token_subscription_service_loaded() ) {
1305 + return Jetpack_Memberships::get_post_access_level() === Jetpack_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS;
1306 + }
1307 +
1308 + return false;
1309 +}
1310 +
1311 +/**
1312 + * Returns true if the post is a subscribers post.
1313 + */
1314 +function is_subscribers_post(): bool {
1315 + require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
1316 +
1317 + // Make sure Stripe is connected and the post is marked for paid subscribers.
1318 + if ( Jetpack_Memberships::has_connected_account() && is_jetpack_token_subscription_service_loaded() ) {
1319 + return Jetpack_Memberships::get_post_access_level() === Jetpack_Token_Subscription_Service::POST_ACCESS_LEVEL_SUBSCRIBERS;
1320 + }
1321 +
1322 + return false;
1323 +}
1324 +
1325 +/**
1237 1326 * Returns paywall content blocks when email confirmation is pending
1238 1327 *
1239 1328 * @return string
1240 1329 */
@@ -1275,22 +1364,37 @@
1275 1364 ';
1276 1365 }
1277 1366
1278 1367 /**
1279 - * Return content for non frontend views like emails.
1280 - *
1281 - * @return string
1368 + * Return content for non frontend views like Reader, emails.
1282 1369 */
1283 -function get_paywall_simple() {
1284 - $access_heading = esc_html__( "You're currently a free subscriber. Upgrade your subscription to get access to the rest of this post and other paid-subscriber only content.", 'jetpack' );
1370 +function get_paywall_simple(): string {
1371 + $is_paid_post = is_paid_post();
1372 + $is_subscribers_post = is_subscribers_post();
1373 + $is_subscriber = is_jetpack_memberships_loaded() && Jetpack_Memberships::is_current_user_subscribed();
1374 + $paywall_heading = esc_html__( 'Subscribe to keep reading', 'jetpack' );
1285 1375
1286 - $subscribe_text = esc_html__( 'Upgrade subscription', 'jetpack' );
1376 + if ( $is_subscribers_post && ! $is_subscriber ) {
1377 + $paywall_description = esc_html__( "It's a subscribers only post. Subscribe to get access to the rest of this post and other subscriber-only content.", 'jetpack' );
1378 + $paywall_action_btn = esc_html__( 'Subscribe', 'jetpack' );
1379 + } elseif ( $is_paid_post && $is_subscriber ) {
1380 + $paywall_description = esc_html__( "You're currently a free subscriber. Upgrade your subscription to get access to the rest of this post and other paid-subscriber only content.", 'jetpack' );
1381 + $paywall_action_btn = esc_html__( 'Upgrade subscription', 'jetpack' );
1382 + } else {
1383 + // - For paid post when the user is not a subscriber.
1384 + // - Default for all other cases.
1385 + $paywall_description = esc_html__( 'Become a paid subscriber to get access to the rest of this post and other exclusive content.', 'jetpack' );
1386 + $paywall_action_btn = esc_html__( 'Subscribe', 'jetpack' );
1387 + }
1287 1388
1288 1389 return '
1289 1390 <!-- wp:columns -->
1290 -<div class="wp-block-columns" style="display: inline-block; width: 90%">
1391 +<div class="wp-block-columns jetpack-paywall-simple" style="display: inline-block; width: 90%">
1291 1392 <!-- wp:column -->
1292 1393 <div class="wp-block-column" style="background-color: #F6F7F7; padding: 32px; 24px;">
1394 + <!-- wp:heading -->
1395 + <h2 class="has-text-align-center" style="margin: 0 0 12px; font-weight: 600;">' . $paywall_heading . '</h2>
1396 + <!-- /wp:heading -->
1293 1397 <!-- wp:paragraph -->
1294 1398 <p class="has-text-align-center"
1295 1399 style="text-align: center;
1296 1400 color: #50575E;
@@ -1297,20 +1401,20 @@
1297 1401 font-weight: 400;
1298 1402 font-size: 16px;
1299 1403 font-family: \'SF Pro Text\', sans-serif;
1300 1404 line-height: 28.8px;">
1301 - ' . $access_heading . '
1405 + ' . $paywall_description . '
1302 1406 </p>
1303 1407 <!-- /wp:paragraph -->
1304 1408 <!-- wp:buttons -->
1305 1409 <div class="wp-block-buttons" style="text-align: center;">
1306 1410 <!-- wp:button -->
1307 - <div class="wp-block-button" style="display: inline-block; margin: 10px 0;">
1411 + <div class="wp-block-button" style="display: inline-block; margin: 10px 0; border-style: none; padding: 0;">
1308 1412 <a href="' . esc_url( get_post_permalink() ) . '" class="wp-block-button__link wp-element-button"
1309 1413 data-wpcom-track data-tracks-link-desc="paywall-email-click"
1310 1414 style="display: inline-block;
1311 - padding: 15px 20px;
1312 - background-color: #0675C4;
1415 + padding: 12px 15px;
1416 + background-color: #3858e9;
1313 1417 color: #FFFFFF;
1314 1418 text-decoration: none;
1315 1419 border-radius: 5px;
1316 1420 font-family: \'SF Pro Display\', sans-serif;
@@ -1315,9 +1419,9 @@
1315 1419 border-radius: 5px;
1316 1420 font-family: \'SF Pro Display\', sans-serif;
1317 1421 font-weight: 500;
1318 1422 font-size: 16px;
1319 - text-align: center;">' . $subscribe_text . '</a>
1423 + text-align: center;">' . $paywall_action_btn . '</a>
1320 1424 </div>
1321 1425 <!-- /wp:button -->
1322 1426 </div>
1323 1427 <!-- /wp:buttons -->