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_jetpack() && /** This filter is documented in modules/contact-form/grunion-contact-form.php */ 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, $this->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'] ) ) { echo $before_title . '' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } else { if ( ! empty( $instance['title'] ) ) { echo $before_title . '' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } } if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) { echo $args['before_title'] . $instance['title'] . $args['after_title'] . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * 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': ?>
You can manage your preferences at subscribe.wordpress.com', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Manage your email preferences.', 'jetpack' ) ); ?>
You can manage your preferences at subscribe.wordpress.com', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Manage your email preferences.', 'jetpack' ) ); ?>
Approve or delete a few subscriptions at subscribe.wordpress.com before continuing.', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Manage your email preferences.', 'jetpack' ) ); ?>
Otherwise, you can manage your preferences at subscribe.wordpress.com.', 'jetpack' ), self::$allowed_html_tags_for_message ), 'https://subscribe.wordpress.com/', esc_attr__( 'Manage your email preferences.', 'jetpack' ) ); ?>
contact us.', 'jetpack' ); break; case 'blocked': $message = __( 'Subscriptions have been blocked for this email address.', 'jetpack' ); break; case 'flooded': $message = __( 'You already have several pending email subscriptions. Approve or delete a few through your Subscription Manager before attempting to subscribe to more blogs.', 'jetpack' ); break; case 'spammed': /* translators: %s is a URL */ $message = sprintf( __( 'Because there are many pending subscriptions for this email address, we have blocked the subscription. Please activate or delete pending subscriptions before attempting to subscribe.', 'jetpack' ), 'https://subscribe.wordpress.com/' ); break; case 'subscribed': $message = __( 'You’re already subscribed to this site.', 'jetpack' ); break; case 'pending': $message = __( 'You have a pending subscription already; we just sent you another email. Click the link or contact us if you don’t receive it.', 'jetpack' ); break; case 'confirmed': $message = __( 'Congrats, you’re subscribed! You’ll get an email with the details of your subscription and an unsubscribe link.', 'jetpack' ); break; } $border_color = isset( $themecolors['border'] ) ? " #{$themecolors['border']}" : ''; $redirect_fragment = self::get_redirect_fragment(); printf( '
'