Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe modal: remove filters and enable for Jetpack sites #33909

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Always enable subscribe modal task in launchpad.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ function wpcom_launchpad_get_task_definitions() {
return __( 'Enable subscribers modal', 'jetpack-mu-wpcom' );
},
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => 'wpcom_launchpad_is_enable_subscribers_modal_visible',
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
'get_calypso_path' => function ( $task, $default, $data ) {
return '/settings/newsletter/' . $data['site_slug_encoded'];
},
Expand Down Expand Up @@ -1363,15 +1362,6 @@ function wpcom_launchpad_mark_enable_subscribers_modal_complete( $old_value, $va
add_action( 'update_option_sm_enabled', 'wpcom_launchpad_mark_enable_subscribers_modal_complete', 10, 3 );
add_action( 'add_option_sm_enabled', 'wpcom_launchpad_mark_enable_subscribers_modal_complete', 10, 3 );

/**
* Determines whether the enable_subscribers_modal task should show.
*
* @return bool True if the task should show, false otherwise.
*/
function wpcom_launchpad_is_enable_subscribers_modal_visible() {
return apply_filters( 'jetpack_subscriptions_modal_enabled', false );
}

/**
* Determine `domain_claim` task visibility.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import React, { useCallback } from 'react';
import { connect } from 'react-redux';
import { isCurrentUserLinked, isUnavailableInOfflineMode, isOfflineMode } from 'state/connection';
import {
isSubscriptionModalEnabled,
currentThemeIsBlockTheme,
currentThemeStylesheet,
getSiteAdminUrl,
Expand All @@ -33,7 +32,6 @@ const trackViewSubsClick = () => {
*/
function SubscriptionsSettings( props ) {
const {
hasSubscriptionModal,
unavailableInOfflineMode,
isLinked,
isOffline,
Expand Down Expand Up @@ -149,36 +147,32 @@ function SubscriptionsSettings( props ) {
'jetpack'
) }
/>
{ hasSubscriptionModal && (
<>
<ToggleControl
checked={ isSubscriptionsActive && isSmEnabled }
disabled={
! isSubscriptionsActive ||
unavailableInOfflineMode ||
isSavingAnyOption( [ 'subscriptions' ] ) ||
! isLinked
}
toggling={ isSavingAnyOption( [ 'sm_enabled' ] ) }
onChange={ handleSubscribeModalToggleChange }
label={ __( 'Enable subscriber pop-up', 'jetpack' ) }
/>
<p className="jp-form-setting-explanation">
{ __(
'Automatically add a subscribe form pop-up to every post and turn visitors into subscribers. It will appear as readers scroll through your posts.',
'jetpack'
) }
{ isBlockTheme && subscribeModalEditorUrl && (
<>
{ ' ' }
<ExternalLink href={ subscribeModalEditorUrl }>
{ __( 'Preview and edit the pop-up', 'jetpack' ) }
</ExternalLink>
</>
) }
</p>
</>
) }
<ToggleControl
checked={ isSubscriptionsActive && isSmEnabled }
disabled={
! isSubscriptionsActive ||
unavailableInOfflineMode ||
isSavingAnyOption( [ 'subscriptions' ] ) ||
! isLinked
}
toggling={ isSavingAnyOption( [ 'sm_enabled' ] ) }
onChange={ handleSubscribeModalToggleChange }
label={ __( 'Enable subscriber pop-up', 'jetpack' ) }
/>
<p className="jp-form-setting-explanation">
{ __(
'Automatically add a subscribe form pop-up to every post and turn visitors into subscribers. It will appear as readers scroll through your posts.',
'jetpack'
) }
{ isBlockTheme && subscribeModalEditorUrl && (
<>
{ ' ' }
<ExternalLink href={ subscribeModalEditorUrl }>
{ __( 'Preview and edit the pop-up', 'jetpack' ) }
</ExternalLink>
</>
) }
</p>
</FormFieldset>
}
</SettingsGroup>
Expand All @@ -201,7 +195,6 @@ export default withModuleSettingsFormHelpers(
isLinked: isCurrentUserLinked( state ),
isOffline: isOfflineMode( state ),
isSubscriptionsActive: ownProps.getOptionValue( 'subscriptions' ),
hasSubscriptionModal: isSubscriptionModalEnabled( state ),
unavailableInOfflineMode: isUnavailableInOfflineMode( state, 'subscriptions' ),
subscriptions: getModule( state, 'subscriptions' ),
isStbEnabled: ownProps.getOptionValue( 'stb_enabled' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,6 @@ export function isBlazeDashboardEnabled( state ) {
return !! state.jetpack.initialState.isBlazeDashboardEnabled;
}

/**
* Returns true if Subscribe Modal can be used on the site.
*
* @param {object} state - Global state tree.
* @returns {boolean} True if Subscription Modal is available on the site.
*/
export function isSubscriptionModalEnabled( state ) {
return !! state.jetpack.initialState.isSubscriptionModalEnabled;
}

/**
* Returns true if Jetpack's Pre-connection helpers are enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ public static function get_initial_state() {
'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ),
'shouldInitializeBlaze' => Blaze::should_initialize(),
'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(),
/** This filter is documented in plugins/jetpack/modules/subscriptions/subscribe-module/class-jetpack-subscribe-module.php */
'isSubscriptionModalEnabled' => apply_filters( 'jetpack_subscriptions_modal_enabled', false ),
'socialInitialState' => self::get_publicize_initial_state(),
'gutenbergInitialState' => self::get_gutenberg_initial_state(),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Add subscribe modal to Newsletter settings
25 changes: 11 additions & 14 deletions projects/plugins/jetpack/modules/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,18 @@ public function configure() {

/** Enable Subscribe Modal */

/** This filter is documented in plugins/jetpack/modules/subscriptions/subscribe-module/class-jetpack-subscribe-module.php */
if ( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) ) {
add_settings_field(
'jetpack_subscriptions_comment_subscribe',
__( 'Enable Subscribe Modal', 'jetpack' ),
array( $this, 'subscribe_modal_setting' ),
'discussion',
'jetpack_subscriptions'
);
add_settings_field(
'jetpack_subscriptions_comment_subscribe',
__( 'Enable Subscribe Modal', 'jetpack' ),
array( $this, 'subscribe_modal_setting' ),
'discussion',
'jetpack_subscriptions'
);

register_setting(
'discussion',
'sm_enabled'
);
}
register_setting(
'discussion',
'sm_enabled'
);

/** Email me whenever: Someone follows my blog */
/* @since 8.1 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,6 @@ public function set_up() {
*/
public function tear_down() {
remove_all_filters( 'jetpack_is_connection_ready' );
remove_all_filters( 'jetpack_subscriptions_modal_enabled' );
parent::tear_down();
}

/**
* Test that the Jetpack Subscribe Modal does not load by default.
* We are removing a feature flag, but adding a check to load this
* feature only on WordPress.com sites.
*/
public function test_subscriber_modal_enabled_under_correct_conditions() {
// Test that the modal is not enabled by default.
$this->assertFalse( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) );

// Test that the modal is not enabled even when
// other needed conditions are met.
switch_theme( 'block-theme' );
update_option( 'site_intent', 'newsletter' );
$this->assertFalse( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) );

// Test that feature can be enabled by manually adding
// feature flag filter.
add_filter( 'jetpack_subscriptions_modal_enabled', '__return_true', 11 );
$this->assertTrue( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) );
}
}
Loading