admin-pages
1 year ago
core-api
1 year ago
debugger
1 year ago
markdown
1 year ago
class-jetpack-ai-helper.php
1 year ago
class-jetpack-currencies.php
2 years ago
class-jetpack-instagram-gallery-helper.php
2 years ago
class-jetpack-mapbox-helper.php
3 years ago
class-jetpack-podcast-feed-locator.php
1 year ago
class-jetpack-podcast-helper.php
1 year ago
class-jetpack-recommendations.php
2 years ago
class-jetpack-top-posts-helper.php
2 years ago
class.color.php
2 years ago
class.core-rest-api-endpoints.php
1 year ago
class.jetpack-automatic-install-skin.php
2 years ago
class.jetpack-iframe-embed.php
3 years ago
class.jetpack-password-checker.php
2 years ago
class.jetpack-search-performance-logger.php
4 years ago
class.media-extractor.php
2 years ago
class.media-summary.php
1 year ago
class.media.php
2 years ago
components.php
3 years ago
debugger.php
2 years ago
functions.wp-notify.php
1 year ago
icalendar-reader.php
1 year ago
jp-simplepie-alias-new.php
1 year ago
jp-simplepie-alias-old.php
1 year ago
jp-simplepie-alias.php
1 year ago
markdown.php
3 years ago
plans.php
4 years ago
plugins.php
4 years ago
tonesque.php
2 years ago
widgets.php
2 years ago
functions.wp-notify.php
432 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 | * @deprecated 13.9 File became unused. |
| 13 | */ |
| 14 | |
| 15 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 16 | use Automattic\Jetpack\Redirect; |
| 17 | |
| 18 | _deprecated_file( __FILE__, 'jetpack-13.9' ); |
| 19 | |
| 20 | // phpcs:disable WordPress.WP.I18n.MissingArgDomain --reason: Code copied from Core, so using Core strings. |
| 21 | // phpcs:disable WordPress.Utils.I18nTextDomainFixer.MissingArgDomain --reason: Code copied from Core, so using Core strings. |
| 22 | |
| 23 | /** |
| 24 | * Short circuits the {@see `wp_notify_postauthor`} function via the `comment_notification_recipients` filter. |
| 25 | * |
| 26 | * Notify an author (and/or others) of a comment/trackback/pingback on a post. |
| 27 | * |
| 28 | * @since 5.8.0 |
| 29 | * @since 9.3.0 Switched from pluggable function to filter callback |
| 30 | * |
| 31 | * @param array $emails List of recipients. |
| 32 | * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
| 33 | * @return array Empty array to shortcircuit wp_notify_postauthor execution. $emails if we want to disable the filter. |
| 34 | */ |
| 35 | function jetpack_notify_postauthor( $emails, $comment_id ) { |
| 36 | // Don't do anything if Jetpack isn't connected. |
| 37 | if ( ! Jetpack::is_connection_ready() || empty( $emails ) ) { |
| 38 | return $emails; |
| 39 | } |
| 40 | |
| 41 | // Original function modified: Code before the comment_notification_recipients filter removed. |
| 42 | |
| 43 | $comment = get_comment( $comment_id ); |
| 44 | if ( ! $comment ) { |
| 45 | return $emails; |
| 46 | } |
| 47 | |
| 48 | $post = get_post( $comment->comment_post_ID ); |
| 49 | $author = get_userdata( $post->post_author ); |
| 50 | |
| 51 | // Facilitate unsetting below without knowing the keys. |
| 52 | $emails = array_flip( $emails ); |
| 53 | |
| 54 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 55 | $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); |
| 56 | |
| 57 | // The comment was left by the author. |
| 58 | if ( $author && ! $notify_author && $comment->user_id === $post->post_author ) { |
| 59 | unset( $emails[ $author->user_email ] ); |
| 60 | } |
| 61 | |
| 62 | // The author moderated a comment on their own post. |
| 63 | if ( $author && ! $notify_author && get_current_user_id() === $post->post_author ) { |
| 64 | unset( $emails[ $author->user_email ] ); |
| 65 | } |
| 66 | |
| 67 | // The post author is no longer a member of the blog. |
| 68 | if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { |
| 69 | unset( $emails[ $author->user_email ] ); |
| 70 | } |
| 71 | |
| 72 | // If there's no email to send the comment to, bail, otherwise flip array back around for use below. |
| 73 | if ( array() === $emails ) { |
| 74 | return array(); // Original function modified. Return empty array instead of false. |
| 75 | } else { |
| 76 | $emails = array_flip( $emails ); |
| 77 | } |
| 78 | |
| 79 | $switched_locale = switch_to_locale( get_locale() ); |
| 80 | |
| 81 | $comment_author_domain = ''; |
| 82 | if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { |
| 83 | $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); |
| 84 | } |
| 85 | |
| 86 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
| 87 | // we want to reverse this for the plain text arena of emails. |
| 88 | $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
| 89 | $comment_content = wp_specialchars_decode( $comment->comment_content ); |
| 90 | |
| 91 | // Original function modified. |
| 92 | $moderate_on_wpcom = ! in_array( // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 93 | false, |
| 94 | array_map( 'jetpack_notify_is_user_connected_by_email', $emails ) |
| 95 | ); |
| 96 | |
| 97 | switch ( $comment->comment_type ) { |
| 98 | case 'trackback': |
| 99 | /* translators: 1: Post title */ |
| 100 | $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; |
| 101 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
| 102 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 103 | /* translators: %s: Site URL */ |
| 104 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 105 | /* translators: %s: Comment Content */ |
| 106 | $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
| 107 | $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; |
| 108 | /* translators: 1: blog name, 2: post title */ |
| 109 | $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title ); |
| 110 | break; |
| 111 | case 'pingback': |
| 112 | /* translators: 1: Post title */ |
| 113 | $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; |
| 114 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
| 115 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 116 | /* translators: %s: Site URL */ |
| 117 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 118 | /* translators: %s: Comment Content */ |
| 119 | $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
| 120 | $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; |
| 121 | /* translators: 1: blog name, 2: post title */ |
| 122 | $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title ); |
| 123 | break; |
| 124 | default: // Comments. |
| 125 | /* translators: 1: Post title */ |
| 126 | $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; |
| 127 | /* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */ |
| 128 | $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 129 | /* translators: %s: Email address */ |
| 130 | $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; |
| 131 | /* translators: %s: Site URL */ |
| 132 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 133 | /* translators: %s: Comment Content */ |
| 134 | $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
| 135 | $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; |
| 136 | /* translators: 1: blog name, 2: post title */ |
| 137 | $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title ); |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | // Original function modified: Consider $moderate_on_wpcom when building $notify_message. |
| 142 | $notify_message .= $moderate_on_wpcom |
| 143 | ? Redirect::get_url( |
| 144 | 'calypso-comments-all', |
| 145 | array( |
| 146 | 'path' => $comment->comment_post_ID, |
| 147 | ) |
| 148 | ) . "/\r\n\r\n" |
| 149 | : get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n"; |
| 150 | |
| 151 | /* translators: %s: URL */ |
| 152 | $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; |
| 153 | |
| 154 | $base_wpcom_edit_comment_url = Redirect::get_url( |
| 155 | 'calypso-edit-comment', |
| 156 | array( |
| 157 | 'path' => $comment_id, |
| 158 | 'query' => 'action=__action__', // __action__ will be replaced by the actual action. |
| 159 | ) |
| 160 | ); |
| 161 | |
| 162 | // Original function modified: Consider $moderate_on_wpcom when building $notify_message. |
| 163 | if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { |
| 164 | if ( EMPTY_TRASH_DAYS ) { |
| 165 | $notify_message .= sprintf( |
| 166 | /* translators: Placeholder is the edit URL */ |
| 167 | __( 'Trash it: %s' ), |
| 168 | $moderate_on_wpcom |
| 169 | ? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url ) |
| 170 | : admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) |
| 171 | ) . "\r\n"; |
| 172 | } else { |
| 173 | $notify_message .= sprintf( |
| 174 | /* translators: Placeholder is the edit URL */ |
| 175 | __( 'Delete it: %s' ), |
| 176 | $moderate_on_wpcom |
| 177 | ? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url ) |
| 178 | : admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) |
| 179 | ) . "\r\n"; |
| 180 | } |
| 181 | $notify_message .= sprintf( |
| 182 | /* translators: Placeholder is the edit URL */ |
| 183 | __( 'Spam it: %s' ), |
| 184 | $moderate_on_wpcom |
| 185 | ? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url ) |
| 186 | : admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) |
| 187 | ) . "\r\n"; |
| 188 | } |
| 189 | |
| 190 | $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( isset( $_SERVER['SERVER_NAME'] ) ? filter_var( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '' ) ); |
| 191 | |
| 192 | if ( '' === $comment->comment_author ) { |
| 193 | $from = "From: \"$blogname\" <$wp_email>"; |
| 194 | if ( '' !== $comment->comment_author_email ) { |
| 195 | $reply_to = "Reply-To: $comment->comment_author_email"; |
| 196 | } |
| 197 | } else { |
| 198 | $from = "From: \"$comment->comment_author\" <$wp_email>"; |
| 199 | if ( '' !== $comment->comment_author_email ) { |
| 200 | $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | $message_headers = "$from\n" |
| 205 | . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
| 206 | |
| 207 | if ( isset( $reply_to ) ) { |
| 208 | $message_headers .= $reply_to . "\n"; |
| 209 | } |
| 210 | |
| 211 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 212 | $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); |
| 213 | |
| 214 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 215 | $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); |
| 216 | |
| 217 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 218 | $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); |
| 219 | |
| 220 | foreach ( $emails as $email ) { |
| 221 | wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
| 222 | } |
| 223 | |
| 224 | if ( $switched_locale ) { |
| 225 | restore_previous_locale(); |
| 226 | } |
| 227 | |
| 228 | return array(); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Short circuits the {@see `wp_notify_moderator`} function via the `notify_moderator` filter. |
| 233 | * |
| 234 | * Notifies the moderator of the site about a new comment that is awaiting approval. |
| 235 | * |
| 236 | * @since 5.8.0 |
| 237 | * @since 9.2.0 Switched from pluggable function to filter callback |
| 238 | * @since 9.5.0 Updated the passing condition to call get_option( 'moderation_notify' ); directly. |
| 239 | * |
| 240 | * @global wpdb $wpdb WordPress database abstraction object. |
| 241 | * |
| 242 | * @param string $notify_moderator The value of the moderation_notify option OR if the comment is awaiting moderation. |
| 243 | * @param int $comment_id Comment ID. |
| 244 | * @return boolean Returns false to shortcircuit the execution of wp_notify_moderator |
| 245 | */ |
| 246 | function jetpack_notify_moderator( $notify_moderator, $comment_id ) { |
| 247 | /* |
| 248 | * $notify_moderator is a tricky one. This filter is called in two places in Core. One is just to pass if a comment |
| 249 | * is being held for moderation. See https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/comment.php#L2296 |
| 250 | * |
| 251 | * So we can't just assume that a true value here is what we need. The second time the filter is called, it checks |
| 252 | * the option -- which is what we expected here. See https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/pluggable.php#L1737 |
| 253 | * |
| 254 | * It's possible another plugin would be filtering this value to true despite the option setting; however, since we're running at priority 1, |
| 255 | * they can still do that. They'll just get the Core flow instead of this one. |
| 256 | */ |
| 257 | |
| 258 | // If Jetpack is not active, or if Notify moderators options is not set, let the default flow go on. |
| 259 | if ( ! $notify_moderator || ! get_option( 'moderation_notify' ) || ! Jetpack::is_connection_ready() ) { |
| 260 | return $notify_moderator; |
| 261 | } |
| 262 | |
| 263 | // Original function modified: Removed code before the notify_moderator filter. |
| 264 | |
| 265 | global $wpdb; |
| 266 | |
| 267 | $comment = get_comment( $comment_id ); |
| 268 | if ( ! $comment ) { |
| 269 | return $notify_moderator; |
| 270 | } |
| 271 | |
| 272 | $post = get_post( $comment->comment_post_ID ); |
| 273 | $user = get_userdata( $post->post_author ); |
| 274 | // Send to the administration and to the post author if the author can modify the comment. |
| 275 | $emails = array( get_option( 'admin_email' ) ); |
| 276 | if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { |
| 277 | if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
| 278 | $emails[] = $user->user_email; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | $switched_locale = switch_to_locale( get_locale() ); |
| 283 | |
| 284 | $comment_author_domain = ''; |
| 285 | if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { |
| 286 | $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); |
| 287 | } |
| 288 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching |
| 289 | $comments_waiting = (int) $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" ); |
| 290 | |
| 291 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
| 292 | // we want to reverse this for the plain text arena of emails. |
| 293 | $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
| 294 | $comment_content = wp_specialchars_decode( $comment->comment_content ); |
| 295 | |
| 296 | switch ( $comment->comment_type ) { |
| 297 | case 'trackback': |
| 298 | /* translators: 1: Post title */ |
| 299 | $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
| 300 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
| 301 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
| 302 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 303 | /* translators: 1: Trackback/pingback/comment author URL */ |
| 304 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 305 | $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
| 306 | break; |
| 307 | case 'pingback': |
| 308 | /* translators: 1: Post title */ |
| 309 | $notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
| 310 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
| 311 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
| 312 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 313 | /* translators: 1: Trackback/pingback/comment author URL */ |
| 314 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 315 | $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
| 316 | break; |
| 317 | default: // Comments. |
| 318 | /* translators: 1: Post title */ |
| 319 | $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
| 320 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
| 321 | /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */ |
| 322 | $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
| 323 | /* translators: 1: Comment author URL */ |
| 324 | $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; |
| 325 | /* translators: 1: Trackback/pingback/comment author URL */ |
| 326 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
| 327 | /* translators: 1: Comment text */ |
| 328 | $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 333 | $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); |
| 334 | |
| 335 | // Original function modified. |
| 336 | $moderate_on_wpcom = ! in_array( // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 337 | false, |
| 338 | array_map( 'jetpack_notify_is_user_connected_by_email', $emails ) |
| 339 | ); |
| 340 | |
| 341 | $base_wpcom_edit_comment_url = Redirect::get_url( |
| 342 | 'calypso-edit-comment', |
| 343 | array( |
| 344 | 'path' => $comment_id, |
| 345 | 'query' => 'action=__action__', // __action__ will be replaced by the actual action. |
| 346 | ) |
| 347 | ); |
| 348 | |
| 349 | // Original function modified: Consider $moderate_on_wpcom when building $notify_message. |
| 350 | $notify_message .= sprintf( |
| 351 | /* translators: Comment moderation. 1: Comment action URL */ |
| 352 | __( 'Approve it: %s' ), |
| 353 | $moderate_on_wpcom |
| 354 | ? str_replace( '__action__', 'approve', $base_wpcom_edit_comment_url ) |
| 355 | : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) |
| 356 | ) . "\r\n"; |
| 357 | |
| 358 | if ( EMPTY_TRASH_DAYS ) { |
| 359 | $notify_message .= sprintf( |
| 360 | /* translators: Comment moderation. 1: Comment action URL */ |
| 361 | __( 'Trash it: %s' ), |
| 362 | $moderate_on_wpcom |
| 363 | ? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url ) |
| 364 | : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) |
| 365 | ) . "\r\n"; |
| 366 | } else { |
| 367 | $notify_message .= sprintf( |
| 368 | /* translators: Comment moderation. 1: Comment action URL */ |
| 369 | __( 'Delete it: %s' ), |
| 370 | $moderate_on_wpcom |
| 371 | ? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url ) |
| 372 | : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) |
| 373 | ) . "\r\n"; |
| 374 | } |
| 375 | |
| 376 | $notify_message .= sprintf( |
| 377 | /* translators: Comment moderation. 1: Comment action URL */ |
| 378 | __( 'Spam it: %s' ), |
| 379 | $moderate_on_wpcom |
| 380 | ? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url ) |
| 381 | : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) |
| 382 | ) . "\r\n"; |
| 383 | |
| 384 | $notify_message .= sprintf( |
| 385 | /* translators: Comment moderation. 1: Number of comments awaiting approval */ |
| 386 | _n( |
| 387 | 'Currently %s comment is waiting for approval. Please visit the moderation panel:', |
| 388 | 'Currently %s comments are waiting for approval. Please visit the moderation panel:', |
| 389 | $comments_waiting |
| 390 | ), |
| 391 | number_format_i18n( $comments_waiting ) |
| 392 | ) . "\r\n"; |
| 393 | |
| 394 | $notify_message .= $moderate_on_wpcom |
| 395 | ? Redirect::get_url( 'calypso-comments-pending' ) |
| 396 | : admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; |
| 397 | |
| 398 | /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ |
| 399 | $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); |
| 400 | $message_headers = ''; |
| 401 | |
| 402 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 403 | $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); |
| 404 | |
| 405 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 406 | $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); |
| 407 | |
| 408 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
| 409 | $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); |
| 410 | |
| 411 | foreach ( $emails as $email ) { |
| 412 | wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
| 413 | } |
| 414 | |
| 415 | if ( $switched_locale ) { |
| 416 | restore_previous_locale(); |
| 417 | } |
| 418 | |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Gets an user by email and verify if it's connected |
| 424 | * |
| 425 | * @param string $email The user email. |
| 426 | * @return boolean |
| 427 | */ |
| 428 | function jetpack_notify_is_user_connected_by_email( $email ) { |
| 429 | $user = get_user_by( 'email', $email ); |
| 430 | return ( new Connection_Manager( 'jetpack' ) )->is_user_connected( $user->ID ); |
| 431 | } |
| 432 |