Contact us if needed.', 'jetpack' );
break;
case 'flooded':
$message = __( 'Oops! It seems you have several subscriptions pending confirmation. You can confirm or unsubscribe some from the Subscriptions Manager before adding more.', 'jetpack' );
break;
case 'spammed':
/* translators: %s is a URL */
$message = sprintf( __( 'Sorry but this email has been blocked. It has too many subscriptions pending confirmation. Please confirm or unsubscribe some from the Subscriptions Manager.', 'jetpack' ), 'https://subscribe.wordpress.com/' );
break;
case 'subscribed':
$message = __( 'Hey! You were already subscribed.', 'jetpack' );
break;
case 'pending':
$message = __( 'It seems you already tried to subscribe. We just sent you another email so you can confirm the subscription.', 'jetpack' );
break;
case 'confirmed':
$message = __( 'Cool! You are now subscribed. Now you can check your email for more details and how to manage the subscription.', 'jetpack' );
break;
}
$border_color = isset( $themecolors['border'] ) ? " #{$themecolors['border']}" : '';
$redirect_fragment = self::get_redirect_fragment();
printf(
'
%3$s
',
esc_attr( $redirect_fragment ),
esc_attr( $border_color ),
wp_kses_post( $message )
);
}
}
/**
* Generates the redirect fragment used after form submission.
*
* @param string $id is the specific id that will appear in the redirect fragment. If none is provided self::$instance_count will be used.
*/
protected static function get_redirect_fragment( $id = null ) {
if ( $id === null ) {
return 'subscribe-blog' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' );
}
return 'subscribe-blog-' . $id;
}
/**
* Generates the source parameter to pass to the iframe
*
* @return string the actaul post access level (see projects/plugins/jetpack/extensions/blocks/subscriptions/settings.js for the values).
*/
protected static function get_post_access_level() {
$post_id = get_the_ID();
if ( ! $post_id ) {
return 'everybody';
}
require_once __DIR__ . '/../../extensions/blocks/subscriptions/constants.php';
$meta = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
if ( empty( $meta ) ) {
$meta = 'everybody';
}
return $meta;
}
/**
* Renders a form allowing folks to subscribe to the blog.
*
* @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
* @param array $instance The settings for the particular instance of the widget.
* @param string $subscribe_email The email to use to prefill the form.
*/
public static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
$show_only_email_and_button = $instance['show_only_email_and_button'];
$show_subscribers_total = (bool) $instance['show_subscribers_total'];
$subscribers_total = self::fetch_subscriber_count();
$subscribe_text = empty( $instance['show_only_email_and_button'] ) ?
stripslashes( $instance['subscribe_text'] ) :
false;
$referer = esc_url_raw( ( is_ssl() ? 'https' : 'http' ) . '://' . ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : '' ) . ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' ) );
$source = 'widget';
$widget_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : self::$instance_count;
$subscribe_button = ! empty( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : $instance['subscribe_button'];
$subscribe_placeholder = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
$submit_button_classes = isset( $instance['submit_button_classes'] ) ? 'wp-block-button__link ' . $instance['submit_button_classes'] : 'wp-block-button__link';
$submit_button_styles = isset( $instance['submit_button_styles'] ) ? $instance['submit_button_styles'] : '';
$submit_button_wrapper_styles = isset( $instance['submit_button_wrapper_styles'] ) ? $instance['submit_button_wrapper_styles'] : '';
$email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
$email_field_styles = isset( $instance['email_field_styles'] ) ? $instance['email_field_styles'] : '';
$post_access_level = self::get_post_access_level();
if ( self::is_wpcom() && ! self::wpcom_has_status_message() ) {
global $current_blog;
$url = defined( 'SUBSCRIBE_BLOG_URL' ) ? SUBSCRIBE_BLOG_URL : '';
$form_id = self::get_redirect_fragment();
?>
query( 'jetpack.fetchSubscriberCount' );
if ( $xml->isError() ) { // If we get an error from .com, set the status to failed so that we will try again next time the data is requested.
$subs_count = array(
'status' => 'failed',
'code' => $xml->getErrorCode(),
'message' => $xml->getErrorMessage(),
'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
);
} else {
$subs_count = array(
'status' => 'success',
'value' => $xml->getResponse(),
);
}
set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
}
return $subs_count['value'];
}
if ( self::is_wpcom() ) {
$subs_count = wpcom_reach_total_for_blog();
return $subs_count;
}
}
/**
* Updates a particular instance of a widget when someone saves it in wp-admin.
*
* @param array $new_instance New widget instance settings.
* @param array $old_instance Old widget instance settings.
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
if ( self::is_jetpack() ) {
$instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
$instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
$instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
$instance['success_message'] = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
}
if ( self::is_wpcom() ) {
$instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
$instance['title_following'] = wp_strip_all_tags( stripslashes( $new_instance['title_following'] ) );
$instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
$instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $new_instance['subscribe_button'] ) );
}
$instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
$instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
$instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
return $instance;
}
/**
* The default args for rendering a subscription form.
*
* @return array
*/
public static function defaults() {
$defaults = array(
'show_subscribers_total' => true,
'show_only_email_and_button' => false,
'include_social_followers' => true,
);
$defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
$defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
$defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
$defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
$defaults['success_message'] = esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm Follow' to start subscribing.", 'jetpack' );
return $defaults;
}
/**
* Renders the widget's options form in wp-admin.
*
* @param array $instance Widget instance.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
$show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
if ( self::is_wpcom() ) {
$title = esc_attr( stripslashes( $instance['title'] ) );
$title_following = esc_attr( stripslashes( $instance['title_following'] ) );
$subscribe_text = esc_attr( stripslashes( $instance['subscribe_text'] ) );
$subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
$subscribe_button = esc_attr( stripslashes( $instance['subscribe_button'] ) );
$subscribers_total = self::fetch_subscriber_count();
}
if ( self::is_jetpack() ) {
$title = stripslashes( $instance['title'] );
$subscribe_text = stripslashes( $instance['subscribe_text'] );
$subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
$subscribe_button = stripslashes( $instance['subscribe_button'] );
$success_message = stripslashes( $instance['success_message'] );
$subscribers_total = self::fetch_subscriber_count();
}
if ( self::is_wpcom() ) :
?>
'
',
);
ob_start();
the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
$output = ob_get_clean();
return $output;
}
add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
/**
* Register the Subscriptions widget.
*/
function jetpack_blog_subscriptions_init() {
register_widget( get_jetpack_blog_subscriptions_widget_classname() );
}
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 );