From 1c7bf2e4e26670518d5d34ff3304f65d9ecddf8a Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Fri, 26 Apr 2024 12:20:29 -0700 Subject: [PATCH] Add/reply to newsletter behaviour setting (#37011) --------- Co-authored-by: Miguel Lezama --- .../changelog/add-reply-to-newsletter-setting | 4 ++ projects/packages/sync/src/class-defaults.php | 1 + .../_inc/client/newsletter/email-settings.jsx | 57 ++++++++++++++++++- .../lib/class.core-rest-api-endpoints.php | 33 +++++++++++ ...lass.jetpack-core-api-module-endpoints.php | 6 ++ .../changelog/add-reply-to-newsletter-setting | 4 ++ ....wpcom-json-api-site-settings-endpoint.php | 21 +++++++ ...m-json-api-site-settings-v1-4-endpoint.php | 1 + .../sync/test_class.jetpack-sync-options.php | 1 + 9 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 projects/packages/sync/changelog/add-reply-to-newsletter-setting create mode 100644 projects/plugins/jetpack/changelog/add-reply-to-newsletter-setting diff --git a/projects/packages/sync/changelog/add-reply-to-newsletter-setting b/projects/packages/sync/changelog/add-reply-to-newsletter-setting new file mode 100644 index 0000000000000..29fd8e7cd6eff --- /dev/null +++ b/projects/packages/sync/changelog/add-reply-to-newsletter-setting @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Newsletters: Add reply to behaviour setting diff --git a/projects/packages/sync/src/class-defaults.php b/projects/packages/sync/src/class-defaults.php index 0acd3247838b7..dfbe6939d1d12 100644 --- a/projects/packages/sync/src/class-defaults.php +++ b/projects/packages/sync/src/class-defaults.php @@ -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', diff --git a/projects/plugins/jetpack/_inc/client/newsletter/email-settings.jsx b/projects/plugins/jetpack/_inc/client/newsletter/email-settings.jsx index f04dd353042da..3e656949e8ef9 100644 --- a/projects/plugins/jetpack/_inc/client/newsletter/email-settings.jsx +++ b/projects/plugins/jetpack/_inc/client/newsletter/email-settings.jsx @@ -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'; @@ -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 { @@ -23,6 +28,7 @@ const EmailSettings = props => { unavailableInOfflineMode, isFeaturedImageInEmailEnabled, subscriptionEmailsUseExcerpt, + subscriptionReplyTo, updateFormStateAndSaveOptionValue, unavailableInSiteConnectionMode, } = props; @@ -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 ( { onChange={ handleSubscriptionEmailsUseExcerptChange } /> + { isNewsletterReplyToEnabled && ( + + + { __( 'Reply-to settings', 'jetpack' ) } + +

+ { __( + 'Choose who receives emails when subscribers reply to your newsletter.', + 'jetpack' + ) } +

+ +
+ ) }
); }; @@ -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, diff --git a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php index cb104c91c4dda..164e24374de54 100644 --- a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php +++ b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php @@ -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', @@ -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. * diff --git a/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php b/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php index aae8a47b52be5..b72eb3ec3ce90 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php @@ -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': diff --git a/projects/plugins/jetpack/changelog/add-reply-to-newsletter-setting b/projects/plugins/jetpack/changelog/add-reply-to-newsletter-setting new file mode 100644 index 0000000000000..2ab2b51c6f0b1 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-reply-to-newsletter-setting @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Newsletter: Add subscrition reply to behaviour diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php index 067033e47f791..a94bedaf1c711 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php @@ -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' ), @@ -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; @@ -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. * diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php index 8f468544ffcbe..6531b283d7e85 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php @@ -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\'.', diff --git a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-options.php b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-options.php index af9ca63d5d41f..1cece20389f61 100644 --- a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-options.php +++ b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-options.php @@ -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',