| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName) |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Newsletter |
| 4 | - * Module Description: Grow your subscriber list and deliver your content directly to their email inbox. | |
| 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 |
| 8 | 8 | * Requires Connection: Yes |
| 9 | 9 | * Requires User Connection: Yes |
| 10 | - * Auto Activate: Yes | |
| 10 | + * Auto Activate: No | |
| 11 | 11 | * Module Tags: Social |
| 12 | 12 | * Feature: Engagement |
| 13 | 13 | * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup, newsletter, creator |
| 14 | 14 | */ |
| @@ -17,17 +17,12 @@ | ||
| 17 | 17 | |
| 18 | 18 | use Automattic\Jetpack\Admin_UI\Admin_Menu; |
| 19 | 19 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 20 | 20 | use Automattic\Jetpack\Connection\XMLRPC_Async_Call; |
| 21 | -use Automattic\Jetpack\Newsletter\Settings as Newsletter_Settings; | |
| 22 | 21 | use Automattic\Jetpack\Redirect; |
| 23 | 22 | use Automattic\Jetpack\Status; |
| 24 | 23 | use Automattic\Jetpack\Status\Host; |
| 25 | 24 | |
| 26 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 27 | - exit( 0 ); | |
| 28 | -} | |
| 29 | - | |
| 30 | 25 | add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' ); |
| 31 | 26 | |
| 32 | 27 | // Loads the User Content Link Redirection feature. |
| 33 | 28 | require_once __DIR__ . '/subscriptions/jetpack-user-content-link-redirection.php'; |
| @@ -63,10 +58,8 @@ | ||
| 63 | 58 | } |
| 64 | 59 | |
| 65 | 60 | /** |
| 66 | 61 | * Main class file for the Subscriptions module. |
| 67 | - * | |
| 68 | - * @phan-constructor-used-for-side-effects | |
| 69 | 62 | */ |
| 70 | 63 | class Jetpack_Subscriptions { |
| 71 | 64 | /** |
| 72 | 65 | * Whether Jetpack has been instantiated or not. |
| @@ -135,10 +128,8 @@ | ||
| 135 | 128 | add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 18, 1 ); |
| 136 | 129 | |
| 137 | 130 | // Set "social_notifications_subscribe" option during the first-time activation. |
| 138 | 131 | add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_social_notifications_subscribe' ) ); |
| 139 | - add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_featured_image_in_email_default' ) ); | |
| 140 | - add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_newsletter_send_default' ) ); | |
| 141 | 132 | |
| 142 | 133 | // Hide subscription messaging in Publish panel for posts that were published in the past |
| 143 | 134 | add_action( 'init', array( $this, 'register_post_meta' ), 20 ); |
| 144 | 135 | add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 ); |
| @@ -155,11 +146,8 @@ | ||
| 155 | 146 | ); |
| 156 | 147 | |
| 157 | 148 | // Track categories created through the category editor page |
| 158 | 149 | add_action( 'wp_ajax_add-tag', array( $this, 'track_newsletter_category_creation' ), 1 ); |
| 159 | - | |
| 160 | - $newsletter_settings = new Newsletter_Settings(); | |
| 161 | - $newsletter_settings::init(); | |
| 162 | 150 | } |
| 163 | 151 | |
| 164 | 152 | /** |
| 165 | 153 | * Jetpack_Subscriptions::xmlrpc_methods() |
| @@ -567,9 +555,8 @@ | ||
| 567 | 555 | |
| 568 | 556 | if ( $async ) { |
| 569 | 557 | XMLRPC_Async_Call::add_call( 'jetpack.subscribeToSite', 0, $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize |
| 570 | 558 | } else { |
| 571 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false | |
| 572 | 559 | $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize |
| 573 | 560 | } |
| 574 | 561 | } |
| 575 | 562 | |
| @@ -577,24 +564,19 @@ | ||
| 577 | 564 | return; |
| 578 | 565 | } |
| 579 | 566 | |
| 580 | 567 | // Call. |
| 581 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early | |
| 582 | 568 | $xml->query(); |
| 583 | 569 | |
| 584 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early | |
| 585 | 570 | if ( $xml->isError() ) { |
| 586 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early | |
| 587 | 571 | return $xml->get_jetpack_error(); |
| 588 | 572 | } |
| 589 | 573 | |
| 590 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false | |
| 591 | 574 | $responses = $xml->getResponse(); |
| 592 | 575 | |
| 593 | 576 | $r = array(); |
| 594 | 577 | foreach ( (array) $responses as $response ) { |
| 595 | 578 | if ( isset( $response['faultCode'] ) || isset( $response['faultString'] ) ) { |
| 596 | - // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false | |
| 597 | 579 | $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] ); |
| 598 | 580 | continue; |
| 599 | 581 | } |
| 600 | 582 | |
| @@ -810,19 +792,8 @@ | ||
| 810 | 792 | * @param int|string $comment_id Comment thread being subscribed to. |
| 811 | 793 | * @param string $approved Comment status. |
| 812 | 794 | */ |
| 813 | 795 | public function comment_subscribe_submit( $comment_id, $approved ) { |
| 814 | - /** | |
| 815 | - * Filters whether to skip comment subscription processing. | |
| 816 | - * | |
| 817 | - * @since 15.5 | |
| 818 | - * | |
| 819 | - * @param bool $skip Whether to skip comment subscription. Default false. | |
| 820 | - */ | |
| 821 | - if ( apply_filters( 'jetpack_subscription_comment_subscribe_skip', false ) ) { | |
| 822 | - return; | |
| 823 | - } | |
| 824 | - | |
| 825 | 796 | if ( 'spam' === $approved ) { |
| 826 | 797 | return; |
| 827 | 798 | } |
| 828 | 799 | |
| @@ -885,9 +856,9 @@ | ||
| 885 | 856 | public function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) { |
| 886 | 857 | $post_id = (int) $post_id; |
| 887 | 858 | |
| 888 | 859 | /** This filter is already documented in core/wp-includes/comment-functions.php */ |
| 889 | - $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', YEAR_IN_SECONDS ); | |
| 860 | + $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); | |
| 890 | 861 | |
| 891 | 862 | /** |
| 892 | 863 | * Filter the Jetpack Comment cookie path. |
| 893 | 864 | * |
| @@ -910,15 +881,15 @@ | ||
| 910 | 881 | */ |
| 911 | 882 | $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN ); |
| 912 | 883 | |
| 913 | 884 | if ( $subscribe_to_post && $post_id >= 0 ) { |
| 914 | - setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '1', time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 885 | + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 915 | 886 | } else { |
| 916 | 887 | setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true ); |
| 917 | 888 | } |
| 918 | 889 | |
| 919 | 890 | if ( $subscribe_to_blog ) { |
| 920 | - setcookie( 'jetpack_blog_subscribe_' . self::$hash, '1', time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 891 | + setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 921 | 892 | } else { |
| 922 | 893 | setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true ); |
| 923 | 894 | } |
| 924 | 895 | } |
| @@ -936,26 +907,8 @@ | ||
| 936 | 907 | } |
| 937 | 908 | } |
| 938 | 909 | |
| 939 | 910 | /** |
| 940 | - * Set the featured image in email option to `1` when the Subscriptions module is activated in the first time. | |
| 941 | - * | |
| 942 | - * @return void | |
| 943 | - */ | |
| 944 | - public function set_featured_image_in_email_default() { | |
| 945 | - add_option( 'wpcom_featured_image_in_email', 1 ); | |
| 946 | - } | |
| 947 | - | |
| 948 | - /** | |
| 949 | - * Set the email post to subscribers default option to `1` when the Subscriptions module is activated for the first time. | |
| 950 | - * | |
| 951 | - * @return void | |
| 952 | - */ | |
| 953 | - public function set_newsletter_send_default() { | |
| 954 | - add_option( 'wpcom_newsletter_send_default', 1 ); | |
| 955 | - } | |
| 956 | - | |
| 957 | - /** | |
| 958 | 911 | * Save a flag when a post was ever published. |
| 959 | 912 | * |
| 960 | 913 | * It saves the post meta when the post was published and becomes a draft. |
| 961 | 914 | * Then this meta is used to hide subscription messaging in Publish panel. |
| @@ -964,13 +917,8 @@ | ||
| 964 | 917 | * @param string $old_status The "old" post status of the transition when saved. |
| 965 | 918 | * @param object $post obj The post object. |
| 966 | 919 | */ |
| 967 | 920 | public function maybe_set_first_published_status( $new_status, $old_status, $post ) { |
| 968 | - // Subscriptions are only available for posts so far. | |
| 969 | - if ( ! $post instanceof \WP_Post || 'post' !== $post->post_type ) { | |
| 970 | - return; | |
| 971 | - } | |
| 972 | - | |
| 973 | 921 | $was_post_ever_published = get_post_meta( $post->ID, '_jetpack_post_was_ever_published', true ); |
| 974 | 922 | if ( ! $was_post_ever_published && 'publish' === $old_status && 'draft' === $new_status ) { |
| 975 | 923 | update_post_meta( $post->ID, '_jetpack_post_was_ever_published', true ); |
| 976 | 924 | } |
| @@ -976,23 +924,23 @@ | ||
| 976 | 924 | } |
| 977 | 925 | } |
| 978 | 926 | |
| 979 | 927 | /** |
| 980 | - * Checks if the current user can edit posts. | |
| 928 | + * Checks if the current user can publish posts. | |
| 981 | 929 | * |
| 982 | 930 | * @return bool |
| 983 | 931 | */ |
| 984 | 932 | public function first_published_status_meta_auth_callback() { |
| 985 | 933 | /** |
| 986 | - * Filter the capability required to edit the "was ever published" post meta. | |
| 934 | + * Filter the capability to view if a post was ever published in the Subscription Module. | |
| 987 | 935 | * |
| 988 | 936 | * @module subscriptions |
| 989 | 937 | * |
| 990 | 938 | * @since 13.4 |
| 991 | 939 | * |
| 992 | - * @param string $capability User capability needed to edit the "was ever published" meta. Default to edit_posts. | |
| 940 | + * @param string $capability User capability needed to view if a post was ever published. Default to publish_posts. | |
| 993 | 941 | */ |
| 994 | - $capability = apply_filters( 'jetpack_subscriptions_post_was_ever_published_capability', 'edit_posts' ); | |
| 942 | + $capability = apply_filters( 'jetpack_subscriptions_post_was_ever_published_capability', 'publish_posts' ); | |
| 995 | 943 | if ( current_user_can( $capability ) ) { |
| 996 | 944 | return true; |
| 997 | 945 | } |
| 998 | 946 | return false; |
| @@ -1002,17 +950,16 @@ | ||
| 1002 | 950 | * Registers the 'post_was_ever_published' post meta for use in the REST API. |
| 1003 | 951 | */ |
| 1004 | 952 | public function register_post_meta() { |
| 1005 | 953 | $jetpack_post_was_ever_published = array( |
| 1006 | - 'type' => 'boolean', | |
| 1007 | - 'description' => __( 'Whether the post was ever published.', 'jetpack' ), | |
| 1008 | - 'single' => true, | |
| 1009 | - 'default' => false, | |
| 1010 | - 'show_in_rest' => array( | |
| 954 | + 'type' => 'boolean', | |
| 955 | + 'description' => __( 'Whether the post was ever published.', 'jetpack' ), | |
| 956 | + 'single' => true, | |
| 957 | + 'default' => false, | |
| 958 | + 'show_in_rest' => array( | |
| 1011 | 959 | 'name' => 'jetpack_post_was_ever_published', |
| 1012 | 960 | ), |
| 1013 | - 'auth_callback' => array( $this, 'first_published_status_meta_auth_callback' ), | |
| 1014 | - 'object_subtype' => 'post', // Subscriptions are only for the post post type so far, so we can limit this meta to posts only. | |
| 961 | + 'auth_callback' => array( $this, 'first_published_status_meta_auth_callback' ), | |
| 1015 | 962 | ); |
| 1016 | 963 | |
| 1017 | 964 | register_meta( 'post', '_jetpack_post_was_ever_published', $jetpack_post_was_ever_published ); |
| 1018 | 965 | } |
| @@ -1021,24 +968,13 @@ | ||
| 1021 | 968 | * Create a Subscribers menu displayed on self-hosted sites. |
| 1022 | 969 | * |
| 1023 | 970 | * - It is not displayed on WordPress.com sites. |
| 1024 | 971 | * - It directs you to Calypso to the existing Subscribers page. |
| 1025 | - * - It is retired once the Newsletter modernization filter is on, since the | |
| 1026 | - * unified Newsletter page then owns the Subscribers tab. | |
| 1027 | 972 | * |
| 1028 | 973 | * @return void |
| 1029 | 974 | */ |
| 1030 | 975 | public function add_subscribers_menu() { |
| 1031 | 976 | /* |
| 1032 | - * Referenced as a string literal (mirrors Newsletter\Settings::MODERNIZATION_FILTER) | |
| 1033 | - * to keep this bootstrap path safe if the packaged Newsletter Settings class does | |
| 1034 | - * not expose the constant yet. | |
| 1035 | - */ | |
| 1036 | - if ( apply_filters( 'rsm_jetpack_ui_modernization_newsletter', true ) ) { | |
| 1037 | - return; | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | - /* | |
| 1041 | 977 | * Do not display any menu on WoA and WordPress.com Simple sites (unless Classic wp-admin is enabled). |
| 1042 | 978 | * They already get a menu item under Users via nav-unification. |
| 1043 | 979 | */ |
| 1044 | 980 | if ( ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) { |
| @@ -1057,20 +993,8 @@ | ||
| 1057 | 993 | ) { |
| 1058 | 994 | return; |
| 1059 | 995 | } |
| 1060 | 996 | |
| 1061 | - /** | |
| 1062 | - * Enables the new in development subscribers in wp-admin dashboard. | |
| 1063 | - * | |
| 1064 | - * @since 9.5.0 | |
| 1065 | - * | |
| 1066 | - * @param bool If the new dashboard is enabled. Defaults on for every site; hosts | |
| 1067 | - * can opt out with this filter. | |
| 1068 | - */ | |
| 1069 | - if ( apply_filters( 'jetpack_wp_admin_subscriber_management_enabled', true ) ) { | |
| 1070 | - return; | |
| 1071 | - } | |
| 1072 | - | |
| 1073 | 997 | $blog_id = Connection_Manager::get_site_id( true ); |
| 1074 | 998 | |
| 1075 | 999 | $link = Redirect::get_url( |
| 1076 | 1000 | 'jetpack-menu-jetpack-manage-subscribers', |
| @@ -1078,13 +1002,13 @@ | ||
| 1078 | 1002 | ); |
| 1079 | 1003 | |
| 1080 | 1004 | Admin_Menu::add_menu( |
| 1081 | 1005 | __( 'Subscribers', 'jetpack' ), |
| 1082 | - __( 'Subscribers', 'jetpack' ) . ' <span aria-hidden="true">↗</span>', | |
| 1006 | + __( 'Subscribers', 'jetpack' ) . ' <span class="dashicons dashicons-external"></span>', | |
| 1083 | 1007 | 'manage_options', |
| 1084 | 1008 | esc_url( $link ), |
| 1085 | 1009 | null, |
| 1086 | - 15 | |
| 1010 | + 11 | |
| 1087 | 1011 | ); |
| 1088 | 1012 | } |
| 1089 | 1013 | |
| 1090 | 1014 | /** |
| @@ -1123,8 +1047,4 @@ | ||
| 1123 | 1047 | require __DIR__ . '/subscriptions/views.php'; |
| 1124 | 1048 | require __DIR__ . '/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php'; |
| 1125 | 1049 | require __DIR__ . '/subscriptions/subscribe-overlay/class-jetpack-subscribe-overlay.php'; |
| 1126 | 1050 | require __DIR__ . '/subscriptions/subscribe-floating-button/class-jetpack-subscribe-floating-button.php'; |
| 1127 | -require __DIR__ . '/subscriptions/newsletter-widget/class-jetpack-newsletter-dashboard-widget.php'; | |
| 1128 | - | |
| 1129 | -require_once __DIR__ . '/subscriptions/abilities/class-newsletter-abilities.php'; | |
| 1130 | -\Automattic\Jetpack\Plugin\Abilities\Newsletter_Abilities::init(); | |