Skip to content

Commit

Permalink
Add default_option_subscription_options filter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivan-ottinger committed Jan 17, 2023
1 parent 0225536 commit 9a1ad4f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Add default_option_subscription_options filter
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/modules/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

/**
Expand Down
29 changes: 29 additions & 0 deletions projects/plugins/jetpack/modules/subscriptions/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href='%1\$s'>%2\$s</a> 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 );

0 comments on commit 9a1ad4f

Please sign in to comment.