| @@ -134,8 +134,19 @@ | ||
| 134 | 134 | add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 ); |
| 135 | 135 | |
| 136 | 136 | // Add Subscribers menu to Jetpack navigation. |
| 137 | 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 ); | |
| 138 | 149 | } |
| 139 | 150 | |
| 140 | 151 | /** |
| 141 | 152 | * Jetpack_Subscriptions::xmlrpc_methods() |
| @@ -395,47 +406,8 @@ | ||
| 395 | 406 | 'discussion', |
| 396 | 407 | 'social_notifications_subscribe', |
| 397 | 408 | array( $this, 'social_notifications_subscribe_validate' ) |
| 398 | 409 | ); |
| 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 | - | |
| 431 | - add_settings_field( | |
| 432 | - 'welcome', | |
| 433 | - __( 'Welcome email text', 'jetpack' ), | |
| 434 | - array( $this, 'setting_welcome' ), | |
| 435 | - 'reading', | |
| 436 | - 'email_settings' | |
| 437 | - ); | |
| 438 | 410 | } |
| 439 | 411 | |
| 440 | 412 | /** |
| 441 | 413 | * Discussions setting section blurb. |
| @@ -573,92 +545,8 @@ | ||
| 573 | 545 | return 'on'; |
| 574 | 546 | } |
| 575 | 547 | |
| 576 | 548 | /** |
| 577 | - * Validate settings for the Subscriptions module. | |
| 578 | - * | |
| 579 | - * @param array $settings Settings to be validated. | |
| 580 | - */ | |
| 581 | - public function validate_settings( $settings ) { | |
| 582 | - global $allowedposttags; | |
| 583 | - | |
| 584 | - $default = $this->get_default_settings(); | |
| 585 | - | |
| 586 | - // Blog Follow. | |
| 587 | - $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) ); | |
| 588 | - if ( empty( $settings['invitation'] ) ) { | |
| 589 | - $settings['invitation'] = $default['invitation']; | |
| 590 | - } | |
| 591 | - | |
| 592 | - // Comments Follow (single post). | |
| 593 | - $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) ); | |
| 594 | - if ( empty( $settings['comment_follow'] ) ) { | |
| 595 | - $settings['comment_follow'] = $default['comment_follow']; | |
| 596 | - } | |
| 597 | - | |
| 598 | - return $settings; | |
| 599 | - } | |
| 600 | - | |
| 601 | - /** | |
| 602 | - * HTML output helper for Reading section. | |
| 603 | - */ | |
| 604 | - public function reading_section() { | |
| 605 | - echo '<p id="follower-settings">'; | |
| 606 | - esc_html_e( 'These settings change emails sent from your blog to followers.', 'jetpack' ); | |
| 607 | - echo '</p>'; | |
| 608 | - } | |
| 609 | - | |
| 610 | - /** | |
| 611 | - * HTML output helper for Invitation section. | |
| 612 | - */ | |
| 613 | - public function setting_invitation() { | |
| 614 | - $settings = $this->get_settings(); | |
| 615 | - echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>'; | |
| 616 | - echo '<p><span class="description">' . esc_html__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ) . '</span></p>'; | |
| 617 | - } | |
| 618 | - | |
| 619 | - /** | |
| 620 | - * HTML output helper for Comment Follow section. | |
| 621 | - */ | |
| 622 | - public function setting_comment_follow() { | |
| 623 | - $settings = $this->get_settings(); | |
| 624 | - echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>'; | |
| 625 | - echo '<p><span class="description">' . esc_html__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ) . '</span></p>'; | |
| 626 | - } | |
| 627 | - | |
| 628 | - /** | |
| 629 | - * HTML output helper for Welcome section. | |
| 630 | - */ | |
| 631 | - public function setting_welcome() { | |
| 632 | - $settings = $this->get_settings(); | |
| 633 | - echo '<textarea name="subscription_options[welcome]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['welcome'] ) . '</textarea>'; | |
| 634 | - echo '<p><span class="description">' . esc_html__( 'Welcome text sent when someone follows your blog.', 'jetpack' ) . '</span></p>'; | |
| 635 | - } | |
| 636 | - | |
| 637 | - /** | |
| 638 | - * Get default settings for the Subscriptions module. | |
| 639 | - */ | |
| 640 | - public function get_default_settings() { | |
| 641 | - $site_url = get_home_url(); | |
| 642 | - $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) ); | |
| 643 | - | |
| 644 | - return array( | |
| 645 | - /* translators: Both %1$s and %2$s is site address */ | |
| 646 | - 'invitation' => sprintf( __( "Howdy,\nYou recently subscribed to <a href='%1\$s'>%2\$s</a> and we need to verify the email you provided. Once you confirm below, you'll be able to receive and read new posts.\n\nIf you believe this is an error, ignore this message and nothing more will happen.", 'jetpack' ), $site_url, $display_url ), | |
| 647 | - 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ), | |
| 648 | - /* translators: %1$s is the site address */ | |
| 649 | - 'welcome' => sprintf( __( 'Cool, you are now subscribed to %1$s and will receive an email notification when a new post is published.', 'jetpack' ), $display_url ), | |
| 650 | - ); | |
| 651 | - } | |
| 652 | - | |
| 653 | - /** | |
| 654 | - * Reeturn merged `subscription_options` option with module default settings. | |
| 655 | - */ | |
| 656 | - public function get_settings() { | |
| 657 | - return wp_parse_args( (array) get_option( 'subscription_options' ), $this->get_default_settings() ); | |
| 658 | - } | |
| 659 | - | |
| 660 | - /** | |
| 661 | 549 | * Jetpack_Subscriptions::subscribe() |
| 662 | 550 | * |
| 663 | 551 | * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request. |
| 664 | 552 | * |
| @@ -1071,9 +959,19 @@ | ||
| 1071 | 959 | * |
| 1072 | 960 | * @return bool |
| 1073 | 961 | */ |
| 1074 | 962 | public function first_published_status_meta_auth_callback() { |
| 1075 | - if ( current_user_can( 'publish_posts' ) ) { | |
| 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 ) ) { | |
| 1076 | 974 | return true; |
| 1077 | 975 | } |
| 1078 | 976 | return false; |
| 1079 | 977 | } |
| @@ -1105,12 +1003,12 @@ | ||
| 1105 | 1003 | * @return void |
| 1106 | 1004 | */ |
| 1107 | 1005 | public function add_subscribers_menu() { |
| 1108 | 1006 | /* |
| 1109 | - * Do not display any menu on WoA and WordPress.com Simple sites. | |
| 1007 | + * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled). | |
| 1110 | 1008 | * They already get a menu item under Users via nav-unification. |
| 1111 | 1009 | */ |
| 1112 | - if ( ( new Host() )->is_wpcom_platform() ) { | |
| 1010 | + if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) { | |
| 1113 | 1011 | return; |
| 1114 | 1012 | } |
| 1115 | 1013 | |
| 1116 | 1014 | $status = new Status(); |
| @@ -1128,9 +1026,9 @@ | ||
| 1128 | 1026 | |
| 1129 | 1027 | $blog_id = Connection_Manager::get_site_id( true ); |
| 1130 | 1028 | |
| 1131 | 1029 | $link = Redirect::get_url( |
| 1132 | - 'jetpack-menu-calypso-subscribers', | |
| 1030 | + 'jetpack-menu-jetpack-manage-subscribers', | |
| 1133 | 1031 | array( 'site' => $blog_id ? $blog_id : $status->get_site_suffix() ) |
| 1134 | 1032 | ); |
| 1135 | 1033 | |
| 1136 | 1034 | add_submenu_page( |
| @@ -1141,8 +1039,38 @@ | ||
| 1141 | 1039 | esc_url( $link ), |
| 1142 | 1040 | null |
| 1143 | 1041 | ); |
| 1144 | 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 | + } | |
| 1145 | 1073 | } |
| 1146 | 1074 | |
| 1147 | 1075 | Jetpack_Subscriptions::init(); |
| 1148 | 1076 | |
| @@ -1147,4 +1075,5 @@ | ||
| 1147 | 1075 | Jetpack_Subscriptions::init(); |
| 1148 | 1076 | |
| 1149 | 1077 | require __DIR__ . '/subscriptions/views.php'; |
| 1150 | 1078 | require __DIR__ . '/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php'; |
| 1079 | +require __DIR__ . '/subscriptions/subscribe-overlay/class-jetpack-subscribe-overlay.php'; | |