From 587fe25ec1664d35c754c19ef650f8a55fb43293 Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Fri, 10 Nov 2017 12:53:38 -0300 Subject: [PATCH 1/7] Comments: adds overrides to the moderation emails to point moderation links to WordPress.com --- jetpack.php | 1 + moderation-emails-override.php | 372 +++++++++++++++++++++++++++++++++ 2 files changed, 373 insertions(+) create mode 100644 moderation-emails-override.php diff --git a/jetpack.php b/jetpack.php index 5201da6fd55ae..0d9d0154e1e3d 100644 --- a/jetpack.php +++ b/jetpack.php @@ -67,6 +67,7 @@ function jetpack_require_lib_dir() { require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-constants.php'); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-idc.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-connection-banner.php' ); +require_once( JETPACK__PLUGIN_DIR . 'moderation-emails-override.php' ); if ( is_admin() ) { require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' ); diff --git a/moderation-emails-override.php b/moderation-emails-override.php new file mode 100644 index 0000000000000..5fcd6fc60d930 --- /dev/null +++ b/moderation-emails-override.php @@ -0,0 +1,372 @@ +comment_post_ID ) ) + return false; + + $post = get_post( $comment->comment_post_ID ); + $author = get_userdata( $post->post_author ); + + // Who to notify? By default, just the post author, but others can be added. + $emails = array(); + if ( $author ) { + $emails[] = $author->user_email; + } + + /** + * Filters the list of email addresses to receive a comment notification. + * + * By default, only post authors are notified of comments. This filter allows + * others to be added. + * + * @since 3.7.0 + * + * @param array $emails An array of email addresses to receive a comment notification. + * @param int $comment_id The comment ID. + */ + $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); + $emails = array_filter( $emails ); + + // If there are no addresses to send the comment to, bail. + if ( ! count( $emails ) ) { + return false; + } + + // Facilitate unsetting below without knowing the keys. + $emails = array_flip( $emails ); + + /** + * Filters whether to notify comment authors of their comments on their own posts. + * + * By default, comment authors aren't notified of their comments on their own + * posts. This filter allows you to override that. + * + * @since 3.8.0 + * + * @param bool $notify Whether to notify the post author of their own comment. + * Default false. + * @param int $comment_id The comment ID. + */ + $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); + + // The comment was left by the author + if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { + unset( $emails[ $author->user_email ] ); + } + + // The author moderated a comment on their own post + if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { + unset( $emails[ $author->user_email ] ); + } + + // The post author is no longer a member of the blog + if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { + unset( $emails[ $author->user_email ] ); + } + + // If there's no email to send the comment to, bail, otherwise flip array back around for use below + if ( ! count( $emails ) ) { + return false; + } else { + $emails = array_flip( $emails ); + } + + $switched_locale = switch_to_locale( get_locale() ); + + $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); + + // The blogname option is escaped with esc_html on the way into the database in sanitize_option + // we want to reverse this for the plain text arena of emails. + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); + $comment_content = wp_specialchars_decode( $comment->comment_content ); + + switch ( $comment->comment_type ) { + case 'trackback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __('Website: %1$s (IP address: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); + break; + case 'pingback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __('Website: %1$s (IP address: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); + break; + default: // Comments + $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */ + $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __('Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); + break; + } + $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; + $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment ) ) . "\r\n"; + + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + $site_id = Jetpack_Options::get_option( 'id' ); + + if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { + if ( EMPTY_TRASH_DAYS ) { + $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + } else { + $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + } + $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + } + + $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); + + if ( '' == $comment->comment_author ) { + $from = "From: \"$blogname\" <$wp_email>"; + if ( '' != $comment->comment_author_email ) + $reply_to = "Reply-To: $comment->comment_author_email"; + } else { + $from = "From: \"$comment->comment_author\" <$wp_email>"; + if ( '' != $comment->comment_author_email ) + $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; + } + + $message_headers = "$from\n" + . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; + + if ( isset($reply_to) ) + $message_headers .= $reply_to . "\n"; + + /** + * Filters the comment notification email text. + * + * @since 1.5.2 + * + * @param string $notify_message The comment notification email text. + * @param int $comment_id Comment ID. + */ + $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); + + /** + * Filters the comment notification email subject. + * + * @since 1.5.2 + * + * @param string $subject The comment notification email subject. + * @param int $comment_id Comment ID. + */ + $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); + + /** + * Filters the comment notification email headers. + * + * @since 1.5.2 + * + * @param string $message_headers Headers for the comment notification email. + * @param int $comment_id Comment ID. + */ + $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); + + foreach ( $emails as $email ) { + @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); + } + + if ( $switched_locale ) { + restore_previous_locale(); + } + + return true; +} +endif; + +if ( ! function_exists('wp_notify_moderator') ) : +/** + * Notifies the moderator of the site about a new comment that is awaiting approval. + * + * @since 1.0.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator + * should be notified, overriding the site setting. + * + * @param int $comment_id Comment ID. + * @return true Always returns true. + */ +function wp_notify_moderator($comment_id) { + global $wpdb; + + $maybe_notify = get_option( 'moderation_notify' ); + + /** + * Filters whether to send the site moderator email notifications, overriding the site setting. + * + * @since 4.4.0 + * + * @param bool $maybe_notify Whether to notify blog moderator. + * @param int $comment_ID The id of the comment for the notification. + */ + $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); + + if ( ! $maybe_notify ) { + return true; + } + + $comment = get_comment($comment_id); + $post = get_post($comment->comment_post_ID); + $user = get_userdata( $post->post_author ); + // Send to the administration and to the post author if the author can modify the comment. + $emails = array( get_option( 'admin_email' ) ); + if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { + if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) + $emails[] = $user->user_email; + } + + $switched_locale = switch_to_locale( get_locale() ); + + $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); + $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); + + // The blogname option is escaped with esc_html on the way into the database in sanitize_option + // we want to reverse this for the plain text arena of emails. + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); + $comment_content = wp_specialchars_decode( $comment->comment_content ); + + switch ( $comment->comment_type ) { + case 'trackback': + /* translators: 1: Post title */ + $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; + break; + case 'pingback': + /* translators: 1: Post title */ + $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; + break; + default: // Comments + /* translators: 1: Post title */ + $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; + /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */ + $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Comment author URL */ + $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + /* translators: 1: Comment text */ + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + break; + } + + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + $site_id = Jetpack_Options::get_option( 'id' ); + + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( __( 'Approve it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + if ( EMPTY_TRASH_DAYS ) { + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + } else { + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + } + + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + + /* translators: Comment moderation. 1: Number of comments awaiting approval */ + $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', + 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; + $notify_message .= admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ) . "\r\n"; + + /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ + $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); + $message_headers = ''; + + /** + * Filters the list of recipients for comment moderation emails. + * + * @since 3.7.0 + * + * @param array $emails List of email addresses to notify for comment moderation. + * @param int $comment_id Comment ID. + */ + $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); + + /** + * Filters the comment moderation email text. + * + * @since 1.5.2 + * + * @param string $notify_message Text of the comment moderation email. + * @param int $comment_id Comment ID. + */ + $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); + + /** + * Filters the comment moderation email subject. + * + * @since 1.5.2 + * + * @param string $subject Subject of the comment moderation email. + * @param int $comment_id Comment ID. + */ + $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); + + /** + * Filters the comment moderation email headers. + * + * @since 2.8.0 + * + * @param string $message_headers Headers for the comment moderation email. + * @param int $comment_id Comment ID. + */ + $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); + + foreach ( $emails as $email ) { + @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); + } + + if ( $switched_locale ) { + restore_previous_locale(); + } + + return true; +} +endif; From 66bc99e2b5abd8d56cc9c1f144c1e4a7f11f9e23 Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Mon, 13 Nov 2017 23:45:29 -0300 Subject: [PATCH 2/7] Comments: adds check for active and connected Jetpack --- moderation-emails-override.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/moderation-emails-override.php b/moderation-emails-override.php index 5fcd6fc60d930..b0780f0ffe871 100644 --- a/moderation-emails-override.php +++ b/moderation-emails-override.php @@ -1,6 +1,6 @@ post_author, 'edit_comment', $comment->comment_ID ) ) { if ( EMPTY_TRASH_DAYS ) { - $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" ) . "\r\n"; } else { - $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" ) . "\r\n"; } - $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" ) . "\r\n"; } $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); @@ -205,7 +204,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { } endif; -if ( ! function_exists('wp_notify_moderator') ) : +if ( ! function_exists('wp_notify_moderator') && Jetpack::is_active() ) : /** * Notifies the moderator of the site about a new comment that is awaiting approval. * @@ -295,20 +294,19 @@ function wp_notify_moderator($comment_id) { } $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); - $site_id = Jetpack_Options::get_option( 'id' ); /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Approve it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Approve it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" ) . "\r\n"; if ( EMPTY_TRASH_DAYS ) { /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" ) . "\r\n"; } else { /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" ) . "\r\n"; } /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam&site_id={$site_id}&post_id={$post->ID}" ) . "\r\n"; + $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" ) . "\r\n"; /* translators: Comment moderation. 1: Number of comments awaiting approval */ $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', From e09540fa97c39775859881cedab943169eda063b Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Tue, 14 Nov 2017 13:33:39 -0300 Subject: [PATCH 3/7] Comments: overrides emails only when Jetpack is active and connected, and if all emails have WordPress.com accounts --- moderation-emails-override.php | 158 ++++++++++++--------------------- 1 file changed, 58 insertions(+), 100 deletions(-) diff --git a/moderation-emails-override.php b/moderation-emails-override.php index b0780f0ffe871..e28a9b1018191 100644 --- a/moderation-emails-override.php +++ b/moderation-emails-override.php @@ -28,17 +28,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { $emails[] = $author->user_email; } - /** - * Filters the list of email addresses to receive a comment notification. - * - * By default, only post authors are notified of comments. This filter allows - * others to be added. - * - * @since 3.7.0 - * - * @param array $emails An array of email addresses to receive a comment notification. - * @param int $comment_id The comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); $emails = array_filter( $emails ); @@ -50,18 +40,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { // Facilitate unsetting below without knowing the keys. $emails = array_flip( $emails ); - /** - * Filters whether to notify comment authors of their comments on their own posts. - * - * By default, comment authors aren't notified of their comments on their own - * posts. This filter allows you to override that. - * - * @since 3.8.0 - * - * @param bool $notify Whether to notify the post author of their own comment. - * Default false. - * @param int $comment_id The comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); // The comment was left by the author @@ -95,6 +74,14 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $comment_content = wp_specialchars_decode( $comment->comment_content ); + function is_user_connected( $email ) { + $user = get_user_by( 'email', $email ); + return Jetpack::is_user_connected( $user->ID ); + } + $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); + + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + switch ( $comment->comment_type ) { case 'trackback': /* translators: 1: Post title */ @@ -130,18 +117,26 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); break; } - $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; - $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment ) ) . "\r\n"; - $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + $notify_message .= $moderate_on_wpcom + ? "https://wordpress.com/comments/all/{$primary_site_slug}/{$comment->comment_post_ID}/\r\n\r\n" + : get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; + + $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment ) ) . "\r\n"; if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { if ( EMPTY_TRASH_DAYS ) { - $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" ) . "\r\n"; + $notify_message .= sprintf( __( 'Trash it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" + : admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } else { - $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" ) . "\r\n"; + $notify_message .= sprintf( __( 'Delete it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" + : admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } - $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" ) . "\r\n"; + $notify_message .= sprintf( __( 'Spam it: %s' ), $moderate_on_wpcom ? + "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" + : admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); @@ -162,34 +157,13 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { if ( isset($reply_to) ) $message_headers .= $reply_to . "\n"; - /** - * Filters the comment notification email text. - * - * @since 1.5.2 - * - * @param string $notify_message The comment notification email text. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); - /** - * Filters the comment notification email subject. - * - * @since 1.5.2 - * - * @param string $subject The comment notification email subject. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); - /** - * Filters the comment notification email headers. - * - * @since 1.5.2 - * - * @param string $message_headers Headers for the comment notification email. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); foreach ( $emails as $email ) { @@ -223,14 +197,7 @@ function wp_notify_moderator($comment_id) { $maybe_notify = get_option( 'moderation_notify' ); - /** - * Filters whether to send the site moderator email notifications, overriding the site setting. - * - * @since 4.4.0 - * - * @param bool $maybe_notify Whether to notify blog moderator. - * @param int $comment_ID The id of the comment for the notification. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); if ( ! $maybe_notify ) { @@ -293,68 +260,59 @@ function wp_notify_moderator($comment_id) { break; } + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); + + function is_user_connected( $email ) { + $user = get_user_by( 'email', $email ); + return Jetpack::is_user_connected( $user->ID ); + } + + $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Approve it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" ) . "\r\n"; + $notify_message .= sprintf( __( 'Approve it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" + : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ). "\r\n"; + if ( EMPTY_TRASH_DAYS ) { /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Trash it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" ) . "\r\n"; + $notify_message .= sprintf( __( 'Trash it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" + : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n"; } else { /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Delete it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" ) . "\r\n"; + $notify_message .= sprintf( __( 'Delete it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" + : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n"; } /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Spam it: %s' ), "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" ) . "\r\n"; + $notify_message .= sprintf( __( 'Spam it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" + : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n"; /* translators: Comment moderation. 1: Number of comments awaiting approval */ $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; - $notify_message .= admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ) . "\r\n"; + + $notify_message .= $moderate_on_wpcom + ? "https://wordpress.com/comments/pending/{$primary_site_slug}/" + : admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ) . "\r\n"; /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); $message_headers = ''; - /** - * Filters the list of recipients for comment moderation emails. - * - * @since 3.7.0 - * - * @param array $emails List of email addresses to notify for comment moderation. - * @param int $comment_id Comment ID. - */ - $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); - - /** - * Filters the comment moderation email text. - * - * @since 1.5.2 - * - * @param string $notify_message Text of the comment moderation email. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); - /** - * Filters the comment moderation email subject. - * - * @since 1.5.2 - * - * @param string $subject Subject of the comment moderation email. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); - /** - * Filters the comment moderation email headers. - * - * @since 2.8.0 - * - * @param string $message_headers Headers for the comment moderation email. - * @param int $comment_id Comment ID. - */ + /** This filter is documented in core/src/wp-includes/pluggable.php */ $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { From 0c5494a277848154aa708f60f07911c6c1df4b5d Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Thu, 7 Dec 2017 16:45:22 -0300 Subject: [PATCH 4/7] Comments: override pluggable notifications functions when edit_links_calypso_redirect option is set --- class.jetpack.php | 4 ++++ jetpack.php | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/class.jetpack.php b/class.jetpack.php index 375f1c8178a35..32edc202f1a3c 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -642,6 +642,10 @@ private function __construct() { if ( Jetpack::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); + + //we'll override wp_notify_postauthor and wp_notify_moderator pluggable functions + //so they point moderation links on emails to Calypso + require_once( JETPACK__PLUGIN_DIR . 'moderation-emails-override.php' ); } // Update the Jetpack plan from API on heartbeats diff --git a/jetpack.php b/jetpack.php index 0d9d0154e1e3d..5201da6fd55ae 100644 --- a/jetpack.php +++ b/jetpack.php @@ -67,7 +67,6 @@ function jetpack_require_lib_dir() { require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-constants.php'); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-idc.php' ); require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-connection-banner.php' ); -require_once( JETPACK__PLUGIN_DIR . 'moderation-emails-override.php' ); if ( is_admin() ) { require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' ); From f0fd596a97669795df97a54417ab1f067de2a03f Mon Sep 17 00:00:00 2001 From: Rodrigo Iloro Date: Wed, 27 Dec 2017 01:49:00 +0000 Subject: [PATCH 5/7] Comments: phpcs/phpbfs style checks on moderation email overrides file --- moderation-emails-override.php | 529 +++++++++++++++++---------------- 1 file changed, 276 insertions(+), 253 deletions(-) diff --git a/moderation-emails-override.php b/moderation-emails-override.php index e28a9b1018191..b3cf04bf651ba 100644 --- a/moderation-emails-override.php +++ b/moderation-emails-override.php @@ -1,7 +1,7 @@ comment_post_ID ) ) - return false; + $comment = get_comment( $comment_id ); + if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) { + return false; + } - $post = get_post( $comment->comment_post_ID ); - $author = get_userdata( $post->post_author ); + $post = get_post( $comment->comment_post_ID ); + $author = get_userdata( $post->post_author ); - // Who to notify? By default, just the post author, but others can be added. - $emails = array(); - if ( $author ) { - $emails[] = $author->user_email; - } + // Who to notify? By default, just the post author, but others can be added. + $emails = array(); + if ( $author ) { + $emails[] = $author->user_email; + } - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); - $emails = array_filter( $emails ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); + $emails = array_filter( $emails ); - // If there are no addresses to send the comment to, bail. - if ( ! count( $emails ) ) { - return false; - } + // If there are no addresses to send the comment to, bail. + if ( ! count( $emails ) ) { + return false; + } - // Facilitate unsetting below without knowing the keys. - $emails = array_flip( $emails ); + // Facilitate unsetting below without knowing the keys. + $emails = array_flip( $emails ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); - // The comment was left by the author - if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { - unset( $emails[ $author->user_email ] ); - } + // The comment was left by the author + if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { + unset( $emails[ $author->user_email ] ); + } - // The author moderated a comment on their own post - if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { - unset( $emails[ $author->user_email ] ); - } + // The author moderated a comment on their own post + if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { + unset( $emails[ $author->user_email ] ); + } - // The post author is no longer a member of the blog - if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { - unset( $emails[ $author->user_email ] ); - } + // The post author is no longer a member of the blog + if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { + unset( $emails[ $author->user_email ] ); + } - // If there's no email to send the comment to, bail, otherwise flip array back around for use below - if ( ! count( $emails ) ) { - return false; - } else { - $emails = array_flip( $emails ); - } + // If there's no email to send the comment to, bail, otherwise flip array back around for use below + if ( ! count( $emails ) ) { + return false; + } else { + $emails = array_flip( $emails ); + } - $switched_locale = switch_to_locale( get_locale() ); + $switched_locale = switch_to_locale( get_locale() ); - $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); + $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); - // The blogname option is escaped with esc_html on the way into the database in sanitize_option - // we want to reverse this for the plain text arena of emails. - $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); - $comment_content = wp_specialchars_decode( $comment->comment_content ); + // The blogname option is escaped with esc_html on the way into the database in sanitize_option + // we want to reverse this for the plain text arena of emails. + $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); + $comment_content = wp_specialchars_decode( $comment->comment_content ); - function is_user_connected( $email ) { - $user = get_user_by( 'email', $email ); - return Jetpack::is_user_connected( $user->ID ); - } - $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); - - $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); - - switch ( $comment->comment_type ) { - case 'trackback': - /* translators: 1: Post title */ - $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; - /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ - $notify_message .= sprintf( __('Website: %1$s (IP address: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; - $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; - /* translators: 1: blog name, 2: post title */ - $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); - break; - case 'pingback': - /* translators: 1: Post title */ - $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; - /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ - $notify_message .= sprintf( __('Website: %1$s (IP address: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; - $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; - /* translators: 1: blog name, 2: post title */ - $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); - break; - default: // Comments - $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; - /* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */ - $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - $notify_message .= sprintf( __('Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; - $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; - /* translators: 1: blog name, 2: post title */ - $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); - break; - } + function is_user_connected( $email ) { + $user = get_user_by( 'email', $email ); + return Jetpack::is_user_connected( $user->ID ); + } + $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); + + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + + switch ( $comment->comment_type ) { + case 'trackback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title ); + break; + case 'pingback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title ); + break; + default: // Comments + $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; + /* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */ + $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; + /* translators: 1: blog name, 2: post title */ + $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title ); + break; + } - $notify_message .= $moderate_on_wpcom - ? "https://wordpress.com/comments/all/{$primary_site_slug}/{$comment->comment_post_ID}/\r\n\r\n" - : get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; + $notify_message .= $moderate_on_wpcom + ? "https://wordpress.com/comments/all/{$primary_site_slug}/{$comment->comment_post_ID}/\r\n\r\n" + : get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n"; + + $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; + + if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { + if ( EMPTY_TRASH_DAYS ) { + $notify_message .= sprintf( + __( 'Trash it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" + : admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) + ) . "\r\n"; + } else { + $notify_message .= sprintf( + __( 'Delete it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" + : admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) + ) . "\r\n"; + } + $notify_message .= sprintf( + __( 'Spam it: %s' ), $moderate_on_wpcom ? + "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" + : admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) + ) . "\r\n"; + } - $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment ) ) . "\r\n"; + $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) ); - if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { - if ( EMPTY_TRASH_DAYS ) { - $notify_message .= sprintf( __( 'Trash it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" - : admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; + if ( '' == $comment->comment_author ) { + $from = "From: \"$blogname\" <$wp_email>"; + if ( '' != $comment->comment_author_email ) { + $reply_to = "Reply-To: $comment->comment_author_email"; + } } else { - $notify_message .= sprintf( __( 'Delete it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" - : admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; + $from = "From: \"$comment->comment_author\" <$wp_email>"; + if ( '' != $comment->comment_author_email ) { + $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; + } } - $notify_message .= sprintf( __( 'Spam it: %s' ), $moderate_on_wpcom ? - "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" - : admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; - } - - $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); - if ( '' == $comment->comment_author ) { - $from = "From: \"$blogname\" <$wp_email>"; - if ( '' != $comment->comment_author_email ) - $reply_to = "Reply-To: $comment->comment_author_email"; - } else { - $from = "From: \"$comment->comment_author\" <$wp_email>"; - if ( '' != $comment->comment_author_email ) - $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; - } + $message_headers = "$from\n" + . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; - $message_headers = "$from\n" - . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; + if ( isset( $reply_to ) ) { + $message_headers .= $reply_to . "\n"; + } - if ( isset($reply_to) ) - $message_headers .= $reply_to . "\n"; + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); + foreach ( $emails as $email ) { + @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); + } - foreach ( $emails as $email ) { - @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); - } + if ( $switched_locale ) { + restore_previous_locale(); + } - if ( $switched_locale ) { - restore_previous_locale(); + return true; } - - return true; -} endif; -if ( ! function_exists('wp_notify_moderator') && Jetpack::is_active() ) : -/** +if ( ! function_exists( 'wp_notify_moderator' ) && Jetpack::is_active() ) : + /** * Notifies the moderator of the site about a new comment that is awaiting approval. * * @since 1.0.0 @@ -192,137 +202,150 @@ function is_user_connected( $email ) { * @param int $comment_id Comment ID. * @return true Always returns true. */ -function wp_notify_moderator($comment_id) { - global $wpdb; - - $maybe_notify = get_option( 'moderation_notify' ); + function wp_notify_moderator( $comment_id ) { + global $wpdb; - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); + $maybe_notify = get_option( 'moderation_notify' ); - if ( ! $maybe_notify ) { - return true; - } + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); - $comment = get_comment($comment_id); - $post = get_post($comment->comment_post_ID); - $user = get_userdata( $post->post_author ); - // Send to the administration and to the post author if the author can modify the comment. - $emails = array( get_option( 'admin_email' ) ); - if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { - if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) - $emails[] = $user->user_email; - } + if ( ! $maybe_notify ) { + return true; + } - $switched_locale = switch_to_locale( get_locale() ); - - $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); - $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); - - // The blogname option is escaped with esc_html on the way into the database in sanitize_option - // we want to reverse this for the plain text arena of emails. - $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); - $comment_content = wp_specialchars_decode( $comment->comment_content ); - - switch ( $comment->comment_type ) { - case 'trackback': - /* translators: 1: Post title */ - $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; - /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ - $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - /* translators: 1: Trackback/pingback/comment author URL */ - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; - break; - case 'pingback': - /* translators: 1: Post title */ - $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; - /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ - $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - /* translators: 1: Trackback/pingback/comment author URL */ - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment_content . "\r\n\r\n"; - break; - default: // Comments - /* translators: 1: Post title */ - $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; - /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */ - $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; - /* translators: 1: Comment author URL */ - $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; - /* translators: 1: Trackback/pingback/comment author URL */ - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; - /* translators: 1: Comment text */ - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; - break; - } + $comment = get_comment( $comment_id ); + $post = get_post( $comment->comment_post_ID ); + $user = get_userdata( $post->post_author ); + // Send to the administration and to the post author if the author can modify the comment. + $emails = array( get_option( 'admin_email' ) ); + if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { + if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { + $emails[] = $user->user_email; + } + } - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); + $switched_locale = switch_to_locale( get_locale() ); + + $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); + $comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" ); + + // The blogname option is escaped with esc_html on the way into the database in sanitize_option + // we want to reverse this for the plain text arena of emails. + $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); + $comment_content = wp_specialchars_decode( $comment->comment_content ); + + switch ( $comment->comment_type ) { + case 'trackback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; + break; + case 'pingback': + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; + /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ + $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; + break; + default: // Comments + /* translators: 1: Post title */ + $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; + $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; + /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */ + $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; + /* translators: 1: Comment author URL */ + $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; + /* translators: 1: Trackback/pingback/comment author URL */ + $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; + /* translators: 1: Comment text */ + $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; + break; + } - function is_user_connected( $email ) { - $user = get_user_by( 'email', $email ); - return Jetpack::is_user_connected( $user->ID ); - } + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); - $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); + function is_user_connected( $email ) { + $user = get_user_by( 'email', $email ); + return Jetpack::is_user_connected( $user->ID ); + } - $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); - /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Approve it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" - : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ). "\r\n"; + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); - if ( EMPTY_TRASH_DAYS ) { - /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Trash it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" - : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n"; - } else { /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Delete it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" - : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n"; - } + $notify_message .= sprintf( + __( 'Approve it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" + : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) + ) . "\r\n"; + + if ( EMPTY_TRASH_DAYS ) { + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( + __( 'Trash it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" + : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) + ) . "\r\n"; + } else { + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( + __( 'Delete it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" + : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) + ) . "\r\n"; + } - /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( __( 'Spam it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" - : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n"; + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( + __( 'Spam it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" + : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) + ) . "\r\n"; - /* translators: Comment moderation. 1: Number of comments awaiting approval */ - $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', - 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; + /* translators: Comment moderation. 1: Number of comments awaiting approval */ + $notify_message .= sprintf( + _n( + 'Currently %s comment is waiting for approval. Please visit the moderation panel:', + 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting + ), number_format_i18n( $comments_waiting ) + ) . "\r\n"; - $notify_message .= $moderate_on_wpcom - ? "https://wordpress.com/comments/pending/{$primary_site_slug}/" - : admin_url( "edit-comments.php?comment_status=moderated#wpbody-content" ) . "\r\n"; + $notify_message .= $moderate_on_wpcom + ? "https://wordpress.com/comments/pending/{$primary_site_slug}/" + : admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; - /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ - $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); - $message_headers = ''; + /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ + $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); + $message_headers = ''; - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); - foreach ( $emails as $email ) { - @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); - } + foreach ( $emails as $email ) { + @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); + } - if ( $switched_locale ) { - restore_previous_locale(); - } + if ( $switched_locale ) { + restore_previous_locale(); + } - return true; -} + return true; + } endif; From df169f868a4eacbc2c298705f535d3349802d258 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 25 Jan 2018 11:32:05 +0300 Subject: [PATCH 6/7] Fixed indentation. --- moderation-emails-override.php | 127 +++++++++++++++++---------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/moderation-emails-override.php b/moderation-emails-override.php index b3cf04bf651ba..fed17b8bdf9f1 100644 --- a/moderation-emails-override.php +++ b/moderation-emails-override.php @@ -2,14 +2,14 @@ if ( ! function_exists( 'wp_notify_postauthor' ) && Jetpack::is_active() ) : /** - * Notify an author (and/or others) of a comment/trackback/pingback on a post. - * - * @since 1.0.0 - * - * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. - * @param string $deprecated Not used - * @return bool True on completion. False if no email addresses were specified. - */ + * Notify an author (and/or others) of a comment/trackback/pingback on a post. + * + * @since 1.0.0 + * + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. + * @param string $deprecated Not used + * @return bool True on completion. False if no email addresses were specified. + */ function wp_notify_postauthor( $comment_id, $deprecated = null ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '3.8.0' ); @@ -66,22 +66,23 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { $emails = array_flip( $emails ); } - $switched_locale = switch_to_locale( get_locale() ); + $switched_locale = switch_to_locale( get_locale() ); - $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); + $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); - // The blogname option is escaped with esc_html on the way into the database in sanitize_option - // we want to reverse this for the plain text arena of emails. - $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); - $comment_content = wp_specialchars_decode( $comment->comment_content ); + // The blogname option is escaped with esc_html on the way into the database in sanitize_option + // we want to reverse this for the plain text arena of emails. + $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); + $comment_content = wp_specialchars_decode( $comment->comment_content ); function is_user_connected( $email ) { $user = get_user_by( 'email', $email ); return Jetpack::is_user_connected( $user->ID ); } - $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); - $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); + $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); + + $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); switch ( $comment->comment_type ) { case 'trackback': @@ -119,11 +120,11 @@ function is_user_connected( $email ) { break; } - $notify_message .= $moderate_on_wpcom + $notify_message .= $moderate_on_wpcom ? "https://wordpress.com/comments/all/{$primary_site_slug}/{$comment->comment_post_ID}/\r\n\r\n" : get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n"; - $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; + $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { if ( EMPTY_TRASH_DAYS ) { @@ -146,7 +147,7 @@ function is_user_connected( $email ) { ) . "\r\n"; } - $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) ); + $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) ); if ( '' == $comment->comment_author ) { $from = "From: \"$blogname\" <$wp_email>"; @@ -160,21 +161,21 @@ function is_user_connected( $email ) { } } - $message_headers = "$from\n" + $message_headers = "$from\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; if ( isset( $reply_to ) ) { $message_headers .= $reply_to . "\n"; } - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); foreach ( $emails as $email ) { @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); @@ -184,24 +185,24 @@ function is_user_connected( $email ) { restore_previous_locale(); } - return true; + return true; } endif; if ( ! function_exists( 'wp_notify_moderator' ) && Jetpack::is_active() ) : /** - * Notifies the moderator of the site about a new comment that is awaiting approval. - * - * @since 1.0.0 - * - * @global wpdb $wpdb WordPress database abstraction object. - * - * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator - * should be notified, overriding the site setting. - * - * @param int $comment_id Comment ID. - * @return true Always returns true. - */ + * Notifies the moderator of the site about a new comment that is awaiting approval. + * + * @since 1.0.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator + * should be notified, overriding the site setting. + * + * @param int $comment_id Comment ID. + * @return true Always returns true. + */ function wp_notify_moderator( $comment_id ) { global $wpdb; @@ -306,37 +307,37 @@ function is_user_connected( $email ) { ) . "\r\n"; } - /* translators: Comment moderation. 1: Comment action URL */ - $notify_message .= sprintf( - __( 'Spam it: %s' ), $moderate_on_wpcom - ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" - : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) - ) . "\r\n"; + /* translators: Comment moderation. 1: Comment action URL */ + $notify_message .= sprintf( + __( 'Spam it: %s' ), $moderate_on_wpcom + ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" + : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) + ) . "\r\n"; - /* translators: Comment moderation. 1: Number of comments awaiting approval */ - $notify_message .= sprintf( - _n( - 'Currently %s comment is waiting for approval. Please visit the moderation panel:', - 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting - ), number_format_i18n( $comments_waiting ) - ) . "\r\n"; + /* translators: Comment moderation. 1: Number of comments awaiting approval */ + $notify_message .= sprintf( + _n( + 'Currently %s comment is waiting for approval. Please visit the moderation panel:', + 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting + ), number_format_i18n( $comments_waiting ) + ) . "\r\n"; - $notify_message .= $moderate_on_wpcom + $notify_message .= $moderate_on_wpcom ? "https://wordpress.com/comments/pending/{$primary_site_slug}/" : admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; - /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ - $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); - $message_headers = ''; + /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ + $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); + $message_headers = ''; - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); + /** This filter is documented in core/src/wp-includes/pluggable.php */ + $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); @@ -346,6 +347,6 @@ function is_user_connected( $email ) { restore_previous_locale(); } - return true; + return true; } endif; From fc70e8cc9071af7cf578aa8209e9a78bf5bbc396 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 25 Jan 2018 11:55:23 +0300 Subject: [PATCH 7/7] Moved the override file into the library folder. --- .../lib/functions.wp-notify.php | 1 + class.jetpack.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename moderation-emails-override.php => _inc/lib/functions.wp-notify.php (99%) diff --git a/moderation-emails-override.php b/_inc/lib/functions.wp-notify.php similarity index 99% rename from moderation-emails-override.php rename to _inc/lib/functions.wp-notify.php index fed17b8bdf9f1..6be0c3ac52bf0 100644 --- a/moderation-emails-override.php +++ b/_inc/lib/functions.wp-notify.php @@ -16,6 +16,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { } $comment = get_comment( $comment_id ); + if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) { return false; } diff --git a/class.jetpack.php b/class.jetpack.php index 32edc202f1a3c..b0c51cdc42b2b 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -645,7 +645,7 @@ private function __construct() { //we'll override wp_notify_postauthor and wp_notify_moderator pluggable functions //so they point moderation links on emails to Calypso - require_once( JETPACK__PLUGIN_DIR . 'moderation-emails-override.php' ); + jetpack_require_lib( 'functions.wp-notify' ); } // Update the Jetpack plan from API on heartbeats