array(), 's' => array(), 'strong' => array(), 'em' => array(), ); /** * Use this variable when printing the message after submitting an email in subscription widgets * * @var array what tags are allowed */ public static $allowed_html_tags_for_message = array( 'a' => array( 'href' => array(), 'title' => array(), 'rel' => array(), 'target' => array(), ), 'br' => array(), ); /** * Jetpack_Subscriptions_Widget constructor. */ public function __construct() { $widget_ops = array( 'classname' => 'widget_blog_subscription jetpack_subscription_widget', 'description' => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); $name = self::is_jetpack() ? /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', __( 'Blog Subscriptions', 'jetpack' ) ) : __( 'Follow Blog', 'jetpack' ); parent::__construct( 'blog_subscription', $name, $widget_ops ); if ( self::is_jetpack() && ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); } add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); } /** * Remove the "Blog Subscription" widget from the Legacy Widget block * * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block. * @return array $widget_types New list of widgets that will be removed. */ public function hide_widget_in_block_editor( $widget_types ) { $widget_types[] = self::ID_BASE; return $widget_types; } /** * Enqueue the form's CSS. * * @since 4.5.0 */ public function enqueue_style() { wp_register_style( 'jetpack-subscriptions', plugins_url( 'subscriptions.css', __FILE__ ), array(), JETPACK__VERSION ); wp_enqueue_style( 'jetpack-subscriptions' ); } /** * Renders a full widget either within the context of WordPress widget, or in response to a shortcode. * * @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. */ public function widget( $args, $instance ) { if ( self::is_wpcom() && ! self::wpcom_has_status_message() && self::is_current_user_subscribed() ) { return null; } if ( self::is_jetpack() && /** This filter is documented in \Automattic\Jetpack\Forms\ContactForm\Contact_Form */ false === apply_filters( 'jetpack_auto_fill_logged_in_user', false ) ) { $subscribe_email = ''; } else { $current_user = wp_get_current_user(); if ( ! empty( $current_user->user_email ) ) { $subscribe_email = esc_attr( $current_user->user_email ); } else { $subscribe_email = ''; } } $stats_action = self::is_jetpack() ? 'jetpack_subscriptions' : 'follow_blog'; /** This action is documented in modules/widgets/gravatar-profile.php */ do_action( 'jetpack_stats_extra', 'widget_view', $stats_action ); $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : ''; $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : ''; $instance = wp_parse_args( (array) $instance, static::defaults() ); echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ++self::$instance_count; self::render_widget_title( $args, $instance ); self::render_widget_status_messages( $instance ); self::render_widget_subscription_form( $args, $instance, $subscribe_email ); echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Prints the widget's title. If show_only_email_and_button is true, we will not show a title. * * @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. */ public static function render_widget_title( $args, $instance ) { $show_only_email_and_button = $instance['show_only_email_and_button']; $before_title = isset( $args['before_title'] ) ? $args['before_title'] : ''; $after_title = isset( $args['after_title'] ) ? $args['after_title'] : ''; if ( self::is_wpcom() && ! $show_only_email_and_button ) { if ( self::is_current_user_subscribed() ) { if ( ! empty( $instance['title_following'] ) ) { printf( '%1$s%4$s%5$s', $before_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ( self::$instance_count > 1 ? '-' . (int) self::$instance_count : '' ), esc_html( $instance['title_following'] ), $after_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped "\n" ); } } elseif ( ! empty( $instance['title'] ) ) { printf( '%1$s%4$s%5$s', $before_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ( self::$instance_count > 1 ? '-' . (int) self::$instance_count : '' ), esc_html( $instance['title'] ), $after_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped "\n" ); } } if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) { printf( '%1$s%2$s%3$s%4$s', $before_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped esc_html( $instance['title'] ), $after_title, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped "\n" ); } } /** * Prints the subscription block's status messages after someone has attempted to subscribe. * Either a success message or an error message. * * @param array $instance The settings for the particular instance of the widget. */ public static function render_widget_status_messages( $instance ) { if ( self::is_jetpack() && isset( $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output. $success_message = isset( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : ''; $subscribers_total = self::fetch_subscriber_count(); switch ( $_GET['subscribe'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended case 'invalid_email': ?>
Subscriptions Manager', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Subscriptions Manager', 'jetpack' ) ); ?>
Subscriptions Manager.', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Subscriptions Manager', 'jetpack' ) ); ?>
Subscriptions Manager before adding more.', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Subscriptions Manager', 'jetpack' ) ); ?>
Subscriptions Manager.', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Subscriptions Manager', 'jetpack' ) ); ?>
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( '
'