Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #202 from fpozzer/master

Avoiding redefinition of core function wp_notify_moderator
  • Loading branch information...
commit 3f4b672d4471ecfe4c515cd0f888b9db19500582 2 parents 6ad24ff + d270bd3
@mjangda mjangda authored
Showing with 21 additions and 83 deletions.
  1. +21 −83 co-authors-plus.php
View
104 co-authors-plus.php
@@ -107,6 +107,9 @@ function __construct() {
// Support Jetpack Open Graph Tags
add_filter( 'jetpack_open_graph_tags', array( $this, 'filter_jetpack_open_graph_tags' ), 10, 2 );
+
+ // Filter to send comment moderation notification e-mail to multiple authors
+ add_filter( 'comment_moderation_recipients', 'cap_filter_comment_moderation_email_recipients', 10, 2 );
}
@@ -1465,90 +1468,25 @@ function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
}
endif;
-if ( !function_exists('wp_notify_moderator') ) :
/**
- * Notifies the moderator of the blog about a new comment that is awaiting approval.
- * This is a modified version of the core function in wp-includes/pluggable.php that
- * supports notifs to multiple co-authors. Unfortunately, this is the best way to do it :(
- *
- * @since 2.6.2
- *
- * @param int $comment_id Comment ID
- * @return bool Always returns true
+ * Filter array of moderation notification email addresses
+ *
+ * @param array $recipients
+ * @param int $comment_id
+ * @return array
*/
-function wp_notify_moderator( $comment_id ) {
- global $wpdb;
-
- if ( 0 == get_option( 'moderation_notify' ) )
- return true;
+function cap_filter_comment_moderation_email_recipients( $recipients, $comment_id ) {
+ $comment = get_comment( $comment_id );
+ $post_id = $comment->comment_post_ID;
+
+ if ( isset($post_id) ) {
+ $coauthors = get_coauthors( $post_id );
+ foreach ( $coauthors as $user ) {
+ if ( !empty($user->user_email) )
+ $extra_recipients[] = $user->user_email;
+ }
- $comment = get_comment($comment_id);
- $post = get_post($comment->comment_post_ID);
- $coauthors = get_coauthors( $post->ID );
- // Send to the administration and to the co-authors if the co-author can modify the comment.
- $email_to = array( get_option('admin_email') );
- foreach( $coauthors as $user ) {
- if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
- $email_to[] = $user->user_email;
+ return array_unique( array_merge( $recipients, $extra_recipients ) );
}
-
- $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);
-
- switch ($comment->comment_type)
- {
- case 'trackback':
- $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";
- $notify_message .= sprintf( __('Website : %1$s (IP: %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 .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- break;
- case 'pingback':
- $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";
- $notify_message .= sprintf( __('Website : %1$s (IP: %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 .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- break;
- default: //Comments
- $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";
- $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
- $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
- $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
- $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- break;
- }
-
- $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n";
- if ( EMPTY_TRASH_DAYS )
- $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
- else
- $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
- $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
-
- $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") . "\r\n";
-
- $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
- $message_headers = '';
-
- $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
- $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
- $message_headers = apply_filters('comment_moderation_headers', $message_headers);
-
- foreach ( $email_to as $email )
- @wp_mail($email, $subject, $notify_message, $message_headers);
-
- return true;
-}
-endif;
-
-
+ return $recipients;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.