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

Add/reply to newsletter behaviour setting #37011

Merged
merged 12 commits into from
Apr 26, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Newsletters: Add reply to behaviour setting
1 change: 1 addition & 0 deletions projects/packages/sync/src/class-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Defaults {
'wpcom_reader_views_enabled',
'wpcom_site_setup',
'wpcom_subscription_emails_use_excerpt',
'jetpack_subscriptions_reply_to',
'jetpack_verbum_subscription_modal',
'jetpack_blocks_disabled',
'jetpack_package_versions',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RadioControl, ToggleControl } from '@automattic/jetpack-components';
import { RadioControl, ToggleControl, getRedirectUrl } from '@automattic/jetpack-components';
import { __ } from '@wordpress/i18n';
import { FormLegend } from 'components/forms';
import { withModuleSettingsFormHelpers } from 'components/module-settings/with-module-settings-form-helpers';
Expand All @@ -15,6 +15,11 @@ const subscriptionsAndNewslettersSupportUrl =
'https://wordpress.com/support/subscriptions-and-newsletters/';
const FEATURED_IMAGE_IN_EMAIL_OPTION = 'wpcom_featured_image_in_email';
const SUBSCRIPTION_EMAILS_USE_EXCERPT_OPTION = 'wpcom_subscription_emails_use_excerpt';
const REPLY_TO_OPTION = 'jetpack_subscriptions_reply_to';

//Check for feature flag
const urlParams = new URLSearchParams( window.location.search );
const isNewsletterReplyToEnabled = urlParams.get( 'enable-newsletter-replyto' ) === 'true';

