From 9a1ad4f9767ab051194d522f77c1576b61793d57 Mon Sep 17 00:00:00 2001 From: Ivan Ottinger <25105483+ivan-ottinger@users.noreply.github.com> Date: Thu, 12 Jan 2023 15:51:32 +0100 Subject: [PATCH] Add `default_option_subscription_options` filter The purpose of this filter is to introduce the default value for `subscription_options`. This default value will be available throughout Simple, Atomic and Jetpack sites, including the Site Settings endpoint. --- ...default_option_subscription_options-filter | 4 +++ ....wpcom-json-api-site-settings-endpoint.php | 2 +- .../plugins/jetpack/modules/subscriptions.php | 2 +- .../jetpack/modules/subscriptions/views.php | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-default_option_subscription_options-filter diff --git a/projects/plugins/jetpack/changelog/add-default_option_subscription_options-filter b/projects/plugins/jetpack/changelog/add-default_option_subscription_options-filter new file mode 100644 index 0000000000000..382f9b5acdc66 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-default_option_subscription_options-filter @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +Add default_option_subscription_options filter 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 532242717fbf6..7776f027274af 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 @@ -441,7 +441,7 @@ public function get_settings_response() { 'wpcom_featured_image_in_email' => (bool) get_option( 'wpcom_featured_image_in_email' ), 'wpcom_gifting_subscription' => (bool) get_option( 'wpcom_gifting_subscription', $this->get_wpcom_gifting_subscription_default() ), 'jetpack_blogging_prompts_enabled' => (bool) jetpack_are_blogging_prompts_enabled(), - 'subscription_options' => (array) get_option( 'subscription_options', array() ), + 'subscription_options' => (array) get_option( 'subscription_options' ), 'wpcom_subscription_emails_use_excerpt' => $this->get_wpcom_subscription_emails_use_excerpt_option(), 'show_on_front' => (string) get_option( 'show_on_front' ), 'page_on_front' => (string) get_option( 'page_on_front' ), diff --git a/projects/plugins/jetpack/modules/subscriptions.php b/projects/plugins/jetpack/modules/subscriptions.php index 605f6edd39ba8..d3a977f5f017e 100644 --- a/projects/plugins/jetpack/modules/subscriptions.php +++ b/projects/plugins/jetpack/modules/subscriptions.php @@ -594,7 +594,7 @@ public function get_default_settings() { * Reeturn merged `subscription_options` option with module default settings. */ public function get_settings() { - return wp_parse_args( (array) get_option( 'subscription_options', array() ), $this->get_default_settings() ); + return wp_parse_args( (array) get_option( 'subscription_options' ), $this->get_default_settings() ); } /** diff --git a/projects/plugins/jetpack/modules/subscriptions/views.php b/projects/plugins/jetpack/modules/subscriptions/views.php index bfec991404824..6111a952b1050 100644 --- a/projects/plugins/jetpack/modules/subscriptions/views.php +++ b/projects/plugins/jetpack/modules/subscriptions/views.php @@ -998,3 +998,32 @@ function jetpack_blog_subscriptions_init() { } add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' ); + +/** + * Sets the default value for `subscription_options` site option. + * + * This default value is available across Simple, Atomic and Jetpack sites, + * including the /sites/$site/settings endpoint. + * + * @param array $default Default `subscription_options` array. + * @param string $option Option name. + * @param bool $passed_default Whether `get_option()` passed a default value. + * + * @return array Default value of `subscription_options`. + */ +function subscription_options_fallback( $default, $option, $passed_default ) { + if ( $passed_default ) { + return $default; + } + + $site_url = get_home_url(); + $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) ); + + return array( + /* translators: Both %1$s and %2$s is site address */ + 'invitation' => sprintf( __( "Howdy,\nYou recently subscribed to %2\$s and we need to verify the email you provided. Once you confirm below, you'll be able to receive and read new posts.\n\nIf you believe this is an error, ignore this message and nothing more will happen.", 'jetpack' ), $site_url, $display_url ), + 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ), + ); +} + +add_filter( 'default_option_subscription_options', 'subscription_options_fallback', 10, 3 );