PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.0.3
Jetpack – WP Security, Backup, Speed, & Growth v12.0.3
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 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / _inc / lib / functions.wp-notify.php
jetpack / _inc / lib Last commit date
admin-pages 3 years ago core-api 3 years ago debugger 3 years ago markdown 4 years ago class-jetpack-ai-helper.php 3 years ago class-jetpack-currencies.php 5 years ago class-jetpack-google-drive-helper.php 3 years ago class-jetpack-instagram-gallery-helper.php 3 years ago class-jetpack-mapbox-helper.php 3 years ago class-jetpack-podcast-feed-locator.php 5 years ago class-jetpack-podcast-helper.php 3 years ago class-jetpack-recommendations.php 4 years ago class-jetpack-tweetstorm-helper.php 3 years ago class-jetpack-wizard.php 5 years ago class.color.php 4 years ago class.core-rest-api-endpoints.php 3 years ago class.jetpack-automatic-install-skin.php 4 years ago class.jetpack-iframe-embed.php 4 years ago class.jetpack-keyring-service-helper.php 4 years ago class.jetpack-password-checker.php 3 years ago class.jetpack-photon-image-sizes.php 3 years ago class.jetpack-photon-image.php 4 years ago class.jetpack-search-performance-logger.php 4 years ago class.media-extractor.php 3 years ago class.media-summary.php 3 years ago class.media.php 3 years ago components.php 3 years ago debugger.php 4 years ago functions.wp-notify.php 4 years ago icalendar-reader.php 3 years ago markdown.php 3 years ago plans.php 4 years ago plugins.php 4 years ago tonesque.php 3 years ago widgets.php 4 years ago
functions.wp-notify.php
427 lines
1 <?php
2 /** phpcs:disable Squiz.Commenting.FileComment.MissingPackageTag,Generic.Commenting.DocComment.MissingShort
3 *
4 * Declare two functions to handle notification emails to authors and moderators.
5 *
6 * These functions are hooked into filters to short circuit the regular flow and send the emails.
7 * Code was copied from the original pluggable functions and slightly modified (modifications are commented).
8 *
9 * In the past, we used to overwrite the whole pluggable function, but we started using filters to avoid having
10 * to check for Jetpack::is_active() too early in the load flow.
11 */
12
13 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
14 use Automattic\Jetpack\Redirect;
15
16 // phpcs:disable WordPress.WP.I18n.MissingArgDomain --reason: Code copied from Core, so using Core strings.
17 // phpcs:disable WordPress.Utils.I18nTextDomainFixer.MissingArgDomain --reason: Code copied from Core, so using Core strings.
18
19 /**
20 * Short circuits the {@see `wp_notify_postauthor`} function via the `comment_notification_recipients` filter.
21 *
22 * Notify an author (and/or others) of a comment/trackback/pingback on a post.
23 *
24 * @since 5.8.0
25 * @since 9.3.0 Switched from pluggable function to filter callback
26 *
27 * @param array $emails List of recipients.
28 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
29 * @return array Empty array to shortcircuit wp_notify_postauthor execution. $emails if we want to disable the filter.
30 */
31 function jetpack_notify_postauthor( $emails, $comment_id ) {
32 // Don't do anything if Jetpack isn't connected.
33 if ( ! Jetpack::is_connection_ready() || empty( $emails ) ) {
34 return $emails;
35 }
36
37 // Original function modified: Code before the comment_notification_recipients filter removed.
38
39 $comment = get_comment( $comment_id );
40 if ( ! $comment ) {
41 return $emails;
42 }
43
44 $post = get_post( $comment->comment_post_ID );
45 $author = get_userdata( $post->post_author );
46
47 // Facilitate unsetting below without knowing the keys.
48 $emails = array_flip( $emails );
49
50 /** This filter is documented in core/src/wp-includes/pluggable.php */
51 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID );
52
53 // The comment was left by the author.
54 if ( $author && ! $notify_author && $comment->user_id === $post->post_author ) {
55 unset( $emails[ $author->user_email ] );
56 }
57
58 // The author moderated a comment on their own post.
59 if ( $author && ! $notify_author && get_current_user_id() === $post->post_author ) {
60 unset( $emails[ $author->user_email ] );
61 }
62
63 // The post author is no longer a member of the blog.
64 if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
65 unset( $emails[ $author->user_email ] );
66 }
67
68 // If there's no email to send the comment to, bail, otherwise flip array back around for use below.
69 if ( ! count( $emails ) ) {
70 return array(); // Original function modified. Return empty array instead of false.
71 } else {
72 $emails = array_flip( $emails );
73 }
74
75 $switched_locale = switch_to_locale( get_locale() );
76
77 $comment_author_domain = '';
78 if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
79 $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
80 }
81
82 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
83 // we want to reverse this for the plain text arena of emails.
84 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
85 $comment_content = wp_specialchars_decode( $comment->comment_content );
86
87 // Original function modified.
88 $moderate_on_wpcom = ! in_array( // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
89 false,
90 array_map( 'jetpack_notify_is_user_connected_by_email', $emails )
91 );
92
93 switch ( $comment->comment_type ) {
94 case 'trackback':
95 /* translators: 1: Post title */
96 $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
97 /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
98 $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
99 /* translators: %s: Site URL */
100 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
101 /* translators: %s: Comment Content */
102 $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
103 $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
104 /* translators: 1: blog name, 2: post title */
105 $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title );
106 break;
107 case 'pingback':
108 /* translators: 1: Post title */
109 $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
110 /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
111 $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
112 /* translators: %s: Site URL */
113 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
114 /* translators: %s: Comment Content */
115 $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
116 $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
117 /* translators: 1: blog name, 2: post title */
118 $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
119 break;
120 default: // Comments.
121 /* translators: 1: Post title */
122 $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
123 /* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */
124 $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
125 /* translators: %s: Email address */
126 $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
127 /* translators: %s: Site URL */
128 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
129 /* translators: %s: Comment Content */
130 $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
131 $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n";
132 /* translators: 1: blog name, 2: post title */
133 $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title );
134 break;
135 }
136
137 // Original function modified: Consider $moderate_on_wpcom when building $notify_message.
138 $notify_message .= $moderate_on_wpcom
139 ? Redirect::get_url(
140 'calypso-comments-all',
141 array(
142 'path' => $comment->comment_post_ID,
143 )
144 ) . "/\r\n\r\n"
145 : get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
146
147 /* translators: %s: URL */
148 $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
149
150 $base_wpcom_edit_comment_url = Redirect::get_url(
151 'calypso-edit-comment',
152 array(
153 'path' => $comment_id,
154 'query' => 'action=__action__', // __action__ will be replaced by the actual action.
155 )
156 );
157
158 // Original function modified: Consider $moderate_on_wpcom when building $notify_message.
159 if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
160 if ( EMPTY_TRASH_DAYS ) {
161 $notify_message .= sprintf(
162 /* translators: Placeholder is the edit URL */
163 __( 'Trash it: %s' ),
164 $moderate_on_wpcom
165 ? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url )
166 : admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" )
167 ) . "\r\n";
168 } else {
169 $notify_message .= sprintf(
170 /* translators: Placeholder is the edit URL */
171 __( 'Delete it: %s' ),
172 $moderate_on_wpcom
173 ? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url )
174 : admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" )
175 ) . "\r\n";
176 }
177 $notify_message .= sprintf(
178 /* translators: Placeholder is the edit URL */
179 __( 'Spam it: %s' ),
180 $moderate_on_wpcom
181 ? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url )
182 : admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" )
183 ) . "\r\n";
184 }
185
186 $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( isset( $_SERVER['SERVER_NAME'] ) ? filter_var( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '' ) );
187
188 if ( '' === $comment->comment_author ) {
189 $from = "From: \"$blogname\" <$wp_email>";
190 if ( '' !== $comment->comment_author_email ) {
191 $reply_to = "Reply-To: $comment->comment_author_email";
192 }
193 } else {
194 $from = "From: \"$comment->comment_author\" <$wp_email>";
195 if ( '' !== $comment->comment_author_email ) {
196 $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
197 }
198 }
199
200 $message_headers = "$from\n"
201 . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
202
203 if ( isset( $reply_to ) ) {
204 $message_headers .= $reply_to . "\n";
205 }
206
207 /** This filter is documented in core/src/wp-includes/pluggable.php */
208 $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID );
209
210 /** This filter is documented in core/src/wp-includes/pluggable.php */
211 $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID );
212
213 /** This filter is documented in core/src/wp-includes/pluggable.php */
214 $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
215
216 foreach ( $emails as $email ) {
217 wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
218 }
219
220 if ( $switched_locale ) {
221 restore_previous_locale();
222 }
223
224 return array();
225 }
226
227 /**
228 * Short circuits the {@see `wp_notify_moderator`} function via the `notify_moderator` filter.
229 *
230 * Notifies the moderator of the site about a new comment that is awaiting approval.
231 *
232 * @since 5.8.0
233 * @since 9.2.0 Switched from pluggable function to filter callback
234 * @since 9.5.0 Updated the passing condition to call get_option( 'moderation_notify' ); directly.
235 *
236 * @global wpdb $wpdb WordPress database abstraction object.
237 *
238 * @param string $notify_moderator The value of the moderation_notify option OR if the comment is awaiting moderation.
239 * @param int $comment_id Comment ID.
240 * @return boolean Returns false to shortcircuit the execution of wp_notify_moderator
241 */
242 function jetpack_notify_moderator( $notify_moderator, $comment_id ) {
243 /*
244 * $notify_moderator is a tricky one. This filter is called in two places in Core. One is just to pass if a comment
245 * is being held for moderation. See https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/comment.php#L2296
246 *
247 * So we can't just assume that a true value here is what we need. The second time the filter is called, it checks
248 * the option -- which is what we expected here. See https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/pluggable.php#L1737
249 *
250 * It's possible another plugin would be filtering this value to true despite the option setting; however, since we're running at priority 1,
251 * they can still do that. They'll just get the Core flow instead of this one.
252 */
253
254 // If Jetpack is not active, or if Notify moderators options is not set, let the default flow go on.
255 if ( ! $notify_moderator || ! get_option( 'moderation_notify' ) || ! Jetpack::is_connection_ready() ) {
256 return $notify_moderator;
257 }
258
259 // Original function modified: Removed code before the notify_moderator filter.
260
261 global $wpdb;
262
263 $comment = get_comment( $comment_id );
264 if ( ! $comment ) {
265 return $notify_moderator;
266 }
267
268 $post = get_post( $comment->comment_post_ID );
269 $user = get_userdata( $post->post_author );
270 // Send to the administration and to the post author if the author can modify the comment.
271 $emails = array( get_option( 'admin_email' ) );
272 if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
273 if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
274 $emails[] = $user->user_email;
275 }
276 }
277
278 $switched_locale = switch_to_locale( get_locale() );
279
280 $comment_author_domain = '';
281 if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
282 $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
283 }
284 $comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
285
286 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
287 // we want to reverse this for the plain text arena of emails.
288 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
289 $comment_content = wp_specialchars_decode( $comment->comment_content );
290
291 switch ( $comment->comment_type ) {
292 case 'trackback':
293 /* translators: 1: Post title */
294 $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
295 $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
296 /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
297 $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
298 /* translators: 1: Trackback/pingback/comment author URL */
299 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
300 $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
301 break;
302 case 'pingback':
303 /* translators: 1: Post title */
304 $notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
305 $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
306 /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
307 $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
308 /* translators: 1: Trackback/pingback/comment author URL */
309 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
310 $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
311 break;
312 default: // Comments.
313 /* translators: 1: Post title */
314 $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
315 $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
316 /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */
317 $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
318 /* translators: 1: Comment author URL */
319 $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
320 /* translators: 1: Trackback/pingback/comment author URL */
321 $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
322 /* translators: 1: Comment text */
323 $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
324 break;
325 }
326
327 /** This filter is documented in core/src/wp-includes/pluggable.php */
328 $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
329
330 // Original function modified.
331 $moderate_on_wpcom = ! in_array( // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
332 false,
333 array_map( 'jetpack_notify_is_user_connected_by_email', $emails )
334 );
335
336 $base_wpcom_edit_comment_url = Redirect::get_url(
337 'calypso-edit-comment',
338 array(
339 'path' => $comment_id,
340 'query' => 'action=__action__', // __action__ will be replaced by the actual action.
341 )
342 );
343
344 // Original function modified: Consider $moderate_on_wpcom when building $notify_message.
345 $notify_message .= sprintf(
346 /* translators: Comment moderation. 1: Comment action URL */
347 __( 'Approve it: %s' ),
348 $moderate_on_wpcom
349 ? str_replace( '__action__', 'approve', $base_wpcom_edit_comment_url )
350 : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" )
351 ) . "\r\n";
352
353 if ( EMPTY_TRASH_DAYS ) {
354 $notify_message .= sprintf(
355 /* translators: Comment moderation. 1: Comment action URL */
356 __( 'Trash it: %s' ),
357 $moderate_on_wpcom
358 ? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url )
359 : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" )
360 ) . "\r\n";
361 } else {
362 $notify_message .= sprintf(
363 /* translators: Comment moderation. 1: Comment action URL */
364 __( 'Delete it: %s' ),
365 $moderate_on_wpcom
366 ? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url )
367 : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" )
368 ) . "\r\n";
369 }
370
371 $notify_message .= sprintf(
372 /* translators: Comment moderation. 1: Comment action URL */
373 __( 'Spam it: %s' ),
374 $moderate_on_wpcom
375 ? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url )
376 : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" )
377 ) . "\r\n";
378
379 $notify_message .= sprintf(
380 /* translators: Comment moderation. 1: Number of comments awaiting approval */
381 _n(
382 'Currently %s comment is waiting for approval. Please visit the moderation panel:',
383 'Currently %s comments are waiting for approval. Please visit the moderation panel:',
384 $comments_waiting
385 ),
386 number_format_i18n( $comments_waiting )
387 ) . "\r\n";
388
389 $notify_message .= $moderate_on_wpcom
390 ? Redirect::get_url( 'calypso-comments-pending' )
391 : admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n";
392
393 /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */
394 $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title );
395 $message_headers = '';
396
397 /** This filter is documented in core/src/wp-includes/pluggable.php */
398 $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
399
400 /** This filter is documented in core/src/wp-includes/pluggable.php */
401 $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
402
403 /** This filter is documented in core/src/wp-includes/pluggable.php */
404 $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
405
406 foreach ( $emails as $email ) {
407 wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
408 }
409
410 if ( $switched_locale ) {
411 restore_previous_locale();
412 }
413
414 return false;
415 }
416
417 /**
418 * Gets an user by email and verify if it's connected
419 *
420 * @param string $email The user email.
421 * @return boolean
422 */
423 function jetpack_notify_is_user_connected_by_email( $email ) {
424 $user = get_user_by( 'email', $email );
425 return ( new Connection_Manager( 'jetpack' ) )->is_user_connected( $user->ID );
426 }
427