PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.2
Jetpack – WP Security, Backup, Speed, & Growth v12.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 +117 -129 14.2.212.2 View file →
@@ -1,7 +1,7 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName)
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,25 +9,17 @@
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 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 -use Automattic\Jetpack\Connection\Manager as Connection_Manager;
20 18 use Automattic\Jetpack\Connection\XMLRPC_Async_Call;
21 -use Automattic\Jetpack\Redirect;
22 -use Automattic\Jetpack\Status;
23 -use Automattic\Jetpack\Status\Host;
24 19
25 20 add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' );
26 21
27 -// Loads the User Content Link Redirection feature.
28 -require_once __DIR__ . '/subscriptions/jetpack-user-content-link-redirection.php';
29 -
30 22 /**
31 23 * Loads the Subscriptions module.
32 24 */
33 25 function jetpack_subscriptions_load() {
@@ -44,13 +36,13 @@
44 36 function jetpack_subscriptions_cherry_pick_server_data() {
45 37 $data = array();
46 38
47 39 foreach ( $_SERVER as $key => $value ) {
48 - if ( ! is_string( $value ) || str_starts_with( $key, 'HTTP_COOKIE' ) ) {
40 + if ( ! is_string( $value ) || 0 === strpos( $key, 'HTTP_COOKIE' ) ) {
49 41 continue;
50 42 }
51 43
52 - if ( str_starts_with( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
44 + if ( 0 === strpos( $key, 'HTTP_' ) || in_array( $key, array( 'REMOTE_ADDR', 'REQUEST_URI', 'DOCUMENT_URI' ), true ) ) {
53 45 $data[ $key ] = $value;
54 46 }
55 47 }
56 48
@@ -132,22 +124,8 @@
132 124
133 125 // Hide subscription messaging in Publish panel for posts that were published in the past
134 126 add_action( 'init', array( $this, 'register_post_meta' ), 20 );
135 127 add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 );
136 -
137 - // Add Subscribers menu to Jetpack navigation.
138 - add_action( 'jetpack_admin_menu', array( $this, 'add_subscribers_menu' ) );
139 -
140 - // Customize the configuration URL to lead to the Subscriptions settings.
141 - add_filter(
142 - 'jetpack_module_configuration_url_subscriptions',
143 - function () {
144 - return Jetpack::admin_url( array( 'page' => 'jetpack#/newsletter' ) );
145 - }
146 - );
147 -
148 - // Track categories created through the category editor page
149 - add_action( 'wp_ajax_add-tag', array( $this, 'track_newsletter_category_creation' ), 1 );
150 128 }
151 129
152 130 /**
153 131 * Jetpack_Subscriptions::xmlrpc_methods()
@@ -369,14 +347,14 @@
369 347 'discussion',
370 348 'stc_enabled'
371 349 );
372 350
373 - /** Email me whenever: Someone subscribes to my blog */
351 + /** Email me whenever: Someone follows my blog */
374 352 /* @since 8.1 */
375 353
376 354 add_settings_section(
377 355 'notifications_section',
378 - __( 'Someone subscribes to my blog', 'jetpack' ),
356 + __( 'Someone follows my blog', 'jetpack' ),
379 357 array( $this, 'social_notifications_subscribe_section' ),
380 358 'discussion'
381 359 );
382 360
@@ -392,8 +370,39 @@
392 370 'discussion',
393 371 'social_notifications_subscribe',
394 372 array( $this, 'social_notifications_subscribe_validate' )
395 373 );
374 +
375 + /** Subscription Messaging Options */
376 +
377 + register_setting(
378 + 'reading',
379 + 'subscription_options',
380 + array( $this, 'validate_settings' )
381 + );
382 +
383 + add_settings_section(
384 + 'email_settings',
385 + __( 'Follower Settings', 'jetpack' ),
386 + array( $this, 'reading_section' ),
387 + 'reading'
388 + );
389 +
390 + add_settings_field(
391 + 'invitation',
392 + __( 'Blog follow email text', 'jetpack' ),
393 + array( $this, 'setting_invitation' ),
394 + 'reading',
395 + 'email_settings'
396 + );
397 +
398 + add_settings_field(
399 + 'comment-follow',
400 + __( 'Comment follow email text', 'jetpack' ),
401 + array( $this, 'setting_comment_follow' ),
402 + 'reading',
403 + 'email_settings'
404 + );
396 405 }
397 406
398 407 /**
399 408 * Discussions setting section blurb.
@@ -452,9 +461,9 @@
452 461 <?php
453 462 }
454 463
455 464 /**
456 - * Someone subscribes to my blog section
465 + * Someone follows my blog section
457 466 *
458 467 * @since 8.1
459 468 */
460 469 public function social_notifications_subscribe_section() {
@@ -478,9 +487,9 @@
478 487 <?php
479 488 }
480 489
481 490 /**
482 - * Someone subscribes to my blog Toggle
491 + * Someone follows my blog Toggle
483 492 *
484 493 * @since 8.1
485 494 */
486 495 public function social_notifications_subscribe_field() {
@@ -490,9 +499,9 @@
490 499 <label>
491 500 <input type="checkbox" name="social_notifications_subscribe" id="social_notifications_subscribe" value="1" <?php checked( $checked ); ?> />
492 501 <?php
493 502 /* translators: this is a label for a setting that starts with "Email me whenever" */
494 - esc_html_e( 'Someone subscribes to my blog', 'jetpack' );
503 + esc_html_e( 'Someone follows my blog', 'jetpack' );
495 504 ?>
496 505 </label>
497 506 <?php
498 507 }
@@ -497,9 +506,9 @@
497 506 <?php
498 507 }
499 508
500 509 /**
501 - * Validate "Someone subscribes to my blog" option
510 + * Validate "Someone follows my blog" option
502 511 *
503 512 * @since 8.1
504 513 *
505 514 * @param String $input the input string to be validated.
@@ -515,8 +524,81 @@
515 524 return 'on';
516 525 }
517 526
518 527 /**
528 + * Validate settings for the Subscriptions module.
529 + *
530 + * @param array $settings Settings to be validated.
531 + */
532 + public function validate_settings( $settings ) {
533 + global $allowedposttags;
534 +
535 + $default = $this->get_default_settings();
536 +
537 + // Blog Follow.
538 + $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) );
539 + if ( empty( $settings['invitation'] ) ) {
540 + $settings['invitation'] = $default['invitation'];
541 + }
542 +
543 + // Comments Follow (single post).
544 + $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) );
545 + if ( empty( $settings['comment_follow'] ) ) {
546 + $settings['comment_follow'] = $default['comment_follow'];
547 + }
548 +
549 + return $settings;
550 + }
551 +
552 + /**
553 + * HTML output helper for Reading section.
554 + */
555 + public function reading_section() {
556 + echo '<p id="follower-settings">';
557 + esc_html_e( 'These settings change emails sent from your blog to followers.', 'jetpack' );
558 + echo '</p>';
559 + }
560 +
561 + /**
562 + * HTML output helper for Invitation section.
563 + */
564 + public function setting_invitation() {
565 + $settings = $this->get_settings();
566 + echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>';
567 + 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>';
568 + }
569 +
570 + /**
571 + * HTML output helper for Comment Follow section.
572 + */
573 + public function setting_comment_follow() {
574 + $settings = $this->get_settings();
575 + echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>';
576 + 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>';
577 + }
578 +
579 + /**
580 + * Get default settings for the Subscriptions module.
581 + */
582 + public function get_default_settings() {
583 + $site_url = get_home_url();
584 + $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) );
585 +
586 + return array(
587 + /* translators: Both %1$s and %2$s is site address */
588 + '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 ),
589 + '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' ),
590 + );
591 + }
592 +
593 + /**
594 + * Reeturn merged `subscription_options` option with module default settings.
595 + */
596 + public function get_settings() {
597 + return wp_parse_args( (array) get_option( 'subscription_options' ), $this->get_default_settings() );
598 + }
599 +
600 + /**
519 601 * Jetpack_Subscriptions::subscribe()
520 602 *
521 603 * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
522 604 *
@@ -616,10 +698,10 @@
616 698 * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method.
617 699 */
618 700 public function widget_submit() {
619 701 // 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;
702 + if ( is_user_logged_in() ) {
703 + check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() );
622 704 }
623 705
624 706 if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) {
625 707 return false;
@@ -707,13 +789,8 @@
707 789 */
708 790 public function comment_subscribe_init( $submit_button ) {
709 791 global $post;
710 792
711 - // Subscriptions are only available for posts so far.
712 - if ( ! $post || 'post' !== $post->post_type ) {
713 - return $submit_button;
714 - }
715 -
716 793 $comments_checked = '';
717 794 $blog_checked = '';
718 795
719 796 // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
@@ -929,19 +1006,9 @@
929 1006 *
930 1007 * @return bool
931 1008 */
932 1009 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 ) ) {
1010 + if ( current_user_can( 'publish_posts' ) ) {
944 1011 return true;
945 1012 }
946 1013 return false;
947 1014 }
@@ -963,88 +1030,9 @@
963 1030
964 1031 register_meta( 'post', '_jetpack_post_was_ever_published', $jetpack_post_was_ever_published );
965 1032 }
966 1033
967 - /**
968 - * Create a Subscribers menu displayed on self-hosted sites.
969 - *
970 - * - It is not displayed on WordPress.com sites.
971 - * - It directs you to Calypso to the existing Subscribers page.
972 - *
973 - * @return void
974 - */
975 - public function add_subscribers_menu() {
976 - /*
977 - * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled).
978 - * They already get a menu item under Users via nav-unification.
979 - */
980 - if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
981 - return;
982 - }
983 -
984 - $status = new Status();
985 -
986 - /*
987 - * Do not display if we're in Offline mode,
988 - * or if the user is not connected.
989 - */
990 - if (
991 - $status->is_offline_mode()
992 - || ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected()
993 - ) {
994 - return;
995 - }
996 -
997 - $blog_id = Connection_Manager::get_site_id( true );
998 -
999 - $link = Redirect::get_url(
1000 - 'jetpack-menu-jetpack-manage-subscribers',
1001 - array( 'site' => $blog_id ? $blog_id : $status->get_site_suffix() )
1002 - );
1003 -
1004 - Admin_Menu::add_menu(
1005 - __( 'Subscribers', 'jetpack' ),
1006 - __( 'Subscribers', 'jetpack' ) . ' <span class="dashicons dashicons-external"></span>',
1007 - 'manage_options',
1008 - esc_url( $link ),
1009 - null,
1010 - 11
1011 - );
1012 - }
1013 -
1014 - /**
1015 - * Record tracks event if categories is created when user enters
1016 - * the edit category page through the newsletter settings page.
1017 - *
1018 - * @return void
1019 - */
1020 - public function track_newsletter_category_creation() {
1021 -
1022 - // phpcs:disable WordPress.Security.NonceVerification.Missing
1023 - if ( empty( $_POST['_wp_http_referer'] ) ) {
1024 - return;
1025 - }
1026 -
1027 - if ( strpos( sanitize_url( wp_unslash( $_POST['_wp_http_referer'] ) ), 'referer=newsletter-categories' ) > -1 ) {
1028 -
1029 - $parent = filter_var( empty( $_POST['parent'] ) ? 0 : wp_unslash( $_POST['parent'] ), FILTER_SANITIZE_NUMBER_INT );
1030 -
1031 - $is_child_category = $parent > 0;
1032 -
1033 - $tracking = new Automattic\Jetpack\Tracking();
1034 - $tracking->tracks_record_event(
1035 - wp_get_current_user(),
1036 - 'jetpack_newsletter_add_category',
1037 - array(
1038 - 'is_child_category' => $is_child_category,
1039 - )
1040 - );
1041 - }
1042 - }
1043 1034 }
1044 1035
1045 1036 Jetpack_Subscriptions::init();
1046 1037
1047 1038 require __DIR__ . '/subscriptions/views.php';
1048 -require __DIR__ . '/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php';
1049 -require __DIR__ . '/subscriptions/subscribe-overlay/class-jetpack-subscribe-overlay.php';
1050 -require __DIR__ . '/subscriptions/subscribe-floating-button/class-jetpack-subscribe-floating-button.php';