const EmailSettings = props => {
const {
Expand All @@ -23,6 +28,7 @@ const EmailSettings = props => {
unavailableInOfflineMode,
isFeaturedImageInEmailEnabled,
subscriptionEmailsUseExcerpt,
subscriptionReplyTo,
updateFormStateAndSaveOptionValue,
unavailableInSiteConnectionMode,
} = props;
Expand All @@ -44,12 +50,21 @@ const EmailSettings = props => {
[ updateFormStateAndSaveOptionValue ]
);

const handleSubscriptionReplyToChange = useCallback(
value => {
updateFormStateAndSaveOptionValue( REPLY_TO_OPTION, value );
},
[ updateFormStateAndSaveOptionValue ]
);

const disabled = unavailableInOfflineMode || unavailableInSiteConnectionMode;
const featuredImageInputDisabled =
disabled || isSavingAnyOption( [ FEATURED_IMAGE_IN_EMAIL_OPTION ] );
const excerptInputDisabled =
disabled || isSavingAnyOption( [ SUBSCRIPTION_EMAILS_USE_EXCERPT_OPTION ] );

const replyToInputDisabled = disabled || isSavingAnyOption( [ REPLY_TO_OPTION ] );

return (
<SettingsCard
{ ...props }
Expand Down Expand Up @@ -107,6 +122,45 @@ const EmailSettings = props => {
onChange={ handleSubscriptionEmailsUseExcerptChange }
/>
</SettingsGroup>
{ isNewsletterReplyToEnabled && (
<SettingsGroup
hasChild
disableInOfflineMode
disableInSiteConnectionMode
module={ subscriptionsModule }
support={ {
link: getRedirectUrl( 'jetpack-support-subscriptions', {
anchor: 'reply-to-email-address',
} ),
text: __(
'Sets the reply to email address for your newsletter emails. This is the email address that your subscribers send email to when they reply to the newsletter.',
'jetpack'
),
} }
>
<FormLegend className="jp-form-label-wide">
{ __( 'Reply-to settings', 'jetpack' ) }
</FormLegend>
<p>
{ __(
'Choose who receives emails when subscribers reply to your newsletter.',
'jetpack'
) }
</p>
<RadioControl
selected={ subscriptionReplyTo || 'no-reply' }
disabled={ replyToInputDisabled }
options={ [
{ label: __( 'Replies are not allowed.', 'jetpack' ), value: 'no-reply' },
{
label: __( "Replies will be sent to the post author's email.", 'jetpack' ),
value: 'author',
},
] }
onChange={ handleSubscriptionReplyToChange }
/>
</SettingsGroup>
) }
</SettingsCard>
);
};
Expand All @@ -121,6 +175,7 @@ export default withModuleSettingsFormHelpers(
subscriptionEmailsUseExcerpt: ownProps.getOptionValue(
SUBSCRIPTION_EMAILS_USE_EXCERPT_OPTION
),
subscriptionReplyTo: ownProps.getOptionValue( REPLY_TO_OPTION ),
unavailableInOfflineMode: isUnavailableInOfflineMode( state, SUBSCRIPTIONS_MODULE_NAME ),
unavailableInSiteConnectionMode: isUnavailableInSiteConnectionMode(
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,13 @@ public static function get_updateable_data_list( $selector = '' ) {
'validate_callback' => __CLASS__ . '::validate_boolean',
'jp_group' => 'subscriptions',
),
'jetpack_subscriptions_reply_to' => array(
'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ),
'type' => 'string',
'default' => 'no-reply',
'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to',
'jp_group' => 'subscriptions',
),
'sm_enabled' => array(
'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ),
'type' => 'boolean',
Expand Down Expand Up @@ -3383,6 +3390,32 @@ public static function validate_sharing_show( $value, $request, $param ) {
return true;
}

/**
* Validates that the parameter is among the valid reply-to types for subscriptions.
*
* @since 4.3.0
*
* @param string|bool $value Value to check.
* @param WP_REST_Request $request The request sent to the WP REST API.
* @param string $param Name of the parameter passed to endpoint holding $value.
*
* @return bool|WP_Error
*/
public static function validate_subscriptions_reply_to( $value, $request, $param ) {
$valid_values = array( 'author', 'no-reply' );
if ( ! empty( $value ) && ! in_array( $value, $valid_values, true ) ) {
return new WP_Error(
'invalid_param',
sprintf(
/* Translators: Placeholder is a parameter name. */
esc_html__( '%s must be a valid type.', 'jetpack' ),
$param
)
);
}
return true;
}

/**
* Validates that the parameter is among the views where the Sharing can be displayed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,12 @@ public function update_data( $request ) {
}
break;

case 'jetpack_subscriptions_reply_to':
// If option value was the same, consider it done.
$sub_value = in_array( $value, array( 'no-reply', 'author' ), true ) ? $value : 'no-reply';
$updated = (string) get_option( $option ) !== (string) $sub_value ? update_option( $option, $sub_value ) : true;
break;

case 'stb_enabled':
case 'stc_enabled':
case 'sm_enabled':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Newsletter: Add subscrition reply to behaviour
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ function ( $newsletter_category ) {
'wpcom_gifting_subscription' => (bool) get_option( 'wpcom_gifting_subscription', $this->get_wpcom_gifting_subscription_default() ),
'wpcom_reader_views_enabled' => (bool) get_option( 'wpcom_reader_views_enabled', true ),
'wpcom_subscription_emails_use_excerpt' => $this->get_wpcom_subscription_emails_use_excerpt_option(),
'jetpack_subscriptions_reply_to' => (string) $this->get_subscriptions_reply_to_option(),
'show_on_front' => (string) get_option( 'show_on_front' ),
'page_on_front' => (string) get_option( 'page_on_front' ),
'page_for_posts' => (string) get_option( 'page_for_posts' ),
Expand Down Expand Up @@ -1026,6 +1027,12 @@ function ( &$value ) {
$updated[ $key ] = (bool) $value;
break;

case 'jetpack_subscriptions_reply_to':
$to_set_value = (string) in_array( $value, array( 'no-reply', 'author' ), true ) ? $value : 'no-reply';
update_option( 'jetpack_subscriptions_reply_to', (string) $to_set_value );
$updated[ $key ] = (bool) $value;
break;

case 'instant_search_enabled':
update_option( 'instant_search_enabled', (bool) $value );
$updated[ $key ] = (bool) $value;
Expand Down Expand Up @@ -1251,6 +1258,20 @@ protected function get_wpcom_subscription_emails_use_excerpt_option() {
return (bool) $wpcom_subscription_emails_use_excerpt;
}

/**
* Get the string value of the jetpack_subscriptions_reply_to option.
* When the option is not set, it will retun 'no-reply'.
*
* @return string
*/
protected function get_subscriptions_reply_to_option() {
$reply_to = get_option( 'jetpack_subscriptions_reply_to', null );
if ( $reply_to === null ) {
return 'no-reply';
}
return $reply_to;
}

/**
* Check if the given value is a valid page ID for the current site.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
'wpcom_gifting_subscription' => '(bool) Whether gifting is enabled for non auto-renew sites',
'wpcom_reader_views_enabled' => '(bool) Whether showing post views in WordPress.com Reader is enabled for the site',
'wpcom_subscription_emails_use_excerpt' => '(bool) Whether site subscription emails (e.g. New Post email notification) will use post excerpts',
'jetpack_subscriptions_reply_to' => '(string) The reply to email behaviour for newsletter emails',
'show_on_front' => '(string) Whether homepage should display related posts or a static page. The expected value is \'posts\' or \'page\'.',
'page_on_front' => '(string) The page ID of the page to use as the site\'s homepage. It will apply only if \'show_on_front\' is set to \'page\'.',
'page_for_posts' => '(string) The page ID of the page to use as the site\'s posts page. It will apply only if \'show_on_front\' is set to \'page\'.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function test_sync_default_options() {
'sm_enabled' => false,
'jetpack_subscriptions_subscribe_post_end_enabled' => false,
'jetpack_subscriptions_login_navigation_enabled' => false,
'jetpack_subscriptions_reply_to' => 'no-reply',
'comment_registration' => 'pineapple',
'show_avatars' => 'pineapple',
'avatar_default' => 'pineapple',
Expand Down
Loading