Completed
Push — add/site-importer-ui ( 829ce4...ff4189 )
by
unknown
07:07
created

fetch_subscriber_count()   B

Complexity

Conditions 8
Paths 10

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 10
nop 0
dl 0
loc 36
rs 8.0995
c 0
b 0
f 0
1
<?php
2
3
class Jetpack_Subscriptions_Widget extends WP_Widget {
4
	static $instance_count = 0;
5
6
	function __construct() {
7
		$widget_ops = array(
8
			'classname'                   => 'widget_blog_subscription jetpack_subscription_widget',
9
			'description'                 => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ),
10
			'customize_selective_refresh' => true,
11
		);
12
13
		$name = self::is_jetpack() ?
14
			/** This filter is documented in modules/widgets/facebook-likebox.php */
15
			apply_filters( 'jetpack_widget_name', __( 'Blog Subscriptions', 'jetpack' ) ) :
16
			__( 'Follow Blog', 'jetpack' );
17
18
		parent::__construct(
19
			'blog_subscription',
20
			$name,
21
			$widget_ops
22
		);
23
24 View Code Duplication
		if ( self::is_jetpack() &&
25
		     (
26
			     is_active_widget( false, false, $this->id_base ) ||
27
			     is_active_widget( false, false, 'monster' ) ||
28
			     is_customize_preview()
29
		     )
30
		) {
31
			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
32
		}
33
	}
34
35
	/**
36
	 * Enqueue the form's CSS.
37
	 *
38
	 * @since 4.5.0
39
	 */
40
	function enqueue_style() {
41
		wp_register_style(
42
			'jetpack-subscriptions',
43
			plugins_url( 'subscriptions.css', __FILE__ ),
44
			array(),
45
			JETPACK__VERSION
46
		);
47
		wp_enqueue_style( 'jetpack-subscriptions' );
48
	}
49
50
	/**
51
	 * Renders a full widget either within the context of WordPress widget, or in response to a shortcode.
52
	 *
53
	 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
54
	 * @param array $instance The settings for the particular instance of the widget.
55
	 */
56
	function widget( $args, $instance ) {
57
		if ( self::is_jetpack() &&
58
		     /** This filter is documented in modules/contact-form/grunion-contact-form.php */
59
		     false === apply_filters( 'jetpack_auto_fill_logged_in_user', false )
60
		) {
61
			$subscribe_email = '';
62
		} else {
63
			$current_user = wp_get_current_user();
64
			if ( ! empty( $current_user->user_email ) ) {
65
				$subscribe_email = esc_attr( $current_user->user_email );
66
			} else {
67
				$subscribe_email = '';
68
			}
69
		}
70
71
		$stats_action = self::is_jetpack() ? 'jetpack_subscriptions' : 'follow_blog';
72
		/** This action is documented in modules/widgets/gravatar-profile.php */
73
		do_action( 'jetpack_stats_extra', 'widget_view', $stats_action );
74
75
		$after_widget  = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
76
		$before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
77
		$instance      = wp_parse_args( (array) $instance, $this->defaults() );
78
79
		echo $before_widget;
80
81
		Jetpack_Subscriptions_Widget::$instance_count ++;
82
83
		self::render_widget_title( $args, $instance );
84
85
		self::render_widget_status_messages( $instance );
86
87
		if ( self::is_current_user_subscribed() ) {
88
			self::render_widget_already_subscribed( $instance );
89
		} else {
90
			self::render_widget_subscription_form( $args, $instance, $subscribe_email );
91
		}
92
93
		echo "\n" . $after_widget;
94
	}
95
96
	/**
97
	 * Prints the widget's title. If show_only_email_and_button is true, we will not show a title.
98
	 *
99
	 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
100
	 * @param array $instance The settings for the particular instance of the widget.
101
	 */
