PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.6
Jetpack – WP Security, Backup, Speed, & Growth v12.6
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 -84 14.2.212.6 View file →
@@ -9,14 +9,13 @@
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, newsletter
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;
19 18 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
20 19 use Automattic\Jetpack\Connection\XMLRPC_Async_Call;
21 20 use Automattic\Jetpack\Redirect;
22 21 use Automattic\Jetpack\Status;
@@ -23,11 +22,8 @@
23 22 use Automattic\Jetpack\Status\Host;
24 23
25 24 add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' );
26 25
27 -// Loads the User Content Link Redirection feature.
28 -require_once __DIR__ . '/subscriptions/jetpack-user-content-link-redirection.php';
29 -
30 26 /**
31 27 * Loads the Subscriptions module.
32 28 */
33 29 function jetpack_subscriptions_load() {
@@ -44,13 +40,13 @@
44 40 function jetpack_subscriptions_cherry_pick_server_data() {
45 41 $data = array();
46 42
47 43 foreach ( $_SERVER as $key => $value ) {
48 - if ( ! is_string( $value ) || str_starts_with( $key, 'HTTP_COOKIE' ) ) {
44 + if ( ! is_string( $value ) || 0 === strpos( $key, 'HTTP_COOKIE' ) ) {
49 45 continue;
50 46 }
51 47
52 - if ( str_starts_with( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
48 + if ( 0 === strpos( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
53 49 $data[ $key ] = $value;
54 50 }
55 51 }
56 52
@@ -135,19 +131,8 @@
135 131 add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 );
136 132
137 133 // Add Subscribers menu to Jetpack navigation.
138 134 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 );
150 135 }
151 136
152 137 /**
153 138 * Jetpack_Subscriptions::xmlrpc_methods()
@@ -369,14 +354,32 @@
369 354 'discussion',
370 355 'stc_enabled'
371 356 );
372 357
373 - /** Email me whenever: Someone subscribes to my blog */
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 */
374 377 /* @since 8.1 */
375 378
376 379 add_settings_section(
377 380 'notifications_section',
378 - __( 'Someone subscribes to my blog', 'jetpack' ),
381 + __( 'Someone follows my blog', 'jetpack' ),
379 382 array( $this, 'social_notifications_subscribe_section' ),
380 383 'discussion'
381 384 );
382 385
@@ -392,8 +395,39 @@
392 395 'discussion',
393 396 'social_notifications_subscribe',
394 397 array( $this, 'social_notifications_subscribe_validate' )
395 398 );
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 + );
396 430 }
397 431
398 432 /**
399 433 * Discussions setting section blurb.
@@ -452,9 +486,25 @@
452 486 <?php
453 487 }
454 488
455 489 /**
456 - * Someone subscribes to my blog section
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
457 507 *
458 508 * @since 8.1
459 509 */
460 510 public function social_notifications_subscribe_section() {
@@ -478,9 +528,9 @@
478 528 <?php
479 529 }
480 530
481 531 /**
482 - * Someone subscribes to my blog Toggle
532 + * Someone follows my blog Toggle
483 533 *
484 534 * @since 8.1
485 535 */
486 536 public function social_notifications_subscribe_field() {
@@ -490,9 +540,9 @@
490 540 <label>
491 541 <input type="checkbox" name="social_notifications_subscribe" id="social_notifications_subscribe" value="1" <?php checked( $checked ); ?> />
492 542 <?php
493 543 /* translators: this is a label for a setting that starts with "Email me whenever" */
494 - esc_html_e( 'Someone subscribes to my blog', 'jetpack' );
544 + esc_html_e( 'Someone follows my blog', 'jetpack' );
495 545 ?>
496 546 </label>
497 547 <?php
498 548 }
@@ -497,9 +547,9 @@
497 547 <?php
498 548 }
499 549
500 550 /**
501 - * Validate "Someone subscribes to my blog" option
551 + * Validate "Someone follows my blog" option
502 552 *
503 553 * @since 8.1
504 554 *
505 555 * @param String $input the input string to be validated.
@@ -515,8 +565,81 @@
515 565 return 'on';
516 566 }
517 567
518 568 /**
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 + /**
519 642 * Jetpack_Subscriptions::subscribe()
520 643 *
521 644 * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
522 645 *
@@ -616,10 +739,10 @@
616 739 * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method.
617 740 */
618 741 public function widget_submit() {
619 742 // Check the nonce.
620 - if ( ! wp_verify_nonce( isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( $_REQUEST['_wpnonce'] ) : '', 'blogsub_subscribe_' . \Jetpack_Options::get_option( 'id' ) ) ) {
621 - return false;
743 + if ( is_user_logged_in() ) {
744 + check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() );
622 745 }
623 746
624 747 if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) {
625 748 return false;
@@ -707,13 +830,8 @@
707 830 */
708 831 public function comment_subscribe_init( $submit_button ) {
709 832 global $post;
710 833
711 - // Subscriptions are only available for posts so far.
712 - if ( ! $post || 'post' !== $post->post_type ) {
713 - return $submit_button;
714 - }
715 -
716 834 $comments_checked = '';
717 835 $blog_checked = '';
718 836
719 837 // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
@@ -929,19 +1047,9 @@
929 1047 *
930 1048 * @return bool
931 1049 */
932 1050 public function first_published_status_meta_auth_callback() {
933 - /**
934 - * Filter the capability to view if a post was ever published in the Subscription Module.
935 - *
936 - * @module subscriptions
937 - *
938 - * @since 13.4
939 - *
940 - * @param string $capability User capability needed to view if a post was ever published. Default to publish_posts.
941 - */
942 - $capability = apply_filters( 'jetpack_subscriptions_post_was_ever_published_capability', 'publish_posts' );
943 - if ( current_user_can( $capability ) ) {
1051 + if ( current_user_can( 'publish_posts' ) ) {
944 1052 return true;
945 1053 }
946 1054 return false;
947 1055 }
@@ -973,12 +1081,12 @@
973 1081 * @return void
974 1082 */
975 1083 public function add_subscribers_menu() {
976 1084 /*
977 - * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled).
1085 + * Do not display any menu on WoA and WordPress.com Simple sites.
978 1086 * They already get a menu item under Users via nav-unification.
979 1087 */
980 - if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
1088 + if ( ( new Host() )->is_wpcom_platform() ) {
981 1089 return;
982 1090 }
983 1091
984 1092 $status = new Status();
@@ -993,54 +1101,22 @@
993 1101 ) {
994 1102 return;
995 1103 }
996 1104
997 - $blog_id = Connection_Manager::get_site_id( true );
998 -
999 1105 $link = Redirect::get_url(
1000 - 'jetpack-menu-jetpack-manage-subscribers',
1001 - array( 'site' => $blog_id ? $blog_id : $status->get_site_suffix() )
1106 + 'jetpack-menu-calypso-subscribers',
1107 + array( 'site' => $status->get_site_suffix() )
1002 1108 );
1003 1109
1004 - Admin_Menu::add_menu(
1005 - __( 'Subscribers', 'jetpack' ),
1110 + add_submenu_page(
1111 + 'jetpack',
1112 + esc_attr__( 'Subscribers', 'jetpack' ),
1006 1113 __( 'Subscribers', 'jetpack' ) . ' <span class="dashicons dashicons-external"></span>',
1007 1114 'manage_options',
1008 1115 esc_url( $link ),
1009 - null,
1010 - 11
1116 + null
1011 1117 );
1012 1118 }
1013 -
1014 - /**
1015 - * Record tracks event if categories is created when user enters
1016 - * the edit category page through the newsletter settings page.
1017 - *
1018 - * @return void
1019 - */
1020 - public function track_newsletter_category_creation() {
1021 -
1022 - // phpcs:disable WordPress.Security.NonceVerification.Missing
1023 - if ( empty( $_POST['_wp_http_referer'] ) ) {
1024 - return;
1025 - }
1026 -
1027 - if ( strpos( sanitize_url( wp_unslash( $_POST['_wp_http_referer'] ) ), 'referer=newsletter-categories' ) > -1 ) {
1028 -
1029 - $parent = filter_var( empty( $_POST['parent'] ) ? 0 : wp_unslash( $_POST['parent'] ), FILTER_SANITIZE_NUMBER_INT );
1030 -
1031 - $is_child_category = $parent > 0;
1032 -
1033 - $tracking = new Automattic\Jetpack\Tracking();
1034 - $tracking->tracks_record_event(
1035 - wp_get_current_user(),
1036 - 'jetpack_newsletter_add_category',
1037 - array(
1038 - 'is_child_category' => $is_child_category,
1039 - )
1040 - );
1041 - }
1042 - }
1043 1119 }
1044 1120
1045 1121 Jetpack_Subscriptions::init();
1046 1122
@@ -1045,6 +1121,4 @@
1045 1121 Jetpack_Subscriptions::init();
1046 1122
1047 1123 require __DIR__ . '/subscriptions/views.php';
1048 1124 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';