PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.2
Jetpack – WP Security, Backup, Speed, & Growth v8.2
16.2-beta 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 All 501 releases
← All changes | modules/subscriptions.php +236 -394 14.0.18.2 View file →
@@ -1,36 +1,20 @@
1 -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName)
1 +<?php
2 2 /**
3 - * Module Name: Newsletter
3 + * Module Name: Subscriptions
4 4 * Module Description: Let visitors subscribe to new posts and comments via email
5 5 * Sort Order: 9
6 6 * Recommendation Order: 8
7 7 * First Introduced: 1.2
8 8 * Requires Connection: Yes
9 - * Requires User Connection: Yes
10 9 * Auto Activate: No
11 10 * Module Tags: Social
12 11 * Feature: Engagement
13 - * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup, newsletter, creator
12 + * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup
14 13 */
15 14
16 -// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
17 -
18 -use Automattic\Jetpack\Admin_UI\Admin_Menu;
19 -use Automattic\Jetpack\Connection\Manager as Connection_Manager;
20 -use Automattic\Jetpack\Connection\XMLRPC_Async_Call;
21 -use Automattic\Jetpack\Redirect;
22 -use Automattic\Jetpack\Status;
23 -use Automattic\Jetpack\Status\Host;
24 -
25 15 add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' );
26 16
27 -// Loads the User Content Link Redirection feature.
28 -require_once __DIR__ . '/subscriptions/jetpack-user-content-link-redirection.php';
29 -
30 -/**
31 - * Loads the Subscriptions module.
32 - */
33 17 function jetpack_subscriptions_load() {
34 18 Jetpack::enable_module_configurable( __FILE__ );
35 19 }
36 20
@@ -44,13 +28,13 @@
44 28 function jetpack_subscriptions_cherry_pick_server_data() {
45 29 $data = array();
46 30
47 31 foreach ( $_SERVER as $key => $value ) {
48 - if ( ! is_string( $value ) || str_starts_with( $key, 'HTTP_COOKIE' ) ) {
32 + if ( ! is_string( $value ) || 0 === strpos( $key, 'HTTP_COOKIE' ) ) {
49 33 continue;
50 34 }
51 35
52 - if ( str_starts_with( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
36 + if ( 0 === strpos( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
53 37 $data[ $key ] = $value;
54 38 }
55 39 }
56 40
@@ -56,49 +40,32 @@
56 40
57 41 return $data;
58 42 }
59 43
60 -/**
61 - * Main class file for the Subscriptions module.
62 - */
63 44 class Jetpack_Subscriptions {
64 - /**
65 - * Whether Jetpack has been instantiated or not.
66 - *
67 - * @var bool
68 - */
69 45 public $jetpack = false;
70 46
71 - /**
72 - * Hash of the siteurl option.
73 - *
74 - * @var string
75 - */
76 47 public static $hash;
77 48
78 49 /**
79 50 * Singleton
80 - *
81 51 * @static
82 52 */
83 - public static function init() {
53 + static function init() {
84 54 static $instance = false;
85 55
86 - if ( ! $instance ) {
87 - $instance = new Jetpack_Subscriptions();
56 + if ( !$instance ) {
57 + $instance = new Jetpack_Subscriptions;
88 58 }
89 59
90 60 return $instance;
91 61 }
92 62
93 - /**
94 - * Jetpack_Subscriptions constructor.
95 - */
96 - public function __construct() {
63 + function __construct() {
97 64 $this->jetpack = Jetpack::init();
98 65
99 66 // Don't use COOKIEHASH as it could be shared across installs && is non-unique in multisite.
100 - // @see: https://twitter.com/nacin/status/378246957451333632 .
67 + // @see: https://twitter.com/nacin/status/378246957451333632
101 68 self::$hash = md5( get_option( 'siteurl' ) );
102 69
103 70 add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
104 71
@@ -103,23 +70,22 @@
103 70 add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
104 71
105 72 // @todo remove sync from subscriptions and move elsewhere...
106 73
107 - // Add Configuration Page.
74 + // Add Configuration Page
108 75 add_action( 'admin_init', array( $this, 'configure' ) );
109 76
110 - // Catch subscription widget submits.
111 - if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce checked in widget_submit() for logged in users.
77 + // Catch subscription widget submits
78 + if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) )
112 79 add_action( 'template_redirect', array( $this, 'widget_submit' ) );
113 - }
114 80
115 - // Set up the comment subscription checkboxes.
81 + // Set up the comment subscription checkboxes
116 82 add_filter( 'comment_form_submit_field', array( $this, 'comment_subscribe_init' ), 10, 2 );
117 83
118 84 // Catch comment posts and check for subscriptions.
119 85 add_action( 'comment_post', array( $this, 'comment_subscribe_submit' ), 50, 2 );
120 86
121 - // Adds post meta checkbox in the post submit metabox.
87 + // Adds post meta checkbox in the post submit metabox
122 88 add_action( 'post_submitbox_misc_actions', array( $this, 'subscription_post_page_metabox' ) );
123 89
124 90 add_action( 'transition_post_status', array( $this, 'maybe_send_subscription_email' ), 10, 3 );
125 91
@@ -127,27 +93,9 @@
127 93
128 94 add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 18, 1 );
129 95
130 96 // Set "social_notifications_subscribe" option during the first-time activation.
131 - add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_social_notifications_subscribe' ) );
132 -
133 - // Hide subscription messaging in Publish panel for posts that were published in the past
134 - add_action( 'init', array( $this, 'register_post_meta' ), 20 );
135 - add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 );
136 -
137 - // Add Subscribers menu to Jetpack navigation.
138 - add_action( 'jetpack_admin_menu', array( $this, 'add_subscribers_menu' ) );
139 -
140 - // Customize the configuration URL to lead to the Subscriptions settings.
141 - add_filter(
142 - 'jetpack_module_configuration_url_subscriptions',
143 - function () {
144 - return Jetpack::admin_url( array( 'page' => 'jetpack#/newsletter' ) );
145 - }
146 - );
147 -
148 - // Track categories created through the category editor page
149 - add_action( 'wp_ajax_add-tag', array( $this, 'track_newsletter_category_creation' ), 1 );
97 + add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_social_notifications_subscribe' ) );
150 98 }
151 99
152 100 /**
153 101 * Jetpack_Subscriptions::xmlrpc_methods()
@@ -152,12 +100,11 @@
152 100 /**
153 101 * Jetpack_Subscriptions::xmlrpc_methods()
154 102 *
155 103 * Register subscriptions methods with the Jetpack XML-RPC server.
156 - *
157 - * @param array $methods Methods being registered.
104 + * @param array $methods
158 105 */
159 - public function xmlrpc_methods( $methods ) {
106 + function xmlrpc_methods( $methods ) {
160 107 return array_merge(
161 108 $methods,
162 109 array(
163 110 'jetpack.subscriptions.subscribe' => array( $this, 'subscribe' ),
@@ -164,13 +111,13 @@
164 111 )
165 112 );
166 113 }
167 114
168 - /**
115 + /*
169 116 * Disable Subscribe on Single Post
170 117 * Register post meta
171 118 */
172 - public function subscription_post_page_metabox() {
119 + function subscription_post_page_metabox() {
173 120 if (
174 121 /**
175 122 * Filter whether or not to show the per-post subscription option.
176 123 *
@@ -179,9 +126,10 @@
179 126 * @since 3.7.0
180 127 *
181 128 * @param bool true = show checkbox option on all new posts | false = hide the option.
182 129 */
183 - ! apply_filters( 'jetpack_allow_per_post_subscriptions', false ) ) {
130 + ! apply_filters( 'jetpack_allow_per_post_subscriptions', false ) )
131 + {
184 132 return;
185 133 }
186 134
187 135 if ( has_filter( 'jetpack_subscriptions_exclude_these_categories' ) || has_filter( 'jetpack_subscriptions_include_only_these_categories' ) ) {
@@ -190,19 +138,18 @@
190 138
191 139 global $post;
192 140 $disable_subscribe_value = get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true );
193 141 // only show checkbox if post hasn't been published and is a 'post' post type.
194 - if ( get_post_status( $post->ID ) !== 'publish' && get_post_type( $post->ID ) === 'post' ) :
195 - // Nonce it.
142 + if ( get_post_status( $post->ID ) !== 'publish' && get_post_type( $post->ID ) == 'post' ) :
143 + // Nonce it
196 144 wp_nonce_field( 'disable_subscribe', 'disable_subscribe_nonce' );
197 145 ?>
198 146 <div class="misc-pub-section">
199 - <label for="_jetpack_dont_email_post_to_subs"><?php esc_html_e( 'Jetpack Subscriptions:', 'jetpack' ); ?></label><br>
147 + <label for="_jetpack_dont_email_post_to_subs"><?php _e( 'Jetpack Subscriptions:', 'jetpack' ); ?></label><br>
200 148 <input type="checkbox" name="_jetpack_dont_email_post_to_subs" id="jetpack-per-post-subscribe" value="1" <?php checked( $disable_subscribe_value, 1, true ); ?> />
201 - <?php esc_html_e( 'Don&#8217;t send this to subscribers', 'jetpack' ); ?>
149 + <?php _e( 'Don&#8217;t send this to subscribers', 'jetpack' ); ?>
202 150 </div>
203 - <?php
204 - endif;
151 + <?php endif;
205 152 }
206 153
207 154 /**
208 155 * Checks whether or not the post should be emailed to subscribers
@@ -213,38 +160,32 @@
213 160 * - Existence of the per-post checkbox option
214 161 *
215 162 * Only one of these can be used at any given time.
216 163 *
217 - * @param string $new_status Tthe "new" post status of the transition when saved.
218 - * @param string $old_status The "old" post status of the transition when saved.
219 - * @param object $post obj The post object.
164 + * @param $new_status string - the "new" post status of the transition when saved
165 + * @param $old_status string - the "old" post status of the transition when saved
166 + * @param $post obj - The post object
220 167 */
221 - public function maybe_send_subscription_email( $new_status, $old_status, $post ) {
168 + function maybe_send_subscription_email( $new_status, $old_status, $post ) {
222 169
223 170 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
224 171 return;
225 172 }
226 173
227 - // Make sure that the checkbox is preseved.
228 - if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WP Core doesn't unslash or sanitize nonces either.
174 + // Make sure that the checkbox is preseved
175 + if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) {
229 176 $set_checkbox = isset( $_POST['_jetpack_dont_email_post_to_subs'] ) ? 1 : 0;
230 177 update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', $set_checkbox );
231 178 }
232 179 }
233 180
234 - /**
235 - * Message used when publishing a post.
236 - *
237 - * @param array $messages Message array for a post.
238 - */
239 - public function update_published_message( $messages ) {
181 + function update_published_message( $messages ) {
240 182 global $post;
241 183 if ( ! $this->should_email_post_to_subscribers( $post ) ) {
242 184 return $messages;
243 185 }
244 186
245 - $view_post_link_html = sprintf(
246 - ' <a href="%1$s">%2$s</a>',
187 + $view_post_link_html = sprintf( ' <a href="%1$s">%2$s</a>',
247 188 esc_url( get_permalink( $post ) ),
248 189 __( 'View post', 'jetpack' )
249 190 );
250 191
@@ -250,17 +191,12 @@
250 191
251 192 $messages['post'][6] = sprintf(
252 193 /* translators: Message shown after a post is published */
253 194 esc_html__( 'Post published and sending emails to subscribers.', 'jetpack' )
254 - ) . $view_post_link_html;
195 + ) . $view_post_link_html;
255 196 return $messages;
256 197 }
257 198
258 - /**
259 - * Determine if a post should notifiy subscribers via email.
260 - *
261 - * @param object $post The post.
262 - */
263 199 public function should_email_post_to_subscribers( $post ) {
264 200 $should_email = true;
265 201 if ( get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) ) {
266 202 return false;
@@ -265,10 +201,10 @@
265 201 if ( get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) ) {
266 202 return false;
267 203 }
268 204
269 - // Only posts are currently supported.
270 - if ( 'post' !== $post->post_type ) {
205 + // Only posts are currently supported
206 + if ( $post->post_type !== 'post' ) {
271 207 return false;
272 208 }
273 209
274 210 // Private posts are not sent to subscribers.
@@ -288,9 +224,9 @@
288 224 * @param array $args Array of category slugs or ID's.
289 225 */
290 226 $excluded_categories = apply_filters( 'jetpack_subscriptions_exclude_these_categories', array() );
291 227
292 - // Never email posts from these categories.
228 + // Never email posts from these categories
293 229 if ( ! empty( $excluded_categories ) && in_category( $excluded_categories, $post->ID ) ) {
294 230 $should_email = false;
295 231 }
296 232
@@ -306,9 +242,9 @@
306 242 * @param array $args Array of category slugs or ID's.
307 243 */
308 244 $only_these_categories = apply_filters( 'jetpack_subscriptions_exclude_all_categories_except', array() );
309 245
310 - // Only emails posts from these categories.
246 + // Only emails posts from these categories
311 247 if ( ! empty( $only_these_categories ) && ! in_category( $only_these_categories, $post->ID ) ) {
312 248 $should_email = false;
313 249 }
314 250
@@ -314,15 +250,9 @@
314 250
315 251 return $should_email;
316 252 }
317 253
318 - /**
319 - * Retrieve which flags should be added to a particular post.
320 - *
321 - * @param array $flags Flags to be added.
322 - * @param object $post A post object.
323 - */
324 - public function set_post_flags( $flags, $post ) {
254 + function set_post_flags( $flags, $post ) {
325 255 $flags['send_subscription'] = $this->should_email_post_to_subscribers( $post );
326 256 return $flags;
327 257 }
328 258
@@ -330,10 +260,10 @@
330 260 * Jetpack_Subscriptions::configure()
331 261 *
332 262 * Jetpack Subscriptions configuration screen.
333 263 */
334 - public function configure() {
335 - // Create the section.
264 + function configure() {
265 + // Create the section
336 266 add_settings_section(
337 267 'jetpack_subscriptions',
338 268 __( 'Jetpack Subscriptions Settings', 'jetpack' ),
339 269 array( $this, 'subscriptions_settings_section' ),
@@ -339,9 +269,9 @@
339 269 array( $this, 'subscriptions_settings_section' ),
340 270 'discussion'
341 271 );
342 272
343 - /** Subscribe to Posts */
273 + /** Subscribe to Posts ***************************************************/
344 274
345 275 add_settings_field(
346 276 'jetpack_subscriptions_post_subscribe',
347 277 __( 'Follow Blog', 'jetpack' ),
@@ -354,9 +284,9 @@
354 284 'discussion',
355 285 'stb_enabled'
356 286 );
357 287
358 - /** Subscribe to Comments */
288 + /** Subscribe to Comments ******************************************************/
359 289
360 290 add_settings_field(
361 291 'jetpack_subscriptions_comment_subscribe',
362 292 __( 'Follow Comments', 'jetpack' ),
@@ -369,14 +299,14 @@
369 299 'discussion',
370 300 'stc_enabled'
371 301 );
372 302
373 - /** Email me whenever: Someone subscribes to my blog */
303 + /** Email me whenever: Someone follows my blog ***************************************************/
374 304 /* @since 8.1 */
375 305
376 306 add_settings_section(
377 307 'notifications_section',
378 - __( 'Someone subscribes to my blog', 'jetpack' ),
308 + __( 'Someone follows my blog', 'jetpack' ),
379 309 array( $this, 'social_notifications_subscribe_section' ),
380 310 'discussion'
381 311 );
382 312
@@ -392,74 +322,90 @@
392 322 'discussion',
393 323 'social_notifications_subscribe',
394 324 array( $this, 'social_notifications_subscribe_validate' )
395 325 );
326 +
327 + /** Subscription Messaging Options ******************************************************/
328 +
329 + register_setting(
330 + 'reading',
331 + 'subscription_options',
332 + array( $this, 'validate_settings' )
333 + );
334 +
335 + add_settings_section(
336 + 'email_settings',
337 + __( 'Follower Settings', 'jetpack' ),
338 + array( $this, 'reading_section' ),
339 + 'reading'
340 + );
341 +
342 + add_settings_field(
343 + 'invitation',
344 + __( 'Blog follow email text', 'jetpack' ),
345 + array( $this, 'setting_invitation' ),
346 + 'reading',
347 + 'email_settings'
348 + );
349 +
350 + add_settings_field(
351 + 'comment-follow',
352 + __( 'Comment follow email text', 'jetpack' ),
353 + array( $this, 'setting_comment_follow' ),
354 + 'reading',
355 + 'email_settings'
356 + );
396 357 }
397 358
398 359 /**
399 - * Discussions setting section blurb.
360 + * Discussions setting section blurb
361 + *
400 362 */
401 - public function subscriptions_settings_section() {
402 - ?>
403 - <p id="jetpack-subscriptions-settings"><?php esc_html_e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p>
363 + function subscriptions_settings_section() {
364 + ?>
365 + <p id="jetpack-subscriptions-settings"><?php _e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p>
404 366
405 - <?php
367 + <?php
406 368 }
407 369
408 370 /**
409 - * Post Subscriptions Toggle.
371 + * Post Subscriptions Toggle
372 + *
410 373 */
411 - public function subscription_post_subscribe_setting() {
374 + function subscription_post_subscribe_setting() {
412 375
413 - $stb_enabled = get_option( 'stb_enabled', 1 );
414 - ?>
376 + $stb_enabled = get_option( 'stb_enabled', 1 ); ?>
415 377
416 378 <p class="description">
417 379 <input type="checkbox" name="stb_enabled" id="jetpack-post-subscribe" value="1" <?php checked( $stb_enabled, 1 ); ?> />
418 - <?php
419 - echo wp_kses(
420 - __(
421 - "Show a <em>'follow blog'</em> option in the comment form",
422 - 'jetpack'
423 - ),
424 - array( 'em' => array() )
425 - );
426 - ?>
380 + <?php _e( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ); ?>
427 381 </p>
428 - <?php
382 + <?php
429 383 }
430 384
431 385 /**
432 - * Comments Subscriptions Toggle.
386 + * Comments Subscriptions Toggle
387 + *
433 388 */
434 - public function subscription_comment_subscribe_setting() {
389 + function subscription_comment_subscribe_setting() {
435 390
436 - $stc_enabled = get_option( 'stc_enabled', 1 );
437 - ?>
391 + $stc_enabled = get_option( 'stc_enabled', 1 ); ?>
438 392
439 393 <p class="description">
440 394 <input type="checkbox" name="stc_enabled" id="jetpack-comment-subscribe" value="1" <?php checked( $stc_enabled, 1 ); ?> />
441 - <?php
442 - echo wp_kses(
443 - __(
444 - "Show a <em>'follow comments'</em> option in the comment form",
445 - 'jetpack'
446 - ),
447 - array( 'em' => array() )
448 - );
449 - ?>
395 + <?php _e( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ); ?>
450 396 </p>
451 397
452 - <?php
398 + <?php
453 399 }
454 400
455 401 /**
456 - * Someone subscribes to my blog section
402 + * Someone follows my blog section
457 403 *
458 404 * @since 8.1
459 405 */
460 406 public function social_notifications_subscribe_section() {
461 - // Atypical usage here. We emit jquery to move subscribe notification checkbox to be with the rest of the email notification settings.
407 + // Atypical usage here. We emit jquery to move subscribe notification checkbox to be with the rest of the email notification settings
462 408 ?>
463 409 <script type="text/javascript">
464 410 jQuery( function( $ ) {
465 411 var table = $( '#social_notifications_subscribe' ).parents( 'table:first' ),
@@ -478,14 +424,14 @@
478 424 <?php
479 425 }
480 426
481 427 /**
482 - * Someone subscribes to my blog Toggle
428 + * Someone follows my blog Toggle
483 429 *
484 430 * @since 8.1
485 431 */
486 432 public function social_notifications_subscribe_field() {
487 - $checked = (int) ( 'on' === get_option( 'social_notifications_subscribe', 'on' ) );
433 + $checked = intval( 'on' === get_option( 'social_notifications_subscribe', 'on' ) );
488 434 ?>
489 435
490 436 <label>
491 437 <input type="checkbox" name="social_notifications_subscribe" id="social_notifications_subscribe" value="1" <?php checked( $checked ); ?> />
@@ -490,9 +436,9 @@
490 436 <label>
491 437 <input type="checkbox" name="social_notifications_subscribe" id="social_notifications_subscribe" value="1" <?php checked( $checked ); ?> />
492 438 <?php
493 439 /* translators: this is a label for a setting that starts with "Email me whenever" */
494 - esc_html_e( 'Someone subscribes to my blog', 'jetpack' );
440 + esc_html_e( 'Someone follows my blog', 'jetpack' );
495 441 ?>
496 442 </label>
497 443 <?php
498 444 }
@@ -497,9 +443,9 @@
497 443 <?php
498 444 }
499 445
500 446 /**
501 - * Validate "Someone subscribes to my blog" option
447 + * Validate "Someone follows my blog" option
502 448 *
503 449 * @since 8.1
504 450 *
505 451 * @param String $input the input string to be validated.
@@ -514,35 +460,81 @@
514 460 // Otherwise we return 'on'.
515 461 return 'on';
516 462 }
517 463
464 + function validate_settings( $settings ) {
465 + global $allowedposttags;
466 +
467 + $default = $this->get_default_settings();
468 +
469 + // Blog Follow
470 + $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) );
471 + if ( empty( $settings['invitation'] ) )
472 + $settings['invitation'] = $default['invitation'];
473 +
474 + // Comments Follow (single post)
475 + $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) );
476 + if ( empty( $settings['comment_follow'] ) )
477 + $settings['comment_follow'] = $default['comment_follow'];
478 +
479 + return $settings;
480 + }
481 +
482 + public function reading_section() {
483 + echo '<p id="follower-settings">';
484 + _e( 'These settings change emails sent from your blog to followers.', 'jetpack' );
485 + echo '</p>';
486 + }
487 +
488 + public function setting_invitation() {
489 + $settings = $this->get_settings();
490 + echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>';
491 + echo '<p><span class="description">'.__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>';
492 + }
493 +
494 + public function setting_comment_follow() {
495 + $settings = $this->get_settings();
496 + echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>';
497 + echo '<p><span class="description">'.__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>';
498 + }
499 +
500 + function get_default_settings() {
501 + return array(
502 + 'invitation' => __( "Howdy.\n\nYou recently followed this blog's posts. This means you will receive each new post by email.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ),
503 + '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' )
504 + );
505 + }
506 +
507 + function get_settings() {
508 + return wp_parse_args( (array) get_option( 'subscription_options', array() ), $this->get_default_settings() );
509 + }
510 +
518 511 /**
519 512 * Jetpack_Subscriptions::subscribe()
520 513 *
521 514 * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
522 515 *
523 - * @param string $email being subscribed.
524 - * @param array $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts.
516 + * @param string $email
517 + * @param array $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts
525 518 * @param bool $async (optional) Should the subscription be performed asynchronously? Defaults to true.
526 - * @param array $extra_data Additional data passed to the `jetpack.subscribeToSite` call.
527 519 *
528 - * @return true|WP_Error true on success
529 - * invalid_email : not a valid email address
530 - * invalid_post_id : not a valid post ID
531 - * unknown_post_id : unknown post
532 - * not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email.
533 - * disabled : Site owner has disabled subscriptions.
534 - * active : Already subscribed.
535 - * pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent.
536 - * unknown : strange error. Jetpack servers at WordPress.com returned something malformed.
537 - * unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand.
520 + * @return true|Jetpack_Error true on success
521 + * invalid_email : not a valid email address
522 + * invalid_post_id : not a valid post ID
523 + * unknown_post_id : unknown post
524 + * not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email.
525 + * disabled : Site owner has disabled subscriptions.
526 + * active : Already subscribed.
527 + * pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent.
528 + * unknown : strange error. Jetpack servers at WordPress.com returned something malformed.
529 + * unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand.
538 530 */
539 - public function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) {
540 - if ( ! is_email( $email ) ) {
541 - return new WP_Error( 'invalid_email' );
531 + function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) {
532 + if ( !is_email( $email ) ) {
533 + return new Jetpack_Error( 'invalid_email' );
542 534 }
543 535
544 - if ( ! $async ) {
536 + if ( !$async ) {
545 537 $xml = new Jetpack_IXR_ClientMulticall();
546 538 }
547 539
548 540 foreach ( (array) $post_ids as $post_id ) {
@@ -547,17 +539,17 @@
547 539
548 540 foreach ( (array) $post_ids as $post_id ) {
549 541 $post_id = (int) $post_id;
550 542 if ( $post_id < 0 ) {
551 - return new WP_Error( 'invalid_post_id' );
552 - } elseif ( $post_id && ! get_post( $post_id ) ) {
553 - return new WP_Error( 'unknown_post_id' );
543 + return new Jetpack_Error( 'invalid_post_id' );
544 + } else if ( $post_id && !$post = get_post( $post_id ) ) {
545 + return new Jetpack_Error( 'unknown_post_id' );
554 546 }
555 547
556 548 if ( $async ) {
557 - XMLRPC_Async_Call::add_call( 'jetpack.subscribeToSite', 0, $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
549 + Jetpack::xmlrpc_async_call( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) );
558 550 } else {
559 - $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
551 + $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) );
560 552 }
561 553 }
562 554
563 555 if ( $async ) {
@@ -563,9 +555,9 @@
563 555 if ( $async ) {
564 556 return;
565 557 }
566 558
567 - // Call.
559 + // Call
568 560 $xml->query();
569 561
570 562 if ( $xml->isError() ) {
571 563 return $xml->get_jetpack_error();
@@ -579,31 +571,31 @@
579 571 $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] );
580 572 continue;
581 573 }
582 574
583 - if ( ! is_array( $response[0] ) || empty( $response[0]['status'] ) ) {
584 - $r[] = new WP_Error( 'unknown' );
575 + if ( !is_array( $response[0] ) || empty( $response[0]['status'] ) ) {
576 + $r[] = new Jetpack_Error( 'unknown' );
585 577 continue;
586 578 }
587 579
588 580 switch ( $response[0]['status'] ) {
589 581 case 'error':
590 - $r[] = new WP_Error( 'not_subscribed' );
582 + $r[] = new Jetpack_Error( 'not_subscribed' );
591 583 continue 2;
592 584 case 'disabled':
593 - $r[] = new WP_Error( 'disabled' );
585 + $r[] = new Jetpack_Error( 'disabled' );
594 586 continue 2;
595 587 case 'active':
596 - $r[] = new WP_Error( 'active' );
588 + $r[] = new Jetpack_Error( 'active' );
597 589 continue 2;
598 590 case 'confirming':
599 591 $r[] = true;
600 592 continue 2;
601 593 case 'pending':
602 - $r[] = new WP_Error( 'pending' );
594 + $r[] = new Jetpack_Error( 'pending' );
603 595 continue 2;
604 596 default:
605 - $r[] = new WP_Error( 'unknown_status', (string) $response[0]['status'] );
597 + $r[] = new Jetpack_Error( 'unknown_status', (string) $response[0]['status'] );
606 598 continue 2;
607 599 }
608 600 }
609 601
@@ -614,36 +606,35 @@
614 606 * Jetpack_Subscriptions::widget_submit()
615 607 *
616 608 * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method.
617 609 */
618 - public function widget_submit() {
610 + function widget_submit() {
619 611 // Check the nonce.
620 - if ( ! wp_verify_nonce( isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( $_REQUEST['_wpnonce'] ) : '', 'blogsub_subscribe_' . \Jetpack_Options::get_option( 'id' ) ) ) {
621 - return false;
612 + if ( is_user_logged_in() ) {
613 + check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() );
622 614 }
623 615
624 - if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) {
616 + if ( empty( $_REQUEST['email'] ) )
625 617 return false;
626 - }
627 618
628 619 $redirect_fragment = false;
629 620 if ( isset( $_REQUEST['redirect_fragment'] ) ) {
630 - $redirect_fragment = preg_replace( '/[^a-z0-9_-]/i', '', $_REQUEST['redirect_fragment'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is manually unslashing and sanitizing.
621 + $redirect_fragment = preg_replace( '/[^a-z0-9_-]/i', '', $_REQUEST['redirect_fragment'] );
631 622 }
632 - if ( ! $redirect_fragment || ! is_string( $redirect_fragment ) ) {
623 + if ( !$redirect_fragment ) {
633 624 $redirect_fragment = 'subscribe-blog';
634 625 }
635 626
636 - $subscribe = self::subscribe(
637 - isset( $_REQUEST['email'] ) ? wp_unslash( $_REQUEST['email'] ) : null, // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated inside self::subscribe().
638 - 0,
639 - false,
640 - array(
641 - 'source' => 'widget',
642 - 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
643 - 'comment_status' => '',
644 - 'server_data' => jetpack_subscriptions_cherry_pick_server_data(),
645 - )
627 + $subscribe = Jetpack_Subscriptions::subscribe(
628 + $_REQUEST['email'],
629 + 0,
630 + false,
631 + array(
632 + 'source' => 'widget',
633 + 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
634 + 'comment_status' => '',
635 + 'server_data' => jetpack_subscriptions_cherry_pick_server_data(),
636 + )
646 637 );
647 638
648 639 if ( is_wp_error( $subscribe ) ) {
649 640 $error = $subscribe->get_error_code();
@@ -703,17 +694,13 @@
703 694 *
704 695 * Set up and add the comment subscription checkbox to the comment form.
705 696 *
706 697 * @param string $submit_button HTML markup for the submit field.
698 + * @param array $args Arguments passed to `comment_form()`.
707 699 */
708 - public function comment_subscribe_init( $submit_button ) {
700 + function comment_subscribe_init( $submit_button, $args ) {
709 701 global $post;
710 702
711 - // Subscriptions are only available for posts so far.
712 - if ( ! $post || 'post' !== $post->post_type ) {
713 - return $submit_button;
714 - }
715 -
716 703 $comments_checked = '';
717 704 $blog_checked = '';
718 705
719 706 // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
@@ -724,20 +711,20 @@
724 711 if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) ) {
725 712 $blog_checked = ' checked="checked"';
726 713 }
727 714
728 - // Some themes call this function, don't show the checkbox again.
715 + // Some themes call this function, don't show the checkbox again
729 716 remove_action( 'comment_form', 'subscription_comment_form' );
730 717
731 - // Check if Mark Jaquith's Subscribe to Comments plugin is active - if so, suppress Jetpack checkbox.
718 + // Check if Mark Jaquith's Subscribe to Comments plugin is active - if so, suppress Jetpack checkbox
732 719
733 720 $str = '';
734 721
735 - if ( false === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 === (int) get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) && 'post' === get_post_type() ) {
736 - // Subscribe to comments checkbox.
737 - $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> ';
722 + if ( FALSE === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 == get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) && 'post' == get_post_type() ) {
723 + // Subscribe to comments checkbox
724 + $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> ';
738 725 $comment_sub_text = __( 'Notify me of follow-up comments by email.', 'jetpack' );
739 - $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . esc_html(
726 + $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . esc_html(
740 727 /**
741 728 * Filter the Subscribe to comments text appearing below the comment form.
742 729 *
743 730 * @module subscriptions
@@ -750,13 +737,13 @@
750 737 ) . '</label>';
751 738 $str .= '</p>';
752 739 }
753 740
754 - if ( 1 === (int) get_option( 'stb_enabled', 1 ) ) {
755 - // Subscribe to blog checkbox.
756 - $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> ';
741 + if ( 1 == get_option( 'stb_enabled', 1 ) ) {
742 + // Subscribe to blog checkbox
743 + $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> ';
757 744 $blog_sub_text = __( 'Notify me of new posts by email.', 'jetpack' );
758 - $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . esc_html(
745 + $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . esc_html(
759 746 /**
760 747 * Filter the Subscribe to blog text appearing below the comment form.
761 748 *
762 749 * @module subscriptions
@@ -787,49 +774,40 @@
787 774 /**
788 775 * Jetpack_Subscriptions::comment_subscribe_init()
789 776 *
790 777 * When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread.
791 - *
792 - * @param int|string $comment_id Comment thread being subscribed to.
793 - * @param string $approved Comment status.
794 778 */
795 - public function comment_subscribe_submit( $comment_id, $approved ) {
779 + function comment_subscribe_submit( $comment_id, $approved ) {
796 780 if ( 'spam' === $approved ) {
797 781 return;
798 782 }
799 783
800 784 $comment = get_comment( $comment_id );
801 - if ( ! $comment ) {
802 - return;
803 - }
804 785
805 - // Set cookies for this post/comment.
806 - $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), $comment->comment_post_ID, isset( $_REQUEST['subscribe_blog'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
786 + // Set cookies for this post/comment
787 + $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), $comment->comment_post_ID, isset( $_REQUEST['subscribe_blog'] ) );
807 788
808 - if ( ! isset( $_REQUEST['subscribe_comments'] ) && ! isset( $_REQUEST['subscribe_blog'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
789 + if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) )
809 790 return;
810 - }
811 791
812 792 $post_ids = array();
813 793
814 - if ( isset( $_REQUEST['subscribe_comments'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
794 + if ( isset( $_REQUEST['subscribe_comments'] ) )
815 795 $post_ids[] = $comment->comment_post_ID;
816 - }
817 796
818 - if ( isset( $_REQUEST['subscribe_blog'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
797 + if ( isset( $_REQUEST['subscribe_blog'] ) )
819 798 $post_ids[] = 0;
820 - }
821 799
822 - $result = self::subscribe(
823 - $comment->comment_author_email,
824 - $post_ids,
825 - true,
826 - array(
827 - 'source' => 'comment-form',
828 - 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
829 - 'comment_status' => $approved,
830 - 'server_data' => jetpack_subscriptions_cherry_pick_server_data(),
831 - )
800 + $result = Jetpack_Subscriptions::subscribe(
801 + $comment->comment_author_email,
802 + $post_ids,
803 + true,
804 + array(
805 + 'source' => 'comment-form',
806 + 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',
807 + 'comment_status' => $approved,
808 + 'server_data' => jetpack_subscriptions_cherry_pick_server_data(),
809 + )
832 810 );
833 811
834 812 /**
835 813 * Fires on each comment subscription form submission.
@@ -838,9 +816,9 @@
838 816 *
839 817 * @since 5.5.0
840 818 *
841 819 * @param NULL|WP_Error $result Result of form submission: NULL on success, WP_Error otherwise.
842 - * @param array $post_ids An array of post IDs that the user subscribed to, 0 means blog subscription.
820 + * @param Array $post_ids An array of post IDs that the user subscribed to, 0 means blog subscription.
843 821 */
844 822 do_action( 'jetpack_subscriptions_comment_form_submission', $result, $post_ids );
845 823 }
846 824
@@ -849,16 +827,16 @@
849 827 *
850 828 * Set a cookie to save state on the comment and post subscription checkboxes.
851 829 *
852 830 * @param bool $subscribe_to_post Whether the user chose to subscribe to subsequent comments on this post.
853 - * @param int $post_id If $subscribe_to_post is true, the post ID they've subscribed to.
831 + * @param int $post_id If $subscribe_to_post is true, the post ID they've subscribed to.
854 832 * @param bool $subscribe_to_blog Whether the user chose to subscribe to all new posts on the blog.
855 833 */
856 - public function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) {
857 - $post_id = (int) $post_id;
834 + function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) {
835 + $post_id = intval( $post_id );
858 836
859 837 /** This filter is already documented in core/wp-includes/comment-functions.php */
860 - $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
838 + $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
861 839
862 840 /**
863 841 * Filter the Jetpack Comment cookie path.
864 842 *
@@ -867,9 +845,9 @@
867 845 * @since 2.5.0
868 846 *
869 847 * @param string COOKIEPATH Cookie path.
870 848 */
871 - $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH );
849 + $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH );
872 850
873 851 /**
874 852 * Filter the Jetpack Comment cookie domain.
875 853 *
@@ -878,20 +856,20 @@
878 856 * @since 2.5.0
879 857 *
880 858 * @param string COOKIE_DOMAIN Cookie domain.
881 859 */
882 - $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN );
860 + $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN );
883 861
884 862 if ( $subscribe_to_post && $post_id >= 0 ) {
885 - setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true );
863 + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
886 864 } else {
887 - setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true );
865 + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain );
888 866 }
889 867
890 868 if ( $subscribe_to_blog ) {
891 - setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true );
869 + setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
892 870 } else {
893 - setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true );
871 + setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );
894 872 }
895 873 }
896 874
897 875 /**
@@ -898,153 +876,17 @@
898 876 * Set the social_notifications_subscribe option to `off` when the Subscriptions module is activated in the first time.
899 877 *
900 878 * @since 8.1
901 879 *
902 - * @return void
880 + * @return null
903 881 */
904 - public function set_social_notifications_subscribe() {
882 + function set_social_notifications_subscribe() {
905 883 if ( false === get_option( 'social_notifications_subscribe' ) ) {
906 884 add_option( 'social_notifications_subscribe', 'off' );
907 885 }
908 886 }
909 887
910 - /**
911 - * Save a flag when a post was ever published.
912 - *
913 - * It saves the post meta when the post was published and becomes a draft.
914 - * Then this meta is used to hide subscription messaging in Publish panel.
915 - *
916 - * @param string $new_status Tthe "new" post status of the transition when saved.
917 - * @param string $old_status The "old" post status of the transition when saved.
918 - * @param object $post obj The post object.
919 - */
920 - public function maybe_set_first_published_status( $new_status, $old_status, $post ) {
921 - $was_post_ever_published = get_post_meta( $post->ID, '_jetpack_post_was_ever_published', true );
922 - if ( ! $was_post_ever_published && 'publish' === $old_status && 'draft' === $new_status ) {
923 - update_post_meta( $post->ID, '_jetpack_post_was_ever_published', true );
924 - }
925 - }
926 -
927 - /**
928 - * Checks if the current user can publish posts.
929 - *
930 - * @return bool
931 - */
932 - public function first_published_status_meta_auth_callback() {
933 - /**
934 - * Filter the capability to view if a post was ever published in the Subscription Module.
935 - *
936 - * @module subscriptions
937 - *
938 - * @since 13.4
939 - *
940 - * @param string $capability User capability needed to view if a post was ever published. Default to publish_posts.
941 - */
942 - $capability = apply_filters( 'jetpack_subscriptions_post_was_ever_published_capability', 'publish_posts' );
943 - if ( current_user_can( $capability ) ) {
944 - return true;
945 - }
946 - return false;
947 - }
948 -
949 - /**
950 - * Registers the 'post_was_ever_published' post meta for use in the REST API.
951 - */
952 - public function register_post_meta() {
953 - $jetpack_post_was_ever_published = array(
954 - 'type' => 'boolean',
955 - 'description' => __( 'Whether the post was ever published.', 'jetpack' ),
956 - 'single' => true,
957 - 'default' => false,
958 - 'show_in_rest' => array(
959 - 'name' => 'jetpack_post_was_ever_published',
960 - ),
961 - 'auth_callback' => array( $this, 'first_published_status_meta_auth_callback' ),
962 - );
963 -
964 - register_meta( 'post', '_jetpack_post_was_ever_published', $jetpack_post_was_ever_published );
965 - }
966 -
967 - /**
968 - * Create a Subscribers menu displayed on self-hosted sites.
969 - *
970 - * - It is not displayed on WordPress.com sites.
971 - * - It directs you to Calypso to the existing Subscribers page.
972 - *
973 - * @return void
974 - */
975 - public function add_subscribers_menu() {
976 - /*
977 - * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled).
978 - * They already get a menu item under Users via nav-unification.
979 - */
980 - if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
981 - return;
982 - }
983 -
984 - $status = new Status();
985 -
986 - /*
987 - * Do not display if we're in Offline mode,
988 - * or if the user is not connected.
989 - */
990 - if (
991 - $status->is_offline_mode()
992 - || ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected()
993 - ) {
994 - return;
995 - }
996 -
997 - $blog_id = Connection_Manager::get_site_id( true );
998 -
999 - $link = Redirect::get_url(
1000 - 'jetpack-menu-jetpack-manage-subscribers',
1001 - array( 'site' => $blog_id ? $blog_id : $status->get_site_suffix() )
1002 - );
1003 -
1004 - Admin_Menu::add_menu(
1005 - __( 'Subscribers', 'jetpack' ),
1006 - __( 'Subscribers', 'jetpack' ) . ' <span class="dashicons dashicons-external"></span>',
1007 - 'manage_options',
1008 - esc_url( $link ),
1009 - null,
1010 - 11
1011 - );
1012 - }
1013 -
1014 - /**
1015 - * Record tracks event if categories is created when user enters
1016 - * the edit category page through the newsletter settings page.
1017 - *
1018 - * @return void
1019 - */
1020 - public function track_newsletter_category_creation() {
1021 -
1022 - // phpcs:disable WordPress.Security.NonceVerification.Missing
1023 - if ( empty( $_POST['_wp_http_referer'] ) ) {
1024 - return;
1025 - }
1026 -
1027 - if ( strpos( sanitize_url( wp_unslash( $_POST['_wp_http_referer'] ) ), 'referer=newsletter-categories' ) > -1 ) {
1028 -
1029 - $parent = filter_var( empty( $_POST['parent'] ) ? 0 : wp_unslash( $_POST['parent'] ), FILTER_SANITIZE_NUMBER_INT );
1030 -
1031 - $is_child_category = $parent > 0;
1032 -
1033 - $tracking = new Automattic\Jetpack\Tracking();
1034 - $tracking->tracks_record_event(
1035 - wp_get_current_user(),
1036 - 'jetpack_newsletter_add_category',
1037 - array(
1038 - 'is_child_category' => $is_child_category,
1039 - )
1040 - );
1041 - }
1042 - }
1043 888 }
1044 889
1045 890 Jetpack_Subscriptions::init();
1046 891
1047 -require __DIR__ . '/subscriptions/views.php';
1048 -require __DIR__ . '/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php';
1049 -require __DIR__ . '/subscriptions/subscribe-overlay/class-jetpack-subscribe-overlay.php';
1050 -require __DIR__ . '/subscriptions/subscribe-floating-button/class-jetpack-subscribe-floating-button.php';
892 +include dirname( __FILE__ ) . '/subscriptions/views.php';