102
	static function render_widget_title( $args, $instance ) {
103
		$show_only_email_and_button = $instance['show_only_email_and_button'];
104
		$before_title               = isset( $args['before_title'] ) ? $args['before_title'] : '';
105
		$after_title                = isset( $args['after_title'] ) ? $args['after_title'] : '';
106
		if ( self::is_wpcom() && ! $show_only_email_and_button ) {
107
			if ( self::is_current_user_subscribed() ) {
108 View Code Duplication
				if ( ! empty( $instance['title_following'] ) ) {
109
					echo $before_title . '<label for="subscribe-field' . ( Jetpack_Subscriptions_Widget::$instance_count > 1 ? '-' . Jetpack_Subscriptions_Widget::$instance_count : '' ) . '">' . esc_attr( $instance['title_following'] ) . '</label>' . $after_title . "\n";
110
				}
111 View Code Duplication
			} else {
112
				if ( ! empty( $instance['title'] ) ) {
113
					echo $before_title . '<label for="subscribe-field' . ( Jetpack_Subscriptions_Widget::$instance_count > 1 ? '-' . Jetpack_Subscriptions_Widget::$instance_count : '' ) . '">' . esc_attr( $instance['title'] ) . '</label>' . $after_title . "\n";
114
				}
115
			}
116
		}
117
118
		if ( self::is_jetpack() && empty( $instance['show_only_email_and_button'] ) ) {
119
			echo $args['before_title'] . esc_attr( $instance['title'] ) . $args['after_title'] . "\n";
120
		}
121
	}
122
123
	/**
124
	 * Prints the subscription block's status messages after someone has attempted to subscribe.
125
	 * Either a success message or an error message.
126
	 *
127
	 * @param array $instance The settings for the particular instance of the widget.
128
	 */
129
	static function render_widget_status_messages( $instance ) {
130
		if ( self::is_jetpack() && isset( $_GET['subscribe'] ) ) {
131
			$success_message   = isset( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : '';
132
			$subscribers_total = self::fetch_subscriber_count();
133
			switch ( $_GET['subscribe'] ) :
134
				case 'invalid_email' : ?>
135
                    <p class="error"><?php esc_html_e( 'The email you entered was invalid. Please check and try again.', 'jetpack' ); ?></p>
136
					<?php break;
137
				case 'opted_out' : ?>
138
                    <p class="error"><?php printf( __( 'The email address has opted out of subscription emails. <br /> You can manage your preferences at <a href="%1$s" title="%2$s" target="_blank">subscribe.wordpress.com</a>', 'jetpack' ),
139
							'https://subscribe.wordpress.com/',
140
							__( 'Manage your email preferences.', 'jetpack' )
141
						); ?></p>
142
					<?php break;
143
				case 'already' : ?>
144
                    <p class="error"><?php printf( __( 'You have already subscribed to this site. Please check your inbox. <br /> You can manage your preferences at <a href="%1$s" title="%2$s" target="_blank">subscribe.wordpress.com</a>', 'jetpack' ),
145
							'https://subscribe.wordpress.com/',
146
							__( 'Manage your email preferences.', 'jetpack' )
147
						); ?></p>
148
					<?php break;
149
				case 'success' : ?>
150
                    <div class="success"><?php echo wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total['value'] ), $success_message ) ); ?></div>
151
					<?php break;
152
				default : ?>
153
                    <p class="error"><?php esc_html_e( 'There was an error when subscribing. Please try again.', 'jetpack' ); ?></p>
154
					<?php break;
155
			endswitch;
156
		}
157
158
		if ( self::is_wpcom() && self::wpcom_has_status_message() ) {
159
			global $themecolors;
160
			switch ( $_GET['blogsub'] ) {
161 View Code Duplication
				case 'confirming':
162
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
163
					_e( 'Thanks for subscribing! You&rsquo;ll get an email with a link to confirm your subscription. If you don&rsquo;t get it, please <a href="http://en.support.wordpress.com/contact/">contact us</a>.' );
164
					echo "</div>";
165
					break;
166 View Code Duplication
				case 'blocked':
167
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
168
					_e( 'Subscriptions have been blocked for this email address.' );
169
					echo "</div>";
170
					break;
171 View Code Duplication
				case 'flooded':
172
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
173
					_e( 'You already have several pending email subscriptions. Approve or delete a few through your <a href="https://subscribe.wordpress.com/">Subscription Manager</a> before attempting to subscribe to more blogs.' );
174
					echo "</div>";
175
					break;
176
				case 'spammed':
177
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
178
					echo wp_kses_post( sprintf( __( 'Because there are many pending subscriptions for this email address, we have blocked the subscription. Please <a href="%s">activate or delete</a> pending subscriptions before attempting to subscribe.' ), 'https://subscribe.wordpress.com/' ) );
179
					echo "</div>";
180
					break;
181 View Code Duplication
				case 'subscribed':
182
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
183
					_e( 'You&rsquo;re already subscribed to this site.' );
184
					echo "</div>";
185
					break;
186 View Code Duplication
				case 'pending':
187
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
188
					_e( 'You have a pending subscription already; we just sent you another email. Click the link or <a href="http://en.support.wordpress.com/contact/">contact us</a> if you don&rsquo;t receive it.' );
189
					echo "</div>";
190
					break;
191 View Code Duplication
				case 'confirmed':
192
					echo "<div style='background-color: #{$themecolors['bg']}; border: 1px solid #{$themecolors['border']}; color: #{$themecolors['text']}; padding-left: 5px; padding-right: 5px; margin-bottom: 10px;'>";
193
					_e( 'Congrats, you&rsquo;re subscribed! You&rsquo;ll get an email with the details of your subscription and an unsubscribe link.' );
194
					echo "</div>";
195
					break;
196
			}
197
		}
