PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 4.4.5
Jetpack – WP Security, Backup, Speed, & Growth v4.4.5
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 14.4.2 All 500 releases
← All changes | modules/subscriptions.php +59 -43 4.3.54.4.5 View file →
@@ -74,27 +74,10 @@
74 74 // Adds post meta checkbox in the post submit metabox
75 75 add_action( 'post_submitbox_misc_actions', array( $this, 'subscription_post_page_metabox' ) );
76 76
77 77 add_action( 'transition_post_status', array( $this, 'maybe_send_subscription_email' ), 10, 3 );
78 - }
79 78
80 - function post_is_public( $the_post ) {
81 - if ( !$post = get_post( $the_post ) ) {
82 - return false;
83 - }
84 -
85 - if ( 'publish' === $post->post_status && strlen( (string) $post->post_password ) < 1 ) {
86 - /**
87 - * Filter whether posts can be emailed to subscribers.
88 - *
89 - * @module subscriptions
90 - *
91 - * @since 2.4.0
92 - *
93 - * @param bool true Can the post be emailed to Subscribers. Default to true.
94 - */
95 - return apply_filters( 'jetpack_is_post_mailable', true );
96 - }
79 + add_filter( 'jetpack_published_post_flags', array( $this, 'set_post_flags' ), 10, 2 );
97 80 }
98 81
99 82 /**
100 83 * Jetpack_Subscriptions::xmlrpc_methods()
@@ -163,15 +146,23 @@
163 146 * @param $old_status string - the "old" post status of the transition when saved
164 147 * @param $post obj - The post object
165 148 */
166 149 function maybe_send_subscription_email( $new_status, $old_status, $post ) {
150 +
151 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
152 + return;
153 + }
154 +
155 + // Make sure that the checkbox is preseved
156 + if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) {
157 + $set_checkbox = isset( $_POST['_jetpack_dont_email_post_to_subs'] ) ? 1 : 0;
158 + update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', $set_checkbox );
159 + }
160 +
167 161 // Only do things on publish
168 162 if ( 'publish' !== $new_status ) {
169 163 return;
170 164 }
171 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
172 - return;
173 - }
174 165
175 166 /**
176 167 * If we're updating the post, let's make sure the flag to not send to subscribers
177 168 * is set to minimize the chances of sending posts multiple times.
@@ -179,8 +170,19 @@
179 170 if ( 'publish' == $old_status ) {
180 171 update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 );
181 172 }
182 173
174 + if ( ! $this->should_email_post_to_subscribers( $post ) ) {
175 + update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 );
176 + }
177 + }
178 +
179 + public function should_email_post_to_subscribers( $post ) {
180 + $should_email = true;
181 + if ( get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) ) {
182 + return false;
183 + }
184 +
183 185 /**
184 186 * Array of categories that will never trigger subscription emails.
185 187 *
186 188 * Will not send subscription emails from any post from within these categories.
@@ -194,9 +196,9 @@
194 196 $excluded_categories = apply_filters( 'jetpack_subscriptions_exclude_these_categories', array() );
195 197
196 198 // Never email posts from these categories
197 199 if ( ! empty( $excluded_categories ) && in_category( $excluded_categories, $post->ID ) ) {
198 - update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 );
200 + $should_email = false;
199 201 }
200 202
201 203 /**
202 204 * ONLY send subscription emails for these categories
@@ -212,19 +214,20 @@
212 214 $only_these_categories = apply_filters( 'jetpack_subscriptions_exclude_all_categories_except', array() );
213 215
214 216 // Only emails posts from these categories
215 217 if ( ! empty( $only_these_categories ) && ! in_category( $only_these_categories, $post->ID ) ) {
216 - update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 );
218 + $should_email = false;
217 219 }
218 220
219 - // Email the post, depending on the checkbox option
220 - if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) {
221 - if ( isset( $_POST['_jetpack_dont_email_post_to_subs'] ) ) {
222 - update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', $_POST['_jetpack_dont_email_post_to_subs'] );
223 - }
224 - }
221 +
222 + return $should_email;
225 223 }
226 224
225 + function set_post_flags( $flags, $post ) {
226 + $flags['send_subscription'] = $this->should_email_post_to_subscribers( $post );
227 + return $flags;
228 + }
229 +
227 230 /**
228 231 * Jetpack_Subscriptions::configure()
229 232 *
230 233 * Jetpack Subscriptions configuration screen.
@@ -583,13 +586,15 @@
583 586 $comments_checked = '';
584 587 $blog_checked = '';
585 588
586 589 // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes.
587 - if ( isset( $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] ) && $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] == $post->ID )
590 + if ( isset( $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash . '_' . $post->ID ] ) ) {
588 591 $comments_checked = ' checked="checked"';
592 + }
589 593
590 - if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) )
594 + if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) ) {
591 595 $blog_checked = ' checked="checked"';
596 + }
592 597
593 598 // Some themes call this function, don't show the checkbox again
594 599 remove_action( 'comment_form', 'subscription_comment_form' );
595 600
@@ -656,15 +661,16 @@
656 661 if ( 'spam' === $approved ) {
657 662 return;
658 663 }
659 664
665 + $comment = get_comment( $comment_id );
666 +
660 667 // Set cookies for this post/comment
661 - $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), isset( $_REQUEST['subscribe_blog'] ) );
668 + $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), $comment->comment_post_ID, isset( $_REQUEST['subscribe_blog'] ) );
662 669
663 670 if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) )
664 671 return;
665 672
666 - $comment = get_comment( $comment_id );
667 673 $post_ids = array();
668 674
669 675 if ( isset( $_REQUEST['subscribe_comments'] ) )
670 676 $post_ids[] = $comment->comment_post_ID;
@@ -688,14 +694,19 @@
688 694 /**
689 695 * Jetpack_Subscriptions::set_cookies()
690 696 *
691 697 * Set a cookie to save state on the comment and post subscription checkboxes.
698 + *
699 + * @param bool $subscribe_to_post Whether the user chose to subscribe to subsequent comments on this post.
700 + * @param int $post_id If $subscribe_to_post is true, the post ID they've subscribed to.
701 + * @param bool $subscribe_to_blog Whether the user chose to subscribe to all new posts on the blog.
692 702 */
693 - function set_cookies( $comments = true, $posts = true ) {
694 - global $post;
703 + function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) {
704 + $post_id = intval( $post_id );
695 705
696 706 /** This filter is already documented in core/wp-includes/comment-functions.php */
697 707 $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
708 +
698 709 /**
699 710 * Filter the Jetpack Comment cookie path.
700 711 *
701 712 * @module subscriptions
@@ -704,8 +715,9 @@
704 715 *
705 716 * @param string COOKIEPATH Cookie path.
706 717 */
707 718 $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH );
719 +
708 720 /**
709 721 * Filter the Jetpack Comment cookie domain.
710 722 *
711 723 * @module subscriptions
@@ -715,18 +727,21 @@
715 727 * @param string COOKIE_DOMAIN Cookie domain.
716 728 */
717 729 $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN );
718 730
719 - if ( $comments )
720 - setcookie( 'jetpack_comments_subscribe_' . self::$hash, $post->ID, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
721 - else
722 - setcookie( 'jetpack_comments_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );
731 + if ( $subscribe_to_post && $post_id >= 0 ) {
732 + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
733 + } else {
734 + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain );
735 + }
723 736
724 - if ( $posts )
737 + if ( $subscribe_to_blog ) {
725 738 setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain );
726 - else
739 + } else {
727 740 setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );
741 + }
728 742 }
743 +
729 744 }
730 745
731 746 Jetpack_Subscriptions::init();
732 747
@@ -764,10 +779,11 @@
764 779 $subscribe_email = '';
765 780 }
766 781 }
767 782
783 + /** This action is already documented in modules/widgets/gravatar-profile.php */
784 + do_action( 'jetpack_stats_extra', 'widget_view', 'jetpack_subscriptions' );
768 785
769 -
770 786 $source = 'widget';
771 787 $instance = wp_parse_args( (array) $instance, $this->defaults() );
772 788 $subscribe_text = isset( $instance['subscribe_text'] ) ? stripslashes( $instance['subscribe_text'] ) : '';
773 789 $subscribe_placeholder = isset( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : '';
@@ -964,9 +980,9 @@
964 980 'title' => esc_html__( 'Subscribe to Blog via Email', 'jetpack' ),
965 981 'subscribe_text' => esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' ),
966 982 'subscribe_placeholder' => esc_html__( 'Email Address', 'jetpack' ),
967 983 'subscribe_button' => esc_html__( 'Subscribe', 'jetpack' ),
968 - 'success_message' => esc_html__( 'Success! An email was just sent to confirm your subscription. Please find the email now and click activate to start subscribing.', 'jetpack' ),
984 + 'success_message' => esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm Follow' to start subscribing.", 'jetpack' ),
969 985 'show_subscribers_total' => true,
970 986 );
971 987 }
972 988