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