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