PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.3.2
Jetpack – WP Security, Backup, Speed, & Growth v12.3.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / subscriptions / views.php
jetpack / modules / subscriptions Last commit date
readme.md 7 years ago subscriptions.css 7 years ago views.php 3 years ago
views.php
1040 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4
5 /**
6 * Jetpack_Subscriptions_Widget main view class.
7 */
8 class Jetpack_Subscriptions_Widget extends WP_Widget {
9
10 const ID_BASE = 'blog_subscription';
11
12 /**
13 * Track number of rendered Subscription widgets. The count is used for class names and widget IDs.
14 *
15 * @var int
16 */
17 public static $instance_count = 0;
18
19 /**
20 * When printing the submit button, what tags are allowed.
21 *
22 * @var array
23 */
24 public static $allowed_html_tags_for_submit_button = array(
25 'br' => array(),
26 's' => array(),
27 'strong' => array(),
28 'em' => array(),
29 );
30
31 /**
32 * Use this variable when printing the message after submitting an email in subscription widgets
33 *
34 * @var array what tags are allowed
35 */
36 public static $allowed_html_tags_for_message = array(
37 'a' => array(
38 'href' => array(),
39 'title' => array(),
40 'rel' => array(),
41 'target' => array(),
42 ),
43 'br' => array(),
44 );
45
46 /**
47 * Jetpack_Subscriptions_Widget constructor.
48 */
49 public function __construct() {
50 $widget_ops = array(
51 'classname' => 'widget_blog_subscription jetpack_subscription_widget',
52 'description' => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ),
53 'customize_selective_refresh' => true,
54 'show_instance_in_rest' => true,
55 );
56
57 $name = self::is_jetpack() ?
58 /** This filter is documented in modules/widgets/facebook-likebox.php */
59 apply_filters( 'jetpack_widget_name', __( 'Blog Subscriptions', 'jetpack' ) ) :
60 __( 'Follow Blog', 'jetpack' );
61
62 parent::__construct(
63 'blog_subscription',
64 $name,
65 $widget_ops
66 );
67
68 if ( self::is_jetpack() &&
69 (
70 is_active_widget( false, false, $this->id_base ) ||
71 is_active_widget( false, false, 'monster' ) ||
72 is_customize_preview()
73 )
74 ) {
75 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
76 }
77
78 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
79 }
80
81 /**
82 * Remove the "Blog Subscription" widget from the Legacy Widget block
83 *
84 * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
85 * @return array $widget_types New list of widgets that will be removed.
86 */
87 public function hide_widget_in_block_editor( $widget_types ) {
88 $widget_types[] = self::ID_BASE;
89 return $widget_types;
90 }
91
92 /**
93 * Enqueue the form's CSS.
94 *
95 * @since 4.5.0
96 */
97 public function enqueue_style() {
98 wp_register_style(
99 'jetpack-subscriptions',
100 plugins_url( 'subscriptions.css', __FILE__ ),
101 array(),
102 JETPACK__VERSION
103 );
104 wp_enqueue_style( 'jetpack-subscriptions' );
105 }
106
107 /**
108 * Renders a full widget either within the context of WordPress widget, or in response to a shortcode.
109 *
110 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
111 * @param array $instance The settings for the particular instance of the widget.
112 */
113 public function widget( $args, $instance ) {
114 if ( self::is_jetpack() &&
115 /** This filter is documented in modules/contact-form/grunion-contact-form.php */
116 false === apply_filters( 'jetpack_auto_fill_logged_in_user', false )
117 ) {
118 $subscribe_email = '';
119 } else {
120 $current_user = wp_get_current_user();
121 if ( ! empty( $current_user->user_email ) ) {
122 $subscribe_email = esc_attr( $current_user->user_email );
123 } else {
124 $subscribe_email = '';
125 }
126 }
127
128 $stats_action = self::is_jetpack() ? 'jetpack_subscriptions' : 'follow_blog';
129 /** This action is documented in modules/widgets/gravatar-profile.php */
130 do_action( 'jetpack_stats_extra', 'widget_view', $stats_action );
131
132 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
133 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
134 $instance = wp_parse_args( (array) $instance, static::defaults() );
135
136 echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
137
138 ++self::$instance_count;
139
140 self::render_widget_title( $args, $instance );
141
142 self::render_widget_status_messages( $instance );
143
144 self::render_widget_subscription_form( $args, $instance, $subscribe_email );
145
146 echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
147 }
148
149 /**
150 * Prints the widget's title. If show_only_email_and_button is true, we will not show a title.
151 *
152 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
153 * @param array $instance The settings for the particular instance of the widget.
154 */
155 public static function render_widget_title( $args, $instance ) {
156 $show_only_email_and_button = $instance['show_only_email_and_button'];
157 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
158 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
159 if ( self::is_wpcom() && ! $show_only_email_and_button ) {
160 if ( self::is_current_user_subscribed() ) {
161 if ( ! empty( $instance['title_following'] ) ) {
162 echo $before_title . '<label for="subscribe-field' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' ) . '">' . esc_attr( $instance['title_following'] ) . '</label>' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
163 }
164 } elseif ( ! empty( $instance['title'] ) ) {
165 echo $before_title . '<label for="subscribe-field' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' ) . '">' . $instance['title'] . '</label>' . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
166 }
167 }
168
169 if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) {
170 echo $args['before_title'] . $instance['title'] . $args['after_title'] . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
171 }
172 }
173
174 /**
175 * Prints the subscription block's status messages after someone has attempted to subscribe.
176 * Either a success message or an error message.
177 *
178 * @param array $instance The settings for the particular instance of the widget.
179 */
180 public static function render_widget_status_messages( $instance ) {
181 if ( self::is_jetpack() && isset( $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
182 $success_message = isset( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : '';
183 $subscribers_total = self::fetch_subscriber_count();
184
185 switch ( $_GET['subscribe'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended
186 case 'invalid_email':
187 ?>
188 <p class="error"><?php esc_html_e( 'Oops! The email you used is invalid. Please try again.', 'jetpack' ); ?></p>
189 <?php
190 break;
191 case 'opted_out':
192 ?>
193 <p class="error">
194 <?php
195 printf(
196 wp_kses(
197 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
198 __( 'Oops! It seems that the email you used has opted out of subscriptions. You can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank">Subscriptions Manager</a>', 'jetpack' ),
199 self::$allowed_html_tags_for_message
200 ),
201 'https://subscribe.wordpress.com/',
202 esc_attr__( 'Subscriptions Manager', 'jetpack' )
203 );
204 ?>
205 </p>
206 <?php
207 break;
208 case 'already':
209 ?>
210 <p class="error">
211 <?php
212 printf(
213 wp_kses(
214 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link. */
215 __( 'You have already subscribed to this site. Please check your email inbox. You can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank">Subscriptions Manager</a>.', 'jetpack' ),
216 self::$allowed_html_tags_for_message
217 ),
218 'https://subscribe.wordpress.com/',
219 esc_attr__( 'Subscriptions Manager', 'jetpack' )
220 );
221 ?>
222 </p>
223 <?php
224 break;
225 case 'many_pending_subs':
226 ?>
227 <p class="error">
228 <?php
229 printf(
230 wp_kses(
231 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
232 __( 'Oops! It seems you have several subscriptions pending confirmation. You can confirm or unsubscribe some from the <a href="%1$s" title="%2$s" target="_blank" rel="noopener noreferrer">Subscriptions Manager</a> before adding more.', 'jetpack' ),
233 self::$allowed_html_tags_for_message
234 ),
235 'https://subscribe.wordpress.com/',
236 esc_attr__( 'Subscriptions Manager', 'jetpack' )
237 );
238 ?>
239 </p>
240 <?php
241 break;
242 case 'pending':
243 ?>
244 <p class="error">
245 <?php
246 printf(
247 wp_kses(
248 /* translators: 1: Link to Subscription Management page https://subscribe.wordpress.com/, 2: Description of this link */
249 __( 'It seems you already tried to subscribe with this email, but have not confirmed from the email link we sent. Please check your email inbox to confirm or you can manage your preferences from the <a href="%1$s" title="%2$s" target="_blank" rel="noopener noreferrer">Subscriptions Manager</a>.', 'jetpack' ),
250 self::$allowed_html_tags_for_message
251 ),
252 'https://subscribe.wordpress.com/',
253 esc_attr__( 'Subscriptions Manager', 'jetpack' )
254 );
255 ?>
256 </p>
257 <?php
258 break;
259 case 'success':
260 ?>
261 <div class="success"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $success_message ) ), 'post' ); ?></div>
262 <?php
263 break;
264 default:
265 ?>
266 <p class="error"><?php esc_html_e( 'Oops! There was an error when subscribing. Please try again.', 'jetpack' ); ?></p>
267 <?php
268 break;
269 endswitch;
270 }
271
272 if ( self::is_wpcom() && self::wpcom_has_status_message() ) {
273 global $themecolors;
274 $message = '';
275
276 switch ( $_GET['blogsub'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
277 case 'confirming':
278 $message = __( 'Thank you! You can now check your email to confirm your subscription.', 'jetpack' );
279 break;
280 case 'blocked':
281 $message = __( 'Sorry but this email has been blocked for this subscription. <a href="https://en.support.wordpress.com/contact/">Contact us</a> if needed.', 'jetpack' );
282 break;
283 case 'flooded':
284 $message = __( 'Oops! It seems you have several subscriptions pending confirmation. You can confirm or unsubscribe some from the <a href="https://subscribe.wordpress.com/">Subscriptions Manager</a> before adding more.', 'jetpack' );
285 break;
286 case 'spammed':
287 /* translators: %s is a URL */
288 $message = sprintf( __( 'Sorry but this email has been blocked. It has too many subscriptions pending confirmation. Please confirm or unsubscribe some from the <a href="%s">Subscriptions Manager</a>.', 'jetpack' ), 'https://subscribe.wordpress.com/' );
289 break;
290 case 'subscribed':
291 $message = __( 'Hey! You were already subscribed.', 'jetpack' );
292 break;
293 case 'pending':
294 $message = __( 'It seems you already tried to subscribe. We just sent you another email so you can confirm the subscription.', 'jetpack' );
295 break;
296 case 'confirmed':
297 $message = __( 'Cool! You are now subscribed. Now you can check your email for more details and how to manage the subscription.', 'jetpack' );
298 break;
299 }
300
301 $border_color = isset( $themecolors['border'] ) ? " #{$themecolors['border']}" : '';
302
303 $redirect_fragment = self::get_redirect_fragment();
304 printf(
305 '<div id="%1$s" class="jetpack-sub-notification">%3$s</div>',
306 esc_attr( $redirect_fragment ),
307 esc_attr( $border_color ),
308 wp_kses_post( $message )
309 );
310 }
311 }
312
313 /**
314 * Generates the redirect fragment used after form submission.
315 *
316 * @param string $id is the specific id that will appear in the redirect fragment. If none is provided self::$instance_count will be used.
317 */
318 protected static function get_redirect_fragment( $id = null ) {
319 if ( $id === null ) {
320 return 'subscribe-blog' . ( self::$instance_count > 1 ? '-' . self::$instance_count : '' );
321 }
322
323 return 'subscribe-blog-' . $id;
324 }
325
326 /**
327 * Renders a form allowing folks to subscribe to the blog.
328 *
329 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
330 * @param array $instance The settings for the particular instance of the widget.
331 * @param string $subscribe_email The email to use to prefill the form.
332 */
333 public static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
334 $show_only_email_and_button = $instance['show_only_email_and_button'];
335 $show_subscribers_total = (bool) $instance['show_subscribers_total'];
336 $subscribers_total = self::fetch_subscriber_count();
337 $subscribe_text = empty( $instance['show_only_email_and_button'] ) ?
338 stripslashes( $instance['subscribe_text'] ) :
339 false;
340 $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'] ) : '' ) );
341 $source = 'widget';
342 $widget_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : self::$instance_count;
343 $subscribe_button = ! empty( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : $instance['subscribe_button'];
344 $subscribe_placeholder = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
345 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? 'wp-block-button__link ' . $instance['submit_button_classes'] : 'wp-block-button__link';
346 $submit_button_styles = isset( $instance['submit_button_styles'] ) ? $instance['submit_button_styles'] : '';
347 $submit_button_wrapper_styles = isset( $instance['submit_button_wrapper_styles'] ) ? $instance['submit_button_wrapper_styles'] : '';
348 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
349 $email_field_styles = isset( $instance['email_field_styles'] ) ? $instance['email_field_styles'] : '';
350
351 // We need to include those in case Jetpack blocks are disabled
352 require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
353 require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
354 $post_access_level = \Jetpack_Memberships::get_post_access_level();
355
356 if ( self::is_wpcom() && ! self::wpcom_has_status_message() ) {
357 global $current_blog;
358
359 $url = defined( 'SUBSCRIBE_BLOG_URL' ) ? SUBSCRIBE_BLOG_URL : '';
360 $form_id = self::get_redirect_fragment();
361 ?>
362
363 <div class="wp-block-jetpack-subscriptions__container">
364 <form
365 action="<?php echo esc_url( $url ); ?>"
366 method="post"
367 accept-charset="utf-8"
368 data-blog="<?php echo esc_attr( get_current_blog_id() ); ?>"
369 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>"
370 id="<?php echo esc_attr( $form_id ); ?>"
371 >
372 <?php
373 if ( ! $show_only_email_and_button ) {
374 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 echo wpautop( $subscribe_text );
376 }
377 $email_field_id = 'subscribe-field';
378 $email_field_id .= self::$instance_count > 1
379 ? '-' . self::$instance_count
380 : '';
381 $label_field_id = $email_field_id . '-label';
382 ?>
383 <p id="subscribe-email">
384 <label
385 id="<?php echo esc_attr( $label_field_id ); ?>"
386 for="<?php echo esc_attr( $email_field_id ); ?>"
387 class="screen-reader-text"
388 >
389 <?php echo esc_html__( 'Email Address:', 'jetpack' ); ?>
390 </label>
391
392 <?php
393 printf(
394 '<input
395 type="email"
396 name="email"
397 %1$s
398 style="%2$s"
399 placeholder="%3$s"
400 value=""
401 id="%4$s"
402 required
403 />',
404 ( ! empty( $email_field_classes )
405 ? 'class="' . esc_attr( $email_field_classes ) . '"'
406 : ''
407 ),
408 ( ! empty( $email_field_styles )
409 ? esc_attr( $email_field_styles )
410 : 'width: 95%; padding: 1px 10px'
411 ),
412 ( empty( $subscribe_placeholder ) ? esc_attr__( 'Enter your email address', 'jetpack' ) : esc_attr( $subscribe_placeholder ) ),
413 esc_attr( $email_field_id )
414 );
415 ?>
416 </p>
417
418 <p id="subscribe-submit"
419 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
420 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
421 <?php } ?>
422 >
423 <input type="hidden" name="action" value="subscribe"/>
424 <input type="hidden" name="blog_id" value="<?php echo (int) $current_blog->blog_id; ?>"/>
425 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
426 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
427 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
428 <?php wp_nonce_field( 'blogsub_subscribe_' . $current_blog->blog_id, '_wpnonce', false ); ?>
429 <button type="submit"
430 <?php if ( ! empty( $submit_button_classes ) ) { ?>
431 class="<?php echo esc_attr( $submit_button_classes ); ?>"
432 <?php } ?>
433 <?php if ( ! empty( $submit_button_styles ) ) { ?>
434 style="<?php echo esc_attr( $submit_button_styles ); ?>"
435 <?php } ?>
436 >
437 <?php
438 echo wp_kses(
439 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
440 self::$allowed_html_tags_for_submit_button
441 );
442 ?>
443 </button>
444 </p>
445 </form>
446 <?php if ( $show_subscribers_total && $subscribers_total ) { ?>
447 <div class="wp-block-jetpack-subscriptions__subscount">
448 <?php
449 /* translators: %s: number of folks following the blog */
450 echo esc_html( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
451 ?>
452 </div>
453 <?php } ?>
454 </div>
455 <?php
456 }
457
458 if ( self::is_jetpack() ) {
459 /**
460 * Filter the subscription form's ID prefix.
461 *
462 * @module subscriptions
463 *
464 * @since 2.7.0
465 *
466 * @param string subscribe-field Subscription form field prefix.
467 * @param int $widget_id Widget ID.
468 */
469 $subscribe_field_id = apply_filters( 'subscribe_field_id', 'subscribe-field', $widget_id );
470
471 $form_id = self::get_redirect_fragment( $widget_id );
472 ?>
473 <div class="wp-block-jetpack-subscriptions__container">
474 <form action="#" method="post" accept-charset="utf-8" id="<?php echo esc_attr( $form_id ); ?>"
475 data-blog="<?php echo esc_attr( \Jetpack_Options::get_option( 'id' ) ); ?>"
476 data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>" >
477 <?php
478 if ( $subscribe_text && ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Non-sensitive informational output.
479 ?>
480 <div id="subscribe-text"><?php echo wp_kses( wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total ), $subscribe_text ) ), 'post' ); ?></div>
481 <?php
482 }
483
484 if ( ! isset( $_GET['subscribe'] ) || 'success' !== $_GET['subscribe'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display of unsubmitted form.
485 ?>
486 <p id="subscribe-email">
487 <label id="jetpack-subscribe-label"
488 class="screen-reader-text"
489 for="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>">
490 <?php echo ! empty( $subscribe_placeholder ) ? esc_html( $subscribe_placeholder ) : esc_html__( 'Email Address:', 'jetpack' ); ?>
491 </label>
492 <input type="email" name="email" required="required"
493 <?php if ( ! empty( $email_field_classes ) ) { ?>
494 class="<?php echo esc_attr( $email_field_classes ); ?> required"
495 <?php } ?>
496 <?php if ( ! empty( $email_field_styles ) ) { ?>
497 style="<?php echo esc_attr( $email_field_styles ); ?>"
498 <?php } ?>
499 value="<?php echo esc_attr( $subscribe_email ); ?>"
500 id="<?php echo esc_attr( $subscribe_field_id . '-' . $widget_id ); ?>"
501 placeholder="<?php echo esc_attr( $subscribe_placeholder ); ?>"
502 />
503 </p>
504
505 <p id="subscribe-submit"
506 <?php if ( ! empty( $submit_button_wrapper_styles ) ) { ?>
507 style="<?php echo esc_attr( $submit_button_wrapper_styles ); ?>"
508 <?php } ?>
509 >
510 <input type="hidden" name="action" value="subscribe"/>
511 <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
512 <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
513 <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
514 <?php
515 if ( is_user_logged_in() ) {
516 wp_nonce_field( 'blogsub_subscribe_' . get_current_blog_id(), '_wpnonce', false );
517 }
518 ?>
519 <button type="submit"
520 <?php if ( ! empty( $submit_button_classes ) ) { ?>
521 class="<?php echo esc_attr( $submit_button_classes ); ?>"
522 <?php } ?>
523 <?php if ( ! empty( $submit_button_styles ) ) { ?>
524 style="<?php echo esc_attr( $submit_button_styles ); ?>"
525 <?php } ?>
526 name="jetpack_subscriptions_widget"
527 >
528 <?php
529 echo wp_kses(
530 html_entity_decode( $subscribe_button, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ),
531 self::$allowed_html_tags_for_submit_button
532 );
533 ?>
534 </button>
535 </p>
536 <?php } ?>
537 </form>
538 <?php if ( $show_subscribers_total && 0 < $subscribers_total ) { ?>
539 <div class="wp-block-jetpack-subscriptions__subscount">
540 <?php
541 /* translators: %s: number of folks following the blog */
542 echo esc_html( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
543 ?>
544 </div>
545 <?php } ?>
546 </div>
547 <?php
548 }
549 }
550
551 /**
552 * Determines if the current user is subscribed to the blog.
553 *
554 * @return bool Is the person already subscribed.
555 */
556 public static function is_current_user_subscribed() {
557 $subscribed = isset( $_GET['subscribe'] ) && 'success' === $_GET['subscribe']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
558
559 if ( self::is_wpcom() && class_exists( 'Blog_Subscription' ) && class_exists( 'Blog_Subscriber' ) ) {
560 $subscribed = is_user_logged_in() && Blog_Subscription::is_subscribed( new Blog_Subscriber() );
561 }
562
563 return $subscribed;
564 }
565
566 /**
567 * Is this script running in the wordpress.com environment?
568 *
569 * @return bool
570 */
571 public static function is_wpcom() {
572 return defined( 'IS_WPCOM' ) && IS_WPCOM;
573 }
574
575 /**
576 * Is this script running in a self-hosted environment?
577 *
578 * @return bool
579 */
580 public static function is_jetpack() {
581 return ! self::is_wpcom();
582 }
583
584 /**
585 * Used to determine if there is a valid status slug within the wordpress.com environment.
586 *
587 * @return bool
588 */
589 public static function wpcom_has_status_message() {
590 return isset( $_GET['blogsub'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
591 in_array(
592 $_GET['blogsub'], // phpcs:ignore WordPress.Security.NonceVerification.Recommended
593 array(
594 'confirming',
595 'blocked',
596 'flooded',
597 'spammed',
598 'subscribed',
599 'pending',
600 'confirmed',
601 ),
602 true
603 );
604 }
605
606 /**
607 * Determine the amount of folks currently subscribed to the blog.
608 *
609 * @return int
610 */
611 public static function fetch_subscriber_count() {
612 $subs_count = 0;
613 if ( self::is_jetpack() ) {
614 $cache_key = 'wpcom_subscribers_total';
615 $subs_count = get_transient( $cache_key );
616 if ( false === $subs_count || 'failed' === $subs_count['status'] ) {
617 $xml = new Jetpack_IXR_Client();
618 $xml->query( 'jetpack.fetchSubscriberCount' );
619
620 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.
621
622 $subs_count = array(
623 'status' => 'failed',
624 'code' => $xml->getErrorCode(),
625 'message' => $xml->getErrorMessage(),
626 'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
627 );
628 } else {
629 $subs_count = array(
630 'status' => 'success',
631 'value' => $xml->getResponse(),
632 );
633 }
634 set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
635 }
636 return $subs_count['value'];
637 }
638
639 if ( self::is_wpcom() ) {
640 $subs_count = wpcom_reach_total_for_blog();
641 return $subs_count;
642 }
643 }
644
645 /**
646 * Updates a particular instance of a widget when someone saves it in wp-admin.
647 *
648 * @param array $new_instance New widget instance settings.
649 * @param array $old_instance Old widget instance settings.
650 *
651 * @return array
652 */
653 public function update( $new_instance, $old_instance ) {
654 $instance = $old_instance;
655
656 if ( self::is_jetpack() ) {
657 $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
658 $instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
659 $instance['subscribe_button'] = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
660 $instance['success_message'] = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
661 }
662
663 if ( self::is_wpcom() ) {
664 $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
665 $instance['title_following'] = wp_strip_all_tags( stripslashes( $new_instance['title_following'] ) );
666 $instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
667 $instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $new_instance['subscribe_button'] ) );
668 }
669
670 $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
671 $instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
672 $instance['subscribe_text'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
673
674 return $instance;
675 }
676
677 /**
678 * The default args for rendering a subscription form.
679 *
680 * @return array
681 */
682 public static function defaults() {
683 $defaults = array(
684 'show_subscribers_total' => true,
685 'show_only_email_and_button' => false,
686 'include_social_followers' => true,
687 );
688
689 $defaults['title'] = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
690 $defaults['subscribe_text'] = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
691 $defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
692 $defaults['subscribe_button'] = esc_html__( 'Subscribe', 'jetpack' );
693 $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' );
694
695 return $defaults;
696 }
697
698 /**
699 * Renders the widget's options form in wp-admin.
700 *
701 * @param array $instance Widget instance.
702 */
703 public function form( $instance ) {
704 $instance = wp_parse_args( (array) $instance, static::defaults() );
705 $show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
706
707 if ( self::is_wpcom() ) {
708 $title = esc_attr( stripslashes( $instance['title'] ) );
709 $title_following = esc_attr( stripslashes( $instance['title_following'] ) );
710 $subscribe_text = esc_attr( stripslashes( $instance['subscribe_text'] ) );
711 $subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
712 $subscribe_button = esc_attr( stripslashes( $instance['subscribe_button'] ) );
713 $subscribers_total = self::fetch_subscriber_count();
714 }
715
716 if ( self::is_jetpack() ) {
717 $title = stripslashes( $instance['title'] );
718 $subscribe_text = stripslashes( $instance['subscribe_text'] );
719 $subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
720 $subscribe_button = stripslashes( $instance['subscribe_button'] );
721 $success_message = stripslashes( $instance['success_message'] );
722 $subscribers_total = self::fetch_subscriber_count();
723 }
724
725 if ( self::is_wpcom() ) :
726 ?>
727 <p>
728 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
729 <?php esc_html_e( 'Widget title for non-followers:', 'jetpack' ); ?>
730 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
731 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
732 value="<?php echo esc_attr( $title ); ?>"/>
733 </label>
734 </p>
735 <p>
736 <label for="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>">
737 <?php esc_html_e( 'Widget title for followers:', 'jetpack' ); ?>
738 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_following' ) ); ?>"
739 name="<?php echo esc_attr( $this->get_field_name( 'title_following' ) ); ?>" type="text"
740 value="<?php echo esc_attr( $title_following ); ?>"/>
741 </label>
742 </p>
743 <p>
744 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>">
745 <?php esc_html_e( 'Optional text to display to logged in WordPress.com users:', 'jetpack' ); ?>
746 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_logged_in' ) ); ?>"
747 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_logged_in' ) ); ?>"
748 type="text"><?php echo esc_html( $subscribe_logged_in ); ?></textarea>
749 </label>
750 </p>
751 <p>
752 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
753 <?php esc_html_e( 'Optional text to display to non-WordPress.com users:', 'jetpack' ); ?>
754 <textarea style="width: 95%" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
755 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
756 type="text"><?php echo esc_html( $subscribe_text ); ?></textarea>
757 </label>
758 </p>
759 <p>
760 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
761 <?php esc_html_e( 'Follow Button Text:', 'jetpack' ); ?>
762 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
763 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
764 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
765 </label>
766 </p>
767 <p>
768 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
769 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
770 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
771 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
772 <?php
773 /* translators: %s: Number of followers. */
774 echo esc_html( sprintf( _n( 'Show total number of followers? (%s follower)', 'Show total number of followers? (%s followers)', $subscribers_total, 'jetpack' ), number_format_i18n( $subscribers_total ) ) );
775 ?>
776 </label>
777 </p>
778 <?php
779 endif;
780
781 if ( self::is_jetpack() ) :
782 ?>
783 <p>
784 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
785 <?php esc_html_e( 'Widget title:', 'jetpack' ); ?>
786 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
787 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
788 value="<?php echo esc_attr( $title ); ?>"/>
789 </label>
790 </p>
791 <p>
792 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>">
793 <?php esc_html_e( 'Optional text to display to your readers:', 'jetpack' ); ?>
794 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_text' ) ); ?>"
795 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_text' ) ); ?>"
796 rows="3"><?php echo esc_html( $subscribe_text ); ?></textarea>
797 </label>
798 </p>
799 <p>
800 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>">
801 <?php esc_html_e( 'Subscribe Placeholder:', 'jetpack' ); ?>
802 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_placeholder' ) ); ?>"
803 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_placeholder' ) ); ?>" type="text"
804 value="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
805 </label>
806 </p>
807 <p>
808 <label for="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>">
809 <?php esc_html_e( 'Subscribe Button:', 'jetpack' ); ?>
810 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'subscribe_button' ) ); ?>"
811 name="<?php echo esc_attr( $this->get_field_name( 'subscribe_button' ) ); ?>" type="text"
812 value="<?php echo esc_attr( $subscribe_button ); ?>"/>
813 </label>
814 </p>
815 <p>
816 <label for="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>">
817 <?php esc_html_e( 'Success Message Text:', 'jetpack' ); ?>
818 <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'success_message' ) ); ?>"
819 name="<?php echo esc_attr( $this->get_field_name( 'success_message' ) ); ?>"
820 rows="5"><?php echo esc_html( $success_message ); ?></textarea>
821 </label>
822 </p>
823 <p>
824 <label for="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>">
825 <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_subscribers_total' ) ); ?>"
826 name="<?php echo esc_attr( $this->get_field_name( 'show_subscribers_total' ) ); ?>"
827 value="1"<?php echo esc_attr( $show_subscribers_total ); ?> />
828 <?php
829 /* translators: %s: Number of subscribers. */
830 echo esc_html( sprintf( _n( 'Show total number of subscribers? (%s subscriber)', 'Show total number of subscribers? (%s subscribers)', $subscribers_total, 'jetpack' ), $subscribers_total ) );
831 ?>
832 </label>
833 </p>
834 <?php
835 endif;
836 }
837 }
838
839 if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'class_alias' ) ) {
840 class_alias( 'Jetpack_Subscriptions_Widget', 'Blog_Subscription_Widget' );
841 }
842
843 /**
844 * Classname / shortcode tag to use for the Subscriptions widget.
845 *
846 * @return string
847 */
848 function get_jetpack_blog_subscriptions_widget_classname() {
849 return ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ?
850 'Blog_Subscription_Widget' :
851 'Jetpack_Subscriptions_Widget';
852 }
853
854 /**
855 * Subscriptions widget form HTML output.
856 *
857 * @param array $instance Widget instance data.
858 */
859 function jetpack_do_subscription_form( $instance ) {
860 if ( empty( $instance ) || ! is_array( $instance ) ) {
861 $instance = array();
862 }
863
864 if ( empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ) {
865 $instance['show_subscribers_total'] = false;
866 } else {
867 $instance['show_subscribers_total'] = true;
868 }
869
870 // the default behavior is to include the social followers
871 if ( empty( $instance['include_social_followers'] ) || 'true' === $instance['include_social_followers'] ) {
872 $instance['include_social_followers'] = true;
873 } else {
874 $instance['include_social_followers'] = false;
875 }
876
877 $show_only_email_and_button = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false;
878 $submit_button_text = isset( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : '';
879
880 // Build up a string with the submit button's classes and styles and set it on the instance.
881 $submit_button_classes = isset( $instance['submit_button_classes'] ) ? $instance['submit_button_classes'] : '';
882 $email_field_classes = isset( $instance['email_field_classes'] ) ? $instance['email_field_classes'] : '';
883 $style = '';
884 $submit_button_styles = '';
885 $submit_button_wrapper_styles = '';
886 $email_field_styles = '';
887 $success_message = '';
888
889 if ( isset( $instance['custom_background_button_color'] ) && 'undefined' !== $instance['custom_background_button_color'] ) {
890 $submit_button_styles .= 'background: ' . $instance['custom_background_button_color'] . '; ';
891 }
892 if ( isset( $instance['custom_text_button_color'] ) && 'undefined' !== $instance['custom_text_button_color'] ) {
893 $submit_button_styles .= 'color: ' . $instance['custom_text_button_color'] . '; ';
894 }
895 if ( isset( $instance['custom_button_width'] ) && 'undefined' !== $instance['custom_button_width'] ) {
896 $submit_button_wrapper_styles .= 'width: ' . $instance['custom_button_width'] . '; ';
897 $submit_button_wrapper_styles .= 'max-width: 100%; ';
898
899 // Account for custom margins on inline forms.
900 if (
901 ! empty( $instance['custom_spacing'] ) &&
902 ! ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] )
903 ) {
904 $submit_button_styles .= 'width: calc(100% - ' . $instance['custom_spacing'] . 'px); ';
905 } else {
906 $submit_button_styles .= 'width: 100%; ';
907 }
908 }
909
910 if ( isset( $instance['custom_font_size'] ) && 'undefined' !== $instance['custom_font_size'] ) {
911 $style = 'font-size: ' . $instance['custom_font_size'];
912 $style .= is_numeric( $instance['custom_font_size'] ) ? 'px; ' : '; '; // Handle deprecated numeric font size values.
913
914 $submit_button_styles .= $style;
915 $email_field_styles .= $style;
916 }
917 if ( isset( $instance['custom_padding'] ) && 'undefined' !== $instance['custom_padding'] ) {
918 $style = 'padding: ' .
919 $instance['custom_padding'] . 'px ' .
920 round( $instance['custom_padding'] * 1.5 ) . 'px ' .
921 $instance['custom_padding'] . 'px ' .
922 round( $instance['custom_padding'] * 1.5 ) . 'px; ';
923
924 $submit_button_styles .= $style;
925 $email_field_styles .= $style;
926 }
927
928 $button_spacing = 0;
929 if ( ! empty( $instance['custom_spacing'] ) ) {
930 $button_spacing = $instance['custom_spacing'];
931 }
932 if ( isset( $instance['button_on_newline'] ) && 'true' === $instance['button_on_newline'] ) {
933 $submit_button_styles .= 'margin-top: ' . $button_spacing . 'px; ';
934 } else {
935 $submit_button_styles .= 'margin: 0px; '; // Reset Safari's 2px default margin for buttons affecting input and button union
936 $submit_button_styles .= 'margin-left: ' . $button_spacing . 'px; ';
937 }
938
939 if ( isset( $instance['custom_border_radius'] ) && 'undefined' !== $instance['custom_border_radius'] ) {
940 $style = 'border-radius: ' . $instance['custom_border_radius'] . 'px; ';
941 $submit_button_styles .= $style;
942 $email_field_styles .= $style;
943 }
944 if ( isset( $instance['custom_border_weight'] ) && 'undefined' !== $instance['custom_border_weight'] ) {
945 $style = 'border-width: ' . $instance['custom_border_weight'] . 'px; ';
946 $submit_button_styles .= $style;
947 $email_field_styles .= $style;
948 }
949 if ( isset( $instance['custom_border_color'] ) && 'undefined' !== $instance['custom_border_color'] ) {
950 $style =
951 'border-color: ' . $instance['custom_border_color'] . '; ' .
952 'border-style: solid;';
953
954 $submit_button_styles .= $style;
955 $email_field_styles .= $style;
956 }
957 if ( isset( $instance['success_message'] ) && 'undefined' !== $instance['success_message'] ) {
958 $success_message = wp_kses( stripslashes( $instance['success_message'] ), array() );
959 }
960
961 $instance = shortcode_atts(
962 Jetpack_Subscriptions_Widget::defaults(),
963 $instance,
964 'jetpack_subscription_form'
965 );
966
967 // These must come after the call to shortcode_atts().
968 $instance['submit_button_text'] = $submit_button_text;
969 $instance['show_only_email_and_button'] = $show_only_email_and_button;
970 if ( ! empty( $submit_button_classes ) ) {
971 $instance['submit_button_classes'] = $submit_button_classes;
972 }
973 if ( ! empty( $email_field_classes ) ) {
974 $instance['email_field_classes'] = $email_field_classes;
975 }
976
977 if ( ! empty( $submit_button_styles ) ) {
978 $instance['submit_button_styles'] = trim( $submit_button_styles );
979 }
980 if ( ! empty( $submit_button_wrapper_styles ) ) {
981 $instance['submit_button_wrapper_styles'] = trim( $submit_button_wrapper_styles );
982 }
983 if ( ! empty( $email_field_styles ) ) {
984 $instance['email_field_styles'] = trim( $email_field_styles );
985 }
986 if ( ! empty( $success_message ) ) {
987 $instance['success_message'] = trim( $success_message );
988 }
989
990 $args = array(
991 'before_widget' => '<div class="jetpack_subscription_widget">',
992 );
993 ob_start();
994 the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
995 $output = ob_get_clean();
996
997 return $output;
998 }
999
1000 add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
1001 add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
1002
1003 /**
1004 * Register the Subscriptions widget.
1005 */
1006 function jetpack_blog_subscriptions_init() {
1007 register_widget( get_jetpack_blog_subscriptions_widget_classname() );
1008 }
1009
1010 add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' );
1011
1012 /**
1013 * Sets the default value for `subscription_options` site option.
1014 *
1015 * This default value is available across Simple, Atomic and Jetpack sites,
1016 * including the /sites/$site/settings endpoint.
1017 *
1018 * @param array $default Default `subscription_options` array.
1019 * @param string $option Option name.
1020 * @param bool $passed_default Whether `get_option()` passed a default value.
1021 *
1022 * @return array Default value of `subscription_options`.
1023 */
1024 function subscription_options_fallback( $default, $option, $passed_default ) {
1025 if ( $passed_default ) {
1026 return $default;
1027 }
1028
1029 $site_url = get_home_url();
1030 $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
1031
1032 return array(
1033 /* translators: Both %1$s and %2$s is site address */
1034 '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 ),
1035 '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' ),
1036 );
1037 }
1038
1039 add_filter( 'default_option_subscription_options', 'subscription_options_fallback', 10, 3 );
1040