198
	}
199
200
	/**
201
	 * Renders a message to folks who are already subscribed.
202
	 *
203
	 * @param array $instance The settings for the particular instance of the widget.
204
	 *
205
	 * @return void
206
	 */
207
	static function render_widget_already_subscribed( $instance ) {
208
		if ( self::is_wpcom() ) {
209
			$subscribers_total = self::fetch_subscriber_count();
210
			$edit_subs_url     = 'https://wordpress.com/following/edit/';
211
			if ( function_exists( 'localized_wpcom_url' ) ) {
212
				$edit_subs_url = localized_wpcom_url( http() . '://wordpress.com/following/edit/', get_user_locale() );
213
			}
214
			$show_subscribers_total = (bool) $instance['show_subscribers_total'];
215
			if ( $show_subscribers_total && $subscribers_total > 1 ) :
216
				$subscribers_not_me = $subscribers_total - 1;
217
				/* translators: %s: number of folks following the blog */
218
				?>
219
                <p><?php printf( _n( 'You are following this blog, along with %s other amazing person (<a href="%s">manage</a>).', 'You are following this blog, along with %s other amazing people (<a href="%s">manage</a>).', $subscribers_not_me ), number_format_i18n( $subscribers_not_me ), $edit_subs_url ) ?></p><?php
220
			else :
221
				?>
222
                <p><?php printf( __( 'You are following this blog (<a href="%s">manage</a>).' ), $edit_subs_url ) ?></p><?php
223
			endif;
224
		}
225
	}
226
227
	/**
228
	 * Renders a form allowing folks to subscribe to the blog.
229
	 *
230
	 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
231
	 * @param array $instance The settings for the particular instance of the widget.
232
	 * @param string $subscribe_email The email to use to prefill the form.
233
	 */
234
	static function render_widget_subscription_form( $args, $instance, $subscribe_email ) {
235
		$show_only_email_and_button = $instance['show_only_email_and_button'];
236
		$subscribe_logged_in        = isset( $instance['subscribe_logged_in'] ) ? stripslashes( $instance['subscribe_logged_in'] ) : '';
237
		$show_subscribers_total     = (bool) $instance['show_subscribers_total'];
238
		$subscribe_text             = empty( $instance['show_only_email_and_button'] ) ?
239
			stripslashes( $instance['subscribe_text'] ) :
240
			false;
241
		$referer                    = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
242
		$source                     = 'widget';
243
		$widget_id                  = esc_attr( ! empty( $args['widget_id'] ) ? esc_attr( $args['widget_id'] ) : mt_rand( 450, 550 ) );
244
		$subscribe_button           = stripslashes( $instance['subscribe_button'] );
245
		$subscribers_total          = self::fetch_subscriber_count();
246
		$subscribe_placeholder      = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
247
248
		if ( self::is_wpcom() && ! self::wpcom_has_status_message() ) {
249
			global $current_blog;
250
			$url = defined( 'SUBSCRIBE_BLOG_URL' ) ? SUBSCRIBE_BLOG_URL : '';
251
			?>
252
            <form action="<?php echo $url; ?>" method="post" accept-charset="utf-8"
253
                  id="subscribe-blog<?php if ( Jetpack_Subscriptions_Widget::$instance_count > 1 ) {
254
				      echo '-' . Jetpack_Subscriptions_Widget::$instance_count;
255
			      } ?>">
256
				<?php if ( is_user_logged_in() ) : ?>
257
					<?php
258
					if ( ! $show_only_email_and_button ) {
259
						echo wpautop( $subscribe_logged_in );
260
					}
261 View Code Duplication
					if ( $show_subscribers_total && $subscribers_total ) {
262
						/* translators: %s: number of folks following the blog */
263
						echo wpautop( sprintf( _n( 'Join %s other follower', 'Join %s other followers', $subscribers_total ), number_format_i18n( $subscribers_total ) ) );
264
					}
265
					?>
266
				<?php else : ?>
267
					<?php
268
					if ( ! $show_only_email_and_button ) {
269
						echo wpautop( $subscribe_text );
270
					}
271 View Code Duplication
					if ( $show_subscribers_total && $subscribers_total ) {
272
						/* translators: %s: number of folks following the blog */
273
						echo wpautop( sprintf( _n( 'Join %s other follower', 'Join %s other followers', $subscribers_total ), number_format_i18n( $subscribers_total ) ) );
274
					}
275
					?>
276
                    <p><input type="text" name="email" style="width: 95%; padding: 1px 2px"
277
                              placeholder="<?php esc_attr_e( 'Enter your email address' ); ?>" value=""
278
                              id="subscribe-field<?php if ( Jetpack_Subscriptions_Widget::$instance_count > 1 ) {
279
						          echo '-' . Jetpack_Subscriptions_Widget::$instance_count;
280
					          } ?>"/></p>
