Skip to content

Commit d4b22e8

Browse files
authored
Subscription Site: Release the Subscribe block after the post placement toggle (#36368)
1 parent f963ca2 commit d4b22e8

File tree

5 files changed

+88
-88
lines changed

5 files changed

+88
-88
lines changed

projects/plugins/jetpack/_inc/client/newsletter/subscriptions-settings.jsx

+24-24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
currentThemeStylesheet,
2020
getSiteAdminUrl,
2121
isSubscriptionSiteEnabled,
22+
subscriptionSiteEditSupported,
2223
} from 'state/initial-state';
2324
import { getModule } from 'state/modules';
2425
import { SUBSCRIPTIONS_MODULE_NAME } from './constants';
@@ -43,7 +44,7 @@ function SubscriptionsSettings( props ) {
4344
isStcEnabled,
4445
isSmEnabled,
4546
isSubscribePostEndEnabled,
46-
isSubscriptionSiteFeatureEnabled,
47+
isSubscriptionSiteEditSupported,
4748
isSubscriptionsActive,
4849
siteRawUrl,
4950
subscriptions,
@@ -150,29 +151,27 @@ function SubscriptionsSettings( props ) {
150151
</ModuleToggle>
151152
{
152153
<FormFieldset>
153-
{ isSubscriptionSiteFeatureEnabled && (
154-
<ToggleControl
155-
checked={ isSubscriptionsActive && isSubscribePostEndEnabled }
156-
disabled={ isDisabled }
157-
toggling={ isSavingAnyOption( [
158-
'jetpack_subscriptions_subscribe_post_end_enabled',
159-
] ) }
160-
onChange={ handleSubscribePostEndToggleChange }
161-
label={
162-
<>
163-
{ __( 'Add the Subscribe Block at the end of each post', 'jetpack' ) }
164-
{ isBlockTheme && singlePostTemplateEditorUrl && (
165-
<>
166-
{ '. ' }
167-
<ExternalLink href={ singlePostTemplateEditorUrl }>
168-
{ __( 'Preview and edit', 'jetpack' ) }
169-
</ExternalLink>
170-
</>
171-
) }
172-
</>
173-
}
174-
/>
175-
) }
154+
<ToggleControl
155+
checked={ isSubscriptionsActive && isSubscribePostEndEnabled }
156+
disabled={ isDisabled }
157+
toggling={ isSavingAnyOption( [
158+
'jetpack_subscriptions_subscribe_post_end_enabled',
159+
] ) }
160+
onChange={ handleSubscribePostEndToggleChange }
161+
label={
162+
<>
163+
{ __( 'Add the Subscribe Block at the end of each post', 'jetpack' ) }
164+
{ isSubscriptionSiteEditSupported && singlePostTemplateEditorUrl && (
165+
<>
166+
{ '. ' }
167+
<ExternalLink href={ singlePostTemplateEditorUrl }>
168+
{ __( 'Preview and edit', 'jetpack' ) }
169+
</ExternalLink>
170+
</>
171+
) }
172+
</>
173+
}
174+
/>
176175
<div className="jp-toggle-set">
177176
<ToggleControl
178177
checked={ isSubscriptionsActive && isSmEnabled }
@@ -259,6 +258,7 @@ export default withModuleSettingsFormHelpers(
259258
'jetpack_subscriptions_subscribe_post_end_enabled'
260259
),
261260
isSubscriptionSiteFeatureEnabled: isSubscriptionSiteEnabled( state ),
261+
isSubscriptionSiteEditSupported: subscriptionSiteEditSupported( state ),
262262
isBlockTheme: currentThemeIsBlockTheme( state ),
263263
siteAdminUrl: getSiteAdminUrl( state ),
264264
themeStylesheet: currentThemeStylesheet( state ),

projects/plugins/jetpack/_inc/client/state/initial-state/reducer.js

+10
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,13 @@ export function getJetpackManageInfo( state ) {
740740
export function isSubscriptionSiteEnabled( state ) {
741741
return !! state.jetpack.initialState.isSubscriptionSiteEnabled;
742742
}
743+
744+
/**
745+
* Returns true if Subscription Site editing feature is supported.
746+
*
747+
* @param {object} state - Global state tree.
748+
* @returns {boolean} True if Subscription Site editing feature is supported.
749+
*/
750+
export function subscriptionSiteEditSupported( state ) {
751+
return !! state.jetpack.initialState.subscriptionSiteEditSupported;
752+
}

projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php

+47-46
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,26 @@ public static function get_initial_state() {
136136
$block_availability = Jetpack_Gutenberg::get_cached_availability();
137137

138138
return array(
139-
'WP_API_root' => esc_url_raw( rest_url() ),
140-
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
141-
'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ),
142-
'purchaseToken' => self::get_purchase_token(),
143-
'partnerCoupon' => Jetpack_Partner_Coupon::get_coupon(),
144-
'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ),
145-
'connectionStatus' => $connection_status,
146-
'connectedPlugins' => Connection_Plugin_Storage::get_all(),
147-
'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
139+
'WP_API_root' => esc_url_raw( rest_url() ),
140+
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
141+
'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ),
142+
'purchaseToken' => self::get_purchase_token(),
143+
'partnerCoupon' => Jetpack_Partner_Coupon::get_coupon(),
144+
'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ),
145+
'connectionStatus' => $connection_status,
146+
'connectedPlugins' => Connection_Plugin_Storage::get_all(),
147+
'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
148148
? Jetpack::init()->build_connect_url( true, false, false )
149149
: '',
150-
'dismissedNotices' => self::get_dismissed_jetpack_notices(),
151-
'isDevVersion' => Jetpack::is_development_version(),
152-
'currentVersion' => JETPACK__VERSION,
153-
'is_gutenberg_available' => true,
154-
'getModules' => $modules,
155-
'rawUrl' => ( new Status() )->get_site_suffix(),
156-
'adminUrl' => esc_url( admin_url() ),
157-
'siteTitle' => (string) htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
158-
'stats' => array(
150+
'dismissedNotices' => self::get_dismissed_jetpack_notices(),
151+
'isDevVersion' => Jetpack::is_development_version(),
152+
'currentVersion' => JETPACK__VERSION,
153+
'is_gutenberg_available' => true,
154+
'getModules' => $modules,
155+
'rawUrl' => ( new Status() )->get_site_suffix(),
156+
'adminUrl' => esc_url( admin_url() ),
157+
'siteTitle' => (string) htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
158+
'stats' => array(
159159
// data is populated asynchronously on page load.
160160
'data' => array(
161161
'general' => false,
@@ -165,13 +165,13 @@ public static function get_initial_state() {
165165
),
166166
'roles' => $stats_roles,
167167
),
168-
'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ),
169-
'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ),
170-
'settings' => self::get_flattened_settings(),
171-
'userData' => array(
168+
'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ),
169+
'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ),
170+
'settings' => self::get_flattened_settings(),
171+
'userData' => array(
172172
'currentUser' => $current_user_data,
173173
),
174-
'siteData' => array(
174+
'siteData' => array(
175175
'blog_id' => Jetpack_Options::get_option( 'id', 0 ),
176176
'icon' => has_site_icon()
177177
? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) )
@@ -199,7 +199,7 @@ public static function get_initial_state() {
199199
'isSharingBlockAvailable' => (bool) isset( $block_availability['sharing-buttons'] )
200200
&& $block_availability['sharing-buttons']['available'],
201201
),
202-
'themeData' => array(
202+
'themeData' => array(
203203
'name' => $current_theme->get( 'Name' ),
204204
'stylesheet' => $current_theme->get_stylesheet(),
205205
'hasUpdate' => (bool) get_theme_update_available( $current_theme ),
@@ -211,42 +211,43 @@ public static function get_initial_state() {
211211
&& ( function_exists( 'wp_register_webfont_provider' ) || function_exists( 'wp_register_webfonts' ) ),
212212
),
213213
),
214-
'jetpackStateNotices' => array(
214+
'jetpackStateNotices' => array(
215215
'messageCode' => Jetpack::state( 'message' ),
216216
'errorCode' => Jetpack::state( 'error' ),
217217
'errorDescription' => Jetpack::state( 'error_description' ),
218218
'messageContent' => Jetpack::state( 'display_update_modal' ) ? self::get_update_modal_data() : null,
219219
),
220-
'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
221-
'currentIp' => IP_Utils::get_ip(),
222-
'lastPostUrl' => esc_url( $last_post ),
223-
'externalServicesConnectUrls' => self::get_external_services_connect_urls(),
224-
'calypsoEnv' => ( new Host() )->get_calypso_env(),
225-
'products' => Jetpack::get_products_for_purchase(),
226-
'recommendationsStep' => Jetpack_Core_Json_Api_Endpoints::get_recommendations_step()['step'],
227-
'isSafari' => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere.
228-
'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ),
229-
'licensing' => array(
220+
'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
221+
'currentIp' => IP_Utils::get_ip(),
222+
'lastPostUrl' => esc_url( $last_post ),
223+
'externalServicesConnectUrls' => self::get_external_services_connect_urls(),
224+
'calypsoEnv' => ( new Host() )->get_calypso_env(),
225+
'products' => Jetpack::get_products_for_purchase(),
226+
'recommendationsStep' => Jetpack_Core_Json_Api_Endpoints::get_recommendations_step()['step'],
227+
'isSafari' => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere.
228+
'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ),
229+
'licensing' => array(
230230
'error' => Licensing::instance()->last_error(),
231231
'showLicensingUi' => Licensing::instance()->is_licensing_input_enabled(),
232232
'userCounts' => Licensing_Endpoints::get_user_license_counts(),
233233
'activationNoticeDismiss' => Licensing::instance()->get_license_activation_notice_dismiss(),
234234
),
235-
'jetpackManage' => array(
235+
'jetpackManage' => array(
236236
'isEnabled' => Jetpack_Manage::could_use_jp_manage(),
237237
'isAgencyAccount' => Jetpack_Manage::is_agency_account(),
238238
),
239-
'hasSeenWCConnectionModal' => Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ),
240-
'newRecommendations' => Jetpack_Recommendations::get_new_conditional_recommendations(),
239+
'hasSeenWCConnectionModal' => Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ),
240+
'newRecommendations' => Jetpack_Recommendations::get_new_conditional_recommendations(),
241241
// Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/).
242-
'isWooCommerceActive' => in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ),
243-
'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(),
244-
'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ),
245-
'shouldInitializeBlaze' => Blaze::should_initialize(),
246-
'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(),
247-
'socialInitialState' => self::get_publicize_initial_state(),
248-
'gutenbergInitialState' => self::get_gutenberg_initial_state(),
249-
'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ) && version_compare( $wp_version, '6.5-beta2', '>=' ),
242+
'isWooCommerceActive' => in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ),
243+
'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(),
244+
'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ),
245+
'shouldInitializeBlaze' => Blaze::should_initialize(),
246+
'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(),
247+
'socialInitialState' => self::get_publicize_initial_state(),
248+
'gutenbergInitialState' => self::get_gutenberg_initial_state(),
249+
'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ),
250+
'subscriptionSiteEditSupported' => $current_theme->is_block_theme() && version_compare( $wp_version, '6.5-beta2', '>=' ),
250251
);
251252
}
252253

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: other
3+
4+
Subscription Site: Release the Subscribe block after the post placement toggle

projects/plugins/jetpack/extensions/blocks/subscriptions/class-jetpack-subscription-site.php

+3-18
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,9 @@ public static function init() {
3838
* @return void
3939
*/
4040
public function handle_subscribe_block_placements() {
41-
if ( ! $this->is_subscription_site_feature_enabled() ) {
42-
return;
43-
}
44-
4541
$this->handle_subscribe_block_post_end_placement();
4642
}
4743

48-
/**
49-
* Returns true if Subscription Site feature is enabled.
50-
*
51-
* @return bool
52-
*/
53-
protected function is_subscription_site_feature_enabled() {
54-
// It's temporary. Allows to enable the Subscription Site feature.
55-
$subscription_site_enabled = (bool) apply_filters( 'jetpack_subscription_site_enabled', false );
56-
57-
global $wp_version;
58-
return $subscription_site_enabled && version_compare( $wp_version, '6.5-beta2', '>=' );
59-
}
60-
6144
/**
6245
* Returns true if current user can view the post.
6346
*
@@ -111,12 +94,14 @@ protected function get_post_end_placement_block_attributes( $default_attrs, $anc
11194
* @return void
11295
*/
11396
protected function handle_subscribe_block_post_end_placement() {
97+
global $wp_version;
98+
11499
$subscribe_post_end_enabled = get_option( 'jetpack_subscriptions_subscribe_post_end_enabled', false );
115100
if ( ! $subscribe_post_end_enabled ) {
116101
return;
117102
}
118103

119-
if ( ! wp_is_block_theme() ) { // Fallback for classic themes.
104+
if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // Fallback for classic themes and wp core < 6.5-beta2.
120105
add_filter(
121106
'the_content',
122107
function ( $content ) {

0 commit comments

Comments
 (0)