WordPress Comment Moderation Tweak

This is a tweak to the WordPress 1.5 comment moderation function that changes the pluggable function "wp_notify_moderator" to notify the author of the subject post, rather than the site administrator, that a comment is awaiting moderation. If the author does not have an email address or does not possess sufficient rights to moderate comments, then the notification is sen to the site administrator.

--- pluggable-functions.php.20050814130602      2005-08-14 13:06:02.000000000 -0500
+++ pluggable-functions.php     2005-11-28 11:11:25.000000000 -0600
@@ -244,6 +244,7 @@

        $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
        $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
+       $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1");

        $comment_author_domain = gethostbyaddr($comment->comment_author_IP);
        $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
@@ -266,7 +267,11 @@
        $notify_message = apply_filters('comment_moderation_text', $notify_message);
        $subject = apply_filters('comment_moderation_subject', $subject);

+       if ('' == $user->user_email || 9 > $user->user_level) { // User has no email or insufficient rights to moderate comments
        @wp_mail($admin_email, $subject, $notify_message);
+               } else {
+               @wp_mail($user->user_email, $subject, $notify_message);
+       }

        return true;
 }