281
				<?php endif; ?>
282
283
                <p>
284
                    <input type="hidden" name="action" value="subscribe"/>
285
                    <input type="hidden" name="blog_id" value="<?php echo (int) $current_blog->blog_id; ?>"/>
286
                    <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
287
                    <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
288
                    <input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $widget_id ); ?>"/>
289
					<?php wp_nonce_field( 'blogsub_subscribe_' . $current_blog->blog_id, '_wpnonce', false ); ?>
290
                    <input type="submit" value="<?php echo esc_attr( $subscribe_button ); ?>"/>
291
                </p>
292
            </form>
293
			<?php
294
		}
295
296
		if ( self::is_jetpack() ) {
297
			/**
298
			 * Filter the subscription form's ID prefix.
299
			 *
300
			 * @module subscriptions
301
			 *
302
			 * @since 2.7.0
303
			 *
304
			 * @param string subscribe-field Subscription form field prefix.
305
			 * @param int $widget_id Widget ID.
306
			 */
307
			$subscribe_field_id = apply_filters( 'subscribe_field_id', 'subscribe-field', $widget_id );
308
			?>
309
            <form action="#" method="post" accept-charset="utf-8" id="subscribe-blog-<?php echo $widget_id; ?>">
310
				<?php
311
				if ( $subscribe_text && ( ! isset ( $_GET['subscribe'] ) || 'success' != $_GET['subscribe'] ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $subscribe_text of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
312
					?>
313
                    <div id="subscribe-text"><?php echo wpautop( str_replace( '[total-subscribers]', number_format_i18n( $subscribers_total['value'] ), $subscribe_text ) ); ?></div><?php
314
				}
315
316
				if ( $show_subscribers_total && 0 < $subscribers_total['value'] ) {
317
					/* translators: %s: number of folks following the blog */
318
					echo wpautop( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total['value'], 'jetpack' ), number_format_i18n( $subscribers_total['value'] ) ) );
319
				}
320
				if ( ! isset ( $_GET['subscribe'] ) || 'success' != $_GET['subscribe'] ) { ?>
321
                    <p id="subscribe-email">
322
                        <label id="jetpack-subscribe-label"
323
                               for="<?php echo esc_attr( $subscribe_field_id ) . '-' . esc_attr( $widget_id ); ?>">
324
							<?php echo ! empty( $subscribe_placeholder ) ? esc_html( $subscribe_placeholder ) : esc_html__( 'Email Address:', 'jetpack' ); ?>
325
                        </label>
326
                        <input type="email" name="email" required="required" class="required"
327
                               value="<?php echo esc_attr( $subscribe_email ); ?>"
328
                               id="<?php echo esc_attr( $subscribe_field_id ) . '-' . esc_attr( $widget_id ); ?>"
329
                               placeholder="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
330
                    </p>
331
332
                    <p id="subscribe-submit">
333
                        <input type="hidden" name="action" value="subscribe"/>
334
                        <input type="hidden" name="source" value="<?php echo esc_url( $referer ); ?>"/>
335
                        <input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
336
                        <input type="hidden" name="redirect_fragment" value="<?php echo $widget_id; ?>"/>
337
						<?php
338
						if ( is_user_logged_in() ) {
339
							wp_nonce_field( 'blogsub_subscribe_' . get_current_blog_id(), '_wpnonce', false );
340
						}
341
						?>
342
                        <input type="submit" value="<?php echo esc_attr( $subscribe_button ); ?>"
343
                               name="jetpack_subscriptions_widget"/>
344
                    </p>
345
				<?php } ?>
