PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.2
Jetpack – WP Security, Backup, Speed, & Growth v14.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 +84 -158 12.6.414.2 View file →
@@ -9,13 +9,14 @@
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
13 + * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup, newsletter, creator
14 14 */
15 15
16 16 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
17 17
18 +use Automattic\Jetpack\Admin_UI\Admin_Menu;
18 19 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
19 20 use Automattic\Jetpack\Connection\XMLRPC_Async_Call;
20 21 use Automattic\Jetpack\Redirect;
21 22 use Automattic\Jetpack\Status;
@@ -22,8 +23,11 @@
22 23 use Automattic\Jetpack\Status\Host;
23 24
24 25 add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' );
25 26
27 +// Loads the User Content Link Redirection feature.
28 +require_once __DIR__ . '/subscriptions/jetpack-user-content-link-redirection.php';
29 +
26 30 /**
27 31 * Loads the Subscriptions module.
28 32 */
29 33 function jetpack_subscriptions_load() {
@@ -40,13 +44,13 @@
40 44 function jetpack_subscriptions_cherry_pick_server_data() {
41 45 $data = array();
42 46
43 47 foreach ( $_SERVER as $key => $value ) {
44 - if ( ! is_string( $value ) || 0 === strpos( $key, 'HTTP_COOKIE' ) ) {
48 + if ( ! is_string( $value ) || str_starts_with( $key, 'HTTP_COOKIE' ) ) {
45 49 continue;
46 50 }
47 51
48 - if ( 0 === strpos( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
52 + if ( str_starts_with( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
49 53 $data[ $key ] = $value;
50 54 }
51 55 }
52 56
@@ -131,8 +135,19 @@
131 135 add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 );
132 136
133 137 // Add Subscribers menu to Jetpack navigation.
134 138 add_action( 'jetpack_admin_menu', array( $this, 'add_subscribers_menu' ) );
139 +
140 + // Customize the configuration URL to lead to the Subscriptions settings.
141 + add_filter(
142 + 'jetpack_module_configuration_url_subscriptions',
143 + function () {
144 + return Jetpack::admin_url( array( 'page' => 'jetpack#/newsletter' ) );
145 + }
146 + );
147 +
148 + // Track categories created through the category editor page
149 + add_action( 'wp_ajax_add-tag', array( $this, 'track_newsletter_category_creation' ), 1 );
135 150 }
136 151
137 152 /**
138 153 * Jetpack_Subscriptions::xmlrpc_methods()
@@ -354,32 +369,14 @@
354 369 'discussion',
355 370 'stc_enabled'
356 371 );
357 372
358 - /** Enable Subscribe Modal */
359 -
360 - /** This filter is documented in plugins/jetpack/modules/subscriptions/subscribe-module/class-jetpack-subscribe-module.php */
361 - if ( apply_filters( 'jetpack_subscriptions_modal_enabled', false ) ) {
362 - add_settings_field(
363 - 'jetpack_subscriptions_comment_subscribe',
364 - __( 'Enable Subscribe Modal', 'jetpack' ),
365 - array( $this, 'subscribe_modal_setting' ),
366 - 'discussion',
367 - 'jetpack_subscriptions'
368 - );
369 -
370 - register_setting(
371 - 'discussion',
372 - 'sm_enabled'
373 - );
374 - }
375 -
376 - /** Email me whenever: Someone follows my blog */
373 + /** Email me whenever: Someone subscribes to my blog */
377 374 /* @since 8.1 */
378 375
379 376 add_settings_section(
380 377 'notifications_section',
381 - __( 'Someone follows my blog', 'jetpack' ),
378 + __( 'Someone subscribes to my blog', 'jetpack' ),
382 379 array( $this, 'social_notifications_subscribe_section' ),
383 380 'discussion'
384 381 );
385 382
@@ -395,39 +392,8 @@
395 392 'discussion',
396 393 'social_notifications_subscribe',
397 394 array( $this, 'social_notifications_subscribe_validate' )
398 395 );
399 -
400 - /** Subscription Messaging Options */
401 -
402 - register_setting(
403 - 'reading',
404 - 'subscription_options',
405 - array( $this, 'validate_settings' )
406 - );
407 -
408 - add_settings_section(
409 - 'email_settings',
410 - __( 'Follower Settings', 'jetpack' ),
411 - array( $this, 'reading_section' ),
412 - 'reading'
413 - );
414 -
415 - add_settings_field(
416 - 'invitation',
417 - __( 'Blog follow email text', 'jetpack' ),
418 - array( $this, 'setting_invitation' ),
419 - 'reading',
420 - 'email_settings'
421 - );
422 -
423 - add_settings_field(
424 - 'comment-follow',
425 - __( 'Comment follow email text', 'jetpack' ),
426 - array( $this, 'setting_comment_follow' ),
427 - 'reading',
428 - 'email_settings'
429 - );
430 396 }
431 397
432 398 /**
433 399 * Discussions setting section blurb.
@@ -486,25 +452,9 @@
486 452 <?php
487 453 }
488 454
489 455 /**
490 - * Subscribe Modal Toggle.
491 - */
492 - public function subscribe_modal_setting() {
493 -
494 - $sm_enabled = get_option( 'sm_enabled', 1 );
495 - ?>
496 -
497 - <p class="description">
498 - <input type="checkbox" name="sm_enabled" id="jetpack-subscribe-modal" value="1" <?php checked( $sm_enabled, 1 ); ?> />
499 - <?php esc_html_e( 'Show a popup subscribe modal to readers.', 'jetpack' ); ?>
500 - </p>
501 -
502 - <?php
503 - }
504 -
505 - /**
506 - * Someone follows my blog section
456 + * Someone subscribes to my blog section
507 457 *
508 458 * @since 8.1
509 459 */
510 460 public function social_notifications_subscribe_section() {
@@ -528,9 +478,9 @@
528 478 <?php
529 479 }
530 480
531 481 /**
532 - * Someone follows my blog Toggle
482 + * Someone subscribes to my blog Toggle
533 483 *
534 484 * @since 8.1
535 485 */
536 486 public function social_notifications_subscribe_field() {
@@ -540,9 +490,9 @@
540 490 <label>
541 491 <input type="checkbox" name="social_notifications_subscribe" id="social_notifications_subscribe" value="1" <?php checked( $checked ); ?> />
542 492 <?php
543 493 /* translators: this is a label for a setting that starts with "Email me whenever" */
544 - esc_html_e( 'Someone follows my blog', 'jetpack' );
494 + esc_html_e( 'Someone subscribes to my blog', 'jetpack' );
545 495 ?>
546 496 </label>
547 497 <?php
548 498 }
@@ -547,9 +497,9 @@
547 497 <?php
548 498 }
549 499
550 500 /**
551 - * Validate "Someone follows my blog" option
501 + * Validate "Someone subscribes to my blog" option
552 502 *
553 503 * @since 8.1
554 504 *
555 505 * @param String $input the input string to be validated.
@@ -565,81 +515,8 @@
565 515 return 'on';
566 516 }
567 517
568 518 /**
569 - * Validate settings for the Subscriptions module.
570 - *
571 - * @param array $settings Settings to be validated.
572 - */
573 - public function validate_settings( $settings ) {
574 - global $allowedposttags;
575 -
576 - $default = $this->get_default_settings();
577 -
578 - // Blog Follow.
579 - $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) );
580 - if ( empty( $settings['invitation'] ) ) {
581 - $settings['invitation'] = $default['invitation'];
582 - }
583 -
584 - // Comments Follow (single post).
585 - $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) );
586 - if ( empty( $settings['comment_follow'] ) ) {
587 - $settings['comment_follow'] = $default['comment_follow'];
588 - }
589 -
590 - return $settings;
591 - }
592 -
593 - /**
594 - * HTML output helper for Reading section.
595 - */
596 - public function reading_section() {
597 - echo '<p id="follower-settings">';
598 - esc_html_e( 'These settings change emails sent from your blog to followers.', 'jetpack' );
599 - echo '</p>';
600 - }
601 -
602 - /**
603 - * HTML output helper for Invitation section.
604 - */
605 - public function setting_invitation() {
606 - $settings = $this->get_settings();
607 - echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>';
608 - 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>';
609 - }
610 -
611 - /**
612 - * HTML output helper for Comment Follow section.
613 - */
614 - public function setting_comment_follow() {
615 - $settings = $this->get_settings();
616 - echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>';
617 - 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>';
618 - }
619 -
620 - /**
621 - * Get default settings for the Subscriptions module.
622 - */
623 - public function get_default_settings() {
624 - $site_url = get_home_url();
625 - $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
626 -
627 - return array(
628 - /* translators: Both %1$s and %2$s is site address */
629 - '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 ),
630 - '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' ),
631 - );
632 - }
633 -
634 - /**
635 - * Reeturn merged `subscription_options` option with module default settings.
636 - */
637 - public function get_settings() {
638 - return wp_parse_args( (array) get_option( 'subscription_options' ), $this->get_default_settings() );
639 - }
640 -
641 - /**
642 519 * Jetpack_Subscriptions::subscribe()
643 520 *
644 521 * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
645 522 *
@@ -739,10 +616,10 @@
739 616 * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method.
740 617 */
741 618 public function widget_submit() {
742 619 // Check the nonce.
743 - if ( is_user_logged_in() ) {
744 - check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() );
620 + if ( ! wp_verify_nonce( isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( $_REQUEST['_wpnonce'] ) : '', 'blogsub_subscribe_' . \Jetpack_Options::get_option( 'id' ) ) ) {
621 + return false;
745 622 }
746 623
747 624 if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) {
748 625 return false;
@@ -830,8 +707,13 @@
830 707 */
831 708 public function comment_subscribe_init( $submit_button ) {
832 709 global $post;
833 710
711 + // Subscriptions are only available for posts so far.
712 + if ( ! $post || 'post' !== $post->post_type ) {
713 + return $submit_button;
714 + }
715 +
834 716 $comments_checked = '';
835 717 $blog_checked = '';
836 718
837 719 // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
@@ -1047,9 +929,19 @@
1047 929 *
1048 930 * @return bool
1049 931 */
1050 932 public function first_published_status_meta_auth_callback() {
1051 - if ( current_user_can( 'publish_posts' ) ) {
933 + /**
934 + * Filter the capability to view if a post was ever published in the Subscription Module.
935 + *
936 + * @module subscriptions
937 + *
938 + * @since 13.4
939 + *
940 + * @param string $capability User capability needed to view if a post was ever published. Default to publish_posts.
941 + */
942 + $capability = apply_filters( 'jetpack_subscriptions_post_was_ever_published_capability', 'publish_posts' );
943 + if ( current_user_can( $capability ) ) {
1052 944 return true;
1053 945 }
1054 946 return false;
1055 947 }
@@ -1081,12 +973,12 @@
1081 973 * @return void
1082 974 */
1083 975 public function add_subscribers_menu() {
1084 976 /*
1085 - * Do not display any menu on WoA and WordPress.com Simple sites.
977 + * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled).
1086 978 * They already get a menu item under Users via nav-unification.
1087 979 */
1088 - if ( ( new Host() )->is_wpcom_platform() ) {
980 + if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
1089 981 return;
1090 982 }
1091 983
1092 984 $status = new Status();
@@ -1101,22 +993,54 @@
1101 993 ) {
1102 994 return;
1103 995 }
1104 996
997 + $blog_id = Connection_Manager::get_site_id( true );
998 +
1105 999 $link = Redirect::get_url(
1106 - 'jetpack-menu-calypso-subscribers',
1107 - array( 'site' => $status->get_site_suffix() )
1000 + 'jetpack-menu-jetpack-manage-subscribers',
1001 + array( 'site' => $blog_id ? $blog_id : $status->get_site_suffix() )
1108 1002 );
1109 1003
1110 - add_submenu_page(
1111 - 'jetpack',
1112 - esc_attr__( 'Subscribers', 'jetpack' ),
1004 + Admin_Menu::add_menu(
1005 + __( 'Subscribers', 'jetpack' ),
1113 1006 __( 'Subscribers', 'jetpack' ) . ' <span class="dashicons dashicons-external"></span>',
1114 1007 'manage_options',
1115 1008 esc_url( $link ),
1116 - null
1009 + null,
1010 + 11
1117 1011 );
1118 1012 }
1013 +
1014 + /**
1015 + * Record tracks event if categories is created when user enters
1016 + * the edit category page through the newsletter settings page.
1017 + *
1018 + * @return void
1019 + */
1020 + public function track_newsletter_category_creation() {
1021 +
1022 + // phpcs:disable WordPress.Security.NonceVerification.Missing
1023 + if ( empty( $_POST['_wp_http_referer'] ) ) {
1024 + return;
1025 + }
1026 +
1027 + if ( strpos( sanitize_url( wp_unslash( $_POST['_wp_http_referer'] ) ), 'referer=newsletter-categories' ) > -1 ) {
1028 +
1029 + $parent = filter_var( empty( $_POST['parent'] ) ? 0 : wp_unslash( $_POST['parent'] ), FILTER_SANITIZE_NUMBER_INT );
1030 +
1031 + $is_child_category = $parent > 0;
1032 +
1033 + $tracking = new Automattic\Jetpack\Tracking();
1034 + $tracking->tracks_record_event(
1035 + wp_get_current_user(),
1036 + 'jetpack_newsletter_add_category',
1037 + array(
1038 + 'is_child_category' => $is_child_category,
1039 + )
1040 + );
1041 + }
1042 + }
1119 1043 }
1120 1044
1121 1045 Jetpack_Subscriptions::init();
1122 1046
@@ -1121,4 +1045,6 @@
1121 1045 Jetpack_Subscriptions::init();
1122 1046
1123 1047 require __DIR__ . '/subscriptions/views.php';
1124 1048 require __DIR__ . '/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php';
1049 +require __DIR__ . '/subscriptions/subscribe-overlay/class-jetpack-subscribe-overlay.php';
1050 +require __DIR__ . '/subscriptions/subscribe-floating-button/class-jetpack-subscribe-floating-button.php';