346
            </form>
347
348
            <script>
349
				/*
350
				Custom functionality for safari and IE
351
				 */
352
				(function (d) {
353
					// In case the placeholder functionality is available we remove labels
354
					if (('placeholder' in d.createElement('input'))) {
355
						var label = d.querySelector('label[for=subscribe-field-<?php echo $widget_id; ?>]');
356
						label.style.clip = 'rect(1px, 1px, 1px, 1px)';
357
						label.style.position = 'absolute';
358
						label.style.height = '1px';
359
						label.style.width = '1px';
360
						label.style.overflow = 'hidden';
361
					}
362
363
					// Make sure the email value is filled in before allowing submit
364
					var form = d.getElementById('subscribe-blog-<?php echo $widget_id; ?>'),
365
						input = d.getElementById('<?php echo esc_attr( $subscribe_field_id ) . '-' . esc_attr( $widget_id ); ?>'),
366
						handler = function (event) {
367
							if ('' === input.value) {
368
								input.focus();
369
370
								if (event.preventDefault) {
371
									event.preventDefault();
372
								}
373
374
								return false;
375
							}
376
						};
377
378
					if (window.addEventListener) {
379
						form.addEventListener('submit', handler, false);
380
					} else {
381
						form.attachEvent('onsubmit', handler);
382
					}
383
				})(document);
384
            </script>
385
		<?php }
386
	}
387
388
	/**
389
	 * Determines if the current user is subscribed to the blog.
390
	 *
391
	 * @return bool Is the person already subscribed.
392
	 */
393
	static function is_current_user_subscribed() {
394
		$subscribed = isset( $_GET['subscribe'] ) && 'success' == $_GET['subscribe'];
395
396
		if ( self::is_wpcom() && class_exists( 'Blog_Subscription' ) && class_exists( 'Blog_Subscriber' ) ) {
397
			$subscribed = is_user_logged_in() && Blog_Subscription::is_subscribed( new Blog_Subscriber() );
398
		}
399
400
		return $subscribed;
401
	}
402
403
	/**
404
	 * Is this script running in the wordpress.com environment?
405
	 *
406
	 * @return bool
407
	 */
408
	static function is_wpcom() {
409
		return defined( 'IS_WPCOM' ) && IS_WPCOM;
410
	}
411
412
	/**
413
	 * Is this script running in a self-hosted environment?
414
	 *
415
	 * @return bool
416
	 */
417
	static function is_jetpack() {
418
		return ! self::is_wpcom();
419
	}
420
421
	/**
422
	 * Used to determine if there is a valid status slug within the wordpress.com environment.
423
	 *
424
	 * @return bool
425
	 */
426
	static function wpcom_has_status_message() {
427
		return isset( $_GET['blogsub'] ) &&
428
		       in_array(
429
			       $_GET['blogsub'],
430
			       array(
431
				       'confirming',
432
				       'blocked',
433
				       'flooded',
434
				       'spammed',
435
				       'subscribed',
436
				       'pending',
437
				       'confirmed',
438
			       )
439
		       );
440
	}
441
442
	/**
443
	 * Determine the amount of folks currently subscribed to the blog.
444
	 *
445
	 * @return int|array
446
	 */
447
	static function fetch_subscriber_count() {
448
		$subs_count = 0;
449
450
		if ( self::is_jetpack() ) {
451
			$subs_count = get_transient( 'wpcom_subscribers_total' );
452
			if ( false === $subs_count || 'failed' == $subs_count['status'] ) {
453
				Jetpack::load_xml_rpc_client();
454
455
				$xml = new Jetpack_IXR_Client( array( 'user_id' => JETPACK_MASTER_USER, ) );
456
457
				$xml->query( 'jetpack.fetchSubscriberCount' );
458
459
				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
460
					$subs_count = array(
461
						'status'  => 'failed',
462
						'code'    => $xml->getErrorCode(),
463
						'message' => $xml->getErrorMessage(),
464
						'value'   => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : 0,
465
					);
466
				} else {
467
					$subs_count = array(
468
						'status' => 'success',
469
						'value'  => $xml->getResponse(),
470
					);
471
				}
472
473
				set_transient( 'wpcom_subscribers_total', $subs_count, 3600 ); // try to cache the result for at least 1 hour
474
			}
475
		}
476
477
		if ( self::is_wpcom() && function_exists( 'wpcom_reach_total_for_blog' ) ) {
478
			$subs_count = wpcom_reach_total_for_blog();
479
		}
480
481
		return $subs_count;
482
	}
483
484
	/**
485
	 * Updates a particular instance of a widget when someone saves it in wp-admin.
486
	 *
487
	 * @param array $new_instance
488
	 * @param array $old_instance
489
	 *
490
	 * @return array
491
	 */
492
	function update( $new_instance, $old_instance ) {
493
		$instance = $old_instance;
494
495
		if ( self::is_jetpack() ) {
496
			$instance['title']                 = wp_kses( stripslashes( $new_instance['title'] ), array() );
497
			$instance['subscribe_placeholder'] = wp_kses( stripslashes( $new_instance['subscribe_placeholder'] ), array() );
498
			$instance['subscribe_button']      = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() );
499
			$instance['success_message']       = wp_kses( stripslashes( $new_instance['success_message'] ), array() );
500
		}
501
502
		if ( self::is_wpcom() ) {
503
			$instance['title']               = strip_tags( stripslashes( $new_instance['title'] ) );
504
			$instance['title_following']     = strip_tags( stripslashes( $new_instance['title_following'] ) );
505
			$instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) );
506
			$instance['subscribe_button']    = strip_tags( stripslashes( $new_instance['subscribe_button'] ) );
507
		}
508
509
		$instance['show_subscribers_total']     = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
510
		$instance['show_only_email_and_button'] = isset( $new_instance['show_only_email_and_button'] ) && $new_instance['show_only_email_and_button'];
511
		$instance['subscribe_text']             = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) );
512
513
		return $instance;
514
	}
515
516
	/**
517
	 * The default args for rendering a subscription form.
518
	 *
519
	 * @return array
520
	 */
521
	static function defaults() {
522
		$defaults = array(
523
			'show_subscribers_total'     => true,
524
			'show_only_email_and_button' => false
525
		);
526
527
		if ( self::is_jetpack() ) {
528
			$defaults['title']                 = esc_html__( 'Subscribe to Blog via Email', 'jetpack' );
529
			$defaults['subscribe_text']        = esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' );
530
			$defaults['subscribe_placeholder'] = esc_html__( 'Email Address', 'jetpack' );
531
			$defaults['subscribe_button']      = esc_html__( 'Subscribe', 'jetpack' );
532
			$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' );
533
		}
534
535
		if ( self::is_wpcom() ) {
536
			$defaults['title']               = __( 'Follow Blog via Email' );
537
			$defaults['title_following']     = __( 'You are following this blog' );
538
			$defaults['subscribe_text']      = __( 'Enter your email address to follow this blog and receive notifications of new posts by email.' );
539
			$defaults['subscribe_button']    = __( 'Follow' );
540
			$defaults['subscribe_logged_in'] = __( 'Click to follow this blog and receive notifications of new posts by email.' );
541
		}
542
543
		return $defaults;
544
	}
545
546
	/**
547
	 * Renders the widget's options form in wp-admin.
548
	 *
549
	 * @param array $instance
550
	 */
551
	function form( $instance ) {
552
		$instance               = wp_parse_args( (array) $instance, $this->defaults() );
553
		$show_subscribers_total = checked( $instance['show_subscribers_total'], true, false );
554
555
556
		if ( self::is_wpcom() ) {
557
			$title               = esc_attr( stripslashes( $instance['title'] ) );
558
			$title_following     = esc_attr( stripslashes( $instance['title_following'] ) );
559
			$subscribe_text      = esc_attr( stripslashes( $instance['subscribe_text'] ) );
560
			$subscribe_logged_in = esc_attr( stripslashes( $instance['subscribe_logged_in'] ) );
561
			$subscribe_button    = esc_attr( stripslashes( $instance['subscribe_button'] ) );
562
			$subscribers_total   = self::fetch_subscriber_count();
563
		}
564
565
		if ( self::is_jetpack() ) {
566
			$title                 = stripslashes( $instance['title'] );
567
			$subscribe_text        = stripslashes( $instance['subscribe_text'] );
568
			$subscribe_placeholder = stripslashes( $instance['subscribe_placeholder'] );
569
			$subscribe_button      = stripslashes( $instance['subscribe_button'] );
570
			$success_message       = stripslashes( $instance['success_message'] );
571
			$subs_fetch            = self::fetch_subscriber_count();
572
			if ( 'failed' == $subs_fetch['status'] ) {
573
				printf( '<div class="error inline"><p>%s: %s</p></div>', esc_html( $subs_fetch['code'] ), esc_html( $subs_fetch['message'] ) );
574
			}
575
			$subscribers_total = number_format_i18n( $subs_fetch['value'] );
576
		}
577
578
		if ( self::is_wpcom() ) : ?>
579
            <p>
580
                <label for="<?php echo $this->get_field_id( 'title' ); ?>">
581
					<?php _e( 'Widget title for non-followers:' ); ?>
582
                    <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
583
                           name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
584
                           value="<?php echo $title; ?>"/>
0 ignored issues
show
Bug introduced by
The variable $title does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
585
                </label>
586
            </p>
587
            <p>
588
                <label for="<?php echo $this->get_field_id( 'title_following' ); ?>">
589
					<?php _e( 'Widget title for followers:' ); ?>
590
                    <input class="widefat" id="<?php echo $this->get_field_id( 'title_following' ); ?>"
591
                           name="<?php echo $this->get_field_name( 'title_following' ); ?>" type="text"
592
                           value="<?php echo $title_following; ?>"/>
0 ignored issues
show
Bug introduced by
The variable $title_following does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
593
                </label>
594
            </p>
595
            <p>
596
                <label for="<?php echo $this->get_field_id( 'subscribe_logged_in' ); ?>">
597
					<?php _e( 'Optional text to display to logged in WordPress.com users:' ); ?>
598
                    <textarea style="width: 95%" id="<?php echo $this->get_field_id( 'subscribe_logged_in' ); ?>"
599
                              name="<?php echo $this->get_field_name( 'subscribe_logged_in' ); ?>"
600
                              type="text"><?php echo $subscribe_logged_in; ?></textarea>
0 ignored issues
show
Bug introduced by
The variable $subscribe_logged_in does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
601
                </label>
602
            </p>
603
            <p>
604
                <label for="<?php echo $this->get_field_id( 'subscribe_text' ); ?>">
605
					<?php _e( 'Optional text to display to non-WordPress.com users:' ); ?>
606
                    <textarea style="width: 95%" id="<?php echo $this->get_field_id( 'subscribe_text' ); ?>"
607
                              name="<?php echo $this->get_field_name( 'subscribe_text' ); ?>"
608
                              type="text"><?php echo $subscribe_text; ?></textarea>
0 ignored issues
show
Bug introduced by
The variable $subscribe_text does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
609
                </label>
610
            </p>
611
            <p>
612
                <label for="<?php echo $this->get_field_id( 'subscribe_button' ); ?>">
613
					<?php _e( 'Follow Button Text:' ); ?>
614
                    <input class="widefat" id="<?php echo $this->get_field_id( 'subscribe_button' ); ?>"
615
                           name="<?php echo $this->get_field_name( 'subscribe_button' ); ?>" type="text"
616
                           value="<?php echo $subscribe_button; ?>"/>
0 ignored issues
show
Bug introduced by
The variable $subscribe_button does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
617
                </label>
618
            </p>
619
            <p>
620
                <label for="<?php echo $this->get_field_id( 'show_subscribers_total' ); ?>">
621
                    <input type="checkbox" id="<?php echo $this->get_field_id( 'show_subscribers_total' ); ?>"
622
                           name="<?php echo $this->get_field_name( 'show_subscribers_total' ); ?>"
623
                           value="1"<?php echo $show_subscribers_total; ?> />
624
					<?php echo esc_html( sprintf( _n( 'Show total number of followers? (%s follower)', 'Show total number of followers? (%s followers)', $subscribers_total ), number_format_i18n( $subscribers_total ) ) ); ?>
0 ignored issues
show
Bug introduced by
The variable $subscribers_total does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
625
                </label>
626
            </p>
627
		<?php endif;
628
629
		if ( self::is_jetpack() ) : ?>
630
            <p>
631
                <label for="<?php echo $this->get_field_id( 'title' ); ?>">
632
					<?php _e( 'Widget title:', 'jetpack' ); ?>
633
                    <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
634
                           name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
635
                           value="<?php echo esc_attr( $title ); ?>"/>
636
                </label>
637
            </p>
638
            <p>
639
                <label for="<?php echo $this->get_field_id( 'subscribe_text' ); ?>">
640
					<?php _e( 'Optional text to display to your readers:', 'jetpack' ); ?>
641
                    <textarea class="widefat" id="<?php echo $this->get_field_id( 'subscribe_text' ); ?>"
642
                              name="<?php echo $this->get_field_name( 'subscribe_text' ); ?>"
643
                              rows="3"><?php echo esc_html( $subscribe_text ); ?></textarea>
644
                </label>
645
            </p>
646
            <p>
647
                <label for="<?php echo $this->get_field_id( 'subscribe_placeholder' ); ?>">
648
					<?php esc_html_e( 'Subscribe Placeholder:', 'jetpack' ); ?>
649
                    <input class="widefat" id="<?php echo $this->get_field_id( 'subscribe_placeholder' ); ?>"
650
                           name="<?php echo $this->get_field_name( 'subscribe_placeholder' ); ?>" type="text"
651
                           value="<?php echo esc_attr( $subscribe_placeholder ); ?>"/>
0 ignored issues
show
Bug introduced by
The variable $subscribe_placeholder does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
652
                </label>
653
            </p>
654
            <p>
655
                <label for="<?php echo $this->get_field_id( 'subscribe_button' ); ?>">
656
					<?php _e( 'Subscribe Button:', 'jetpack' ); ?>
657
                    <input class="widefat" id="<?php echo $this->get_field_id( 'subscribe_button' ); ?>"
658
                           name="<?php echo $this->get_field_name( 'subscribe_button' ); ?>" type="text"
659
                           value="<?php echo esc_attr( $subscribe_button ); ?>"/>
660
                </label>
661
            </p>
662
            <p>
663
                <label for="<?php echo $this->get_field_id( 'success_message' ); ?>">
664
					<?php _e( 'Success Message Text:', 'jetpack' ); ?>
665
                    <textarea class="widefat" id="<?php echo $this->get_field_id( 'success_message' ); ?>"
666
                              name="<?php echo $this->get_field_name( 'success_message' ); ?>"
667
                              rows="5"><?php echo esc_html( $success_message ); ?></textarea>
0 ignored issues
show
Bug introduced by
The variable $success_message does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
668
                </label>
669
            </p>
670
            <p>
671
                <label for="<?php echo $this->get_field_id( 'show_subscribers_total' ); ?>">
672
                    <input type="checkbox" id="<?php echo $this->get_field_id( 'show_subscribers_total' ); ?>"
673
                           name="<?php echo $this->get_field_name( 'show_subscribers_total' ); ?>"
674
                           value="1"<?php echo $show_subscribers_total; ?> />
675
					<?php echo esc_html( sprintf( _n( 'Show total number of subscribers? (%s subscriber)', 'Show total number of subscribers? (%s subscribers)', $subscribers_total, 'jetpack' ), $subscribers_total ) ); ?>
676
                </label>
677
            </p>
678
		<?php endif;
679
	}
680
}
681
682
if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'class_alias' ) ) {
683
	class_alias( 'Jetpack_Subscriptions_Widget', 'Blog_Subscription_Widget' );
684
}
685
686
function get_jetpack_blog_subscriptions_widget_classname() {
687
	return ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ?
688
		'Blog_Subscription_Widget' :
689
		'Jetpack_Subscriptions_Widget';
690
}
691
692
function jetpack_do_subscription_form( $instance ) {
693
	if ( empty( $instance ) || ! is_array( $instance ) ) {
694
		$instance = array();
695
	}
696
	$instance['show_subscribers_total'] = empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ? false : true;
697
	$show_only_email_and_button         = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false;
698
699
	$instance = shortcode_atts(
700
		Jetpack_Subscriptions_Widget::defaults(),
701
		$instance,
702
		'jetpack_subscription_form'
703
	);
704
705
	$instance['show_only_email_and_button'] = $show_only_email_and_button;
706
707
	$args = array(
708
		'before_widget' => '<div class="jetpack_subscription_widget">',
709
	);
710
	ob_start();
711
	the_widget( get_jetpack_blog_subscriptions_widget_classname(), $instance, $args );
712
	$output = ob_get_clean();
713
714
	return $output;
715
}
716
717
add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' );
718
add_shortcode( 'blog_subscription_form', 'jetpack_do_subscription_form' );
719
720
function jetpack_blog_subscriptions_init() {
721
	register_widget( get_jetpack_blog_subscriptions_widget_classname() );
722
}
723
724
add_action( 'widgets_init', 'jetpack_blog_subscriptions_init' );
725
726
function jetpack_register_subscriptions_block() {
727
	jetpack_register_block( 'subscriptions' );
728
}
729
730
add_action( 'init', 'jetpack_register_subscriptions_block' );
731