Make WordPress Core

Ticket #33587: 33587.diff

File 33587.diff, 26.1 KB (added by dshanske, 10 years ago)

Patch for Adding Hooks to Notify

  • comment-functions.php

     
    24072407
    24082408        return $open;
    24092409}
     2410
     2411/**
     2412 * Generates a text summary for a comment to be used in notification messages.
     2413 *                                                                             
     2414 * @access public
     2415 * @since trunk
     2416 *
     2417 * @param int $comment_id Comment ID
     2418 * @return string $notify_message
     2419 */
     2420function get_comment_notify_summary( $comment_id ) {
     2421        $comment = get_comment($comment_id);
     2422        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
     2423        switch ( $comment->comment_type ) {
     2424                case 'trackback':
     2425                        /* translators: 1: website name, 2: website IP, 3: website hostname */
     2426                        $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
     2427                        $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     2428                        $notify_message .= sprintf( __( 'Trackback Excerpt: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
     2429                        break;
     2430                case 'pingback':
     2431                        /* translators: 1: website name, 2: website IP, 3: website hostname */
     2432                        $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
     2433                        $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     2434                        $notify_message .= sprintf( __( 'Pingback Excerpt: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
     2435                        break;
     2436                        default: // Comments
     2437                                /* translators: 1: comment author, 2: author IP, 3: author domain */
     2438                                $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
     2439                                $notify_message .= sprintf( __( 'E-mail: %s' ), $comment->comment_author_email ) . "\r\n";
     2440                                $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     2441                                $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
     2442                                break;
     2443                }
     2444    /**
     2445     * Filter the result, allowing for custom comment types and/or custom presentation.
     2446     *
     2447     * @since
     2448     *
     2449     * @param string $notify_message Text of the Summary Message.
     2450     * @param int $comment_id Comment ID.
     2451     */
     2452                return apply_filters( 'comment_notify_summary', $notify_message, $comment_id );
     2453}
     2454
     2455/**
     2456 * Notifies a moderator that a new comment is available
     2457 *
     2458 * @access public
     2459 * @since trunk
     2460 *
     2461 * @param int $comment_id Comment ID
     2462 */
     2463function wp_email_moderator( $comment_id ) {
     2464        global $wpdb;
     2465        $comment = get_comment($comment_id);
     2466        $post = get_post($comment->comment_post_ID);
     2467        $user = get_userdata( $post->post_author );
     2468        // Send to the administration and to the post author if the author can modify the comment.
     2469        $emails = array( get_option( 'admin_email' ) );
     2470        if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
     2471                if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) )
     2472                        $emails[] = $user->user_email;
     2473        }
     2474        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
     2475        $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
     2476 
     2477        // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     2478        // we want to reverse this for the plain text arena of emails.
     2479        $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     2480        $summary = get_comment_notify_summary ($comment_id);
     2481
     2482        // Generate the Moderation Links.
     2483  $moderation = sprintf( __('Approve it: %s'),  admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n";
     2484        if ( EMPTY_TRASH_DAYS )
     2485                $moderation .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
     2486        else
     2487                $moderation .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
     2488        $moderation .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
     2489 
     2490        $moderation .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',
     2491                'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n";
     2492        $moderation .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n";
     2493        /**
     2494         * Filter the comment moderation email links.
     2495         *
     2496         * @since
     2497         *
     2498         * @param string $moderation Text of the comment moderation email links.
     2499         * @param int    $comment_id     Comment ID.
     2500         */
     2501        $moderation = apply_filters( 'comment_notify_moderator_links', $moderation, $comment_id );
     2502
     2503        /**
     2504         * Filter the list of recipients for comment moderation emails.
     2505         *
     2506         * @since 3.7.0
     2507         *
     2508         * @param array $emails     List of email addresses to notify for comment moderation.
     2509         * @param int   $comment_id Comment ID.
     2510         */
     2511        $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
     2512
     2513
     2514        // Set up an Optional Header and a Footer for the Emails
     2515        $header = '';
     2516        $footer = '';
     2517
     2518  /**
     2519  * Filter the email header.
     2520  *
     2521  * @since
     2522  *
     2523  * @param string $header Text of the header for the email.
     2524  */
     2525        $header = apply_filters( 'email_notify_header', $header );
     2526
     2527  /**
     2528  * Filter the email footer.
     2529  *
     2530  * @since
     2531  *
     2532  * @param string $footer Text of the footer for the email.
     2533  */
     2534  $footer = apply_filters( 'email_notify_footer', $footer );
     2535
     2536
     2537        // Put together the pieces of the message.
     2538        $notify_message = $header . $summary . $moderation . $footer;
     2539
     2540        /**
     2541        * Filter the comment moderation email text.
     2542        *
     2543        * @since 1.5.2
     2544        *
     2545        * @param string $notify_message Text of the comment moderation email.
     2546        * @param int    $comment_id     Comment ID.
     2547        */
     2548        $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
     2549
     2550
     2551        $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
     2552
     2553        /**
     2554         * Filter the comment moderation email subject.
     2555         *
     2556         * @since 1.5.2
     2557         *
     2558         * @param string $subject    Subject of the comment moderation email.
     2559         * @param int    $comment_id Comment ID.
     2560         */
     2561        $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
     2562
     2563        /**
     2564         * Filter the comment moderation email headers.
     2565         *
     2566         * @since 2.8.0
     2567         *
     2568         * @param string $message_headers Headers for the comment moderation email.
     2569         * @param int    $comment_id      Comment ID.
     2570         */
     2571        $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
     2572       
     2573
     2574        foreach ( $emails as $email ) {
     2575                @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
     2576        }
     2577}
     2578
     2579add_action ( 'wp_notify_moderator', 'wp_email_moderator', 10, 1);
     2580
     2581/**
     2582 * Notifies a post author that a new comment is available
     2583 *
     2584 * @access public
     2585 * @since trunk
     2586 *
     2587 * @param int $comment_id Comment ID
     2588 */
     2589function wp_email_postauthor( $comment_id ) {
     2590        $post    = get_post( $comment->comment_post_ID );
     2591        $author  = get_userdata( $post->post_author );
     2592
     2593        // Who to notify? By default, just the post author, but others can be added.
     2594        $emails = array();
     2595        if ( $author ) {
     2596                $emails[] = $author->user_email;
     2597        }
     2598 
     2599        /**
     2600         * Filter the list of email addresses to receive a comment notification.
     2601         *
     2602         * By default, only post authors are notified of comments. This filter allows
     2603         * others to be added.
     2604         *
     2605         * @since 3.7.0
     2606         *
     2607         * @param array $emails     An array of email addresses to receive a comment notification.
     2608         * @param int   $comment_id The comment ID.
     2609         */
     2610         $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
     2611         $emails = array_filter( $emails );
     2612 
     2613        // If there are no addresses to send the comment to, bail.
     2614        if ( ! count( $emails ) ) {
     2615                return false;
     2616        }
     2617        // Facilitate unsetting below without knowing the keys.
     2618        $emails = array_flip( $emails );
     2619 
     2620        /**
     2621         * Filter whether to notify comment authors of their comments on their own posts.
     2622         *
     2623         * By default, comment authors aren't notified of their comments on their own
     2624         * posts. This filter allows you to override that.
     2625         *
     2626         * @since 3.8.0
     2627         *
     2628         * @param bool $notify     Whether to notify the post author of their own comment.
     2629         *                         Default false.
     2630         * @param int  $comment_id The comment ID.
     2631         */
     2632        $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id );
     2633        // The comment was left by the author
     2634        if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
     2635                        unset( $emails[ $author->user_email ] );
     2636        }
     2637 
     2638        // The author moderated a comment on their own post
     2639        if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) {
     2640                unset( $emails[ $author->user_email ] );
     2641        }
     2642 
     2643        // The post author is no longer a member of the blog
     2644        if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
     2645                unset( $emails[ $author->user_email ] );
     2646        }
     2647 
     2648        // If there's no email to send the comment to, bail, otherwise flip array back around for use below
     2649        if ( ! count( $emails ) ) {
     2650                return false;
     2651        } else {
     2652                $emails = array_flip( $emails );
     2653        }
     2654
     2655        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
     2656 
     2657        // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     2658        // we want to reverse this for the plain text arena of emails.
     2659        $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     2660
     2661        $summary = get_comment_notify_summary( $comment_id );
     2662
     2663        $moderation = get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
     2664        $moderation .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n";
     2665 
     2666        if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) {
     2667                if ( EMPTY_TRASH_DAYS )
     2668                        $moderation .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
     2669                else
     2670                        $moderation .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
     2671                        $moderation .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
     2672        }
     2673  /**
     2674   * Filter the comment moderation email links.
     2675   *
     2676   * @since
     2677   *
     2678   * @param string $moderation Text of the comment moderation email links.
     2679   * @param int    $comment_id     Comment ID.
     2680   */
     2681  $moderation = apply_filters( 'comment_notify_postauthor_links', $moderation, $comment_id );
     2682
     2683        $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
     2684 
     2685        if ( '' == $comment->comment_author ) {
     2686                $from = "From: \"$blogname\" <$wp_email>";
     2687                if ( '' != $comment->comment_author_email )
     2688                        $reply_to = "Reply-To: $comment->comment_author_email";
     2689                } else {
     2690                        $from = "From: \"$comment->comment_author\" <$wp_email>";
     2691                if ( '' != $comment->comment_author_email )
     2692                        $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
     2693                }
     2694 
     2695        $message_headers = "$from\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
     2696        if ( isset($reply_to) )
     2697                $message_headers .= $reply_to . "\n";
     2698
     2699        // Set up an Optional Header and a Footer for the Emails
     2700        $header = '';
     2701        $footer = '';
     2702
     2703        /**
     2704         * Filter the email header.
     2705         *
     2706         * @since
     2707         *
     2708         * @param string $header Text of the header for the email.
     2709         */
     2710        $header = apply_filters( 'email_notify_header', $header );
     2711
     2712        /**
     2713         * Filter the email footer.
     2714         *
     2715         * @since
     2716         *
     2717         * @param string $footer Text of the footer for the email.
     2718         */
     2719        $footer = apply_filters( 'email_notify_footer', $footer );
     2720
     2721
     2722  // Put together the pieces of the message.
     2723  $notify_message = $header . $summary . $moderation . $footer;
     2724
     2725        /**
     2726         * Filter the comment notification email text.
     2727         *
     2728         * @since 1.5.2
     2729         *
     2730         * @param string $notify_message The comment notification email text.
     2731         * @param int    $comment_id     Comment ID.
     2732         */
     2733        $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id );
     2734 
     2735        /**
     2736         * Filter the comment notification email subject.
     2737         *
     2738         * @since 1.5.2
     2739         *
     2740         * @param string $subject    The comment notification email subject.
     2741         * @param int    $comment_id Comment ID.
     2742         */
     2743         $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id );
     2744 
     2745        /**
     2746         * Filter the comment notification email headers.
     2747         *
     2748         * @since 1.5.2
     2749         *
     2750         * @param string $message_headers Headers for the comment notification email.
     2751         * @param int    $comment_id      Comment ID.
     2752         */
     2753        $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );
     2754 
     2755        foreach ( $emails as $email ) {
     2756         @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
     2757        }
     2758 
     2759        return true;
     2760}
     2761
     2762add_action ( 'wp_notify_postauthor', 'wp_email_postauthor', 10, 1);
     2763
     2764
  • pluggable.php

     
    13651365        if ( empty( $comment ) )
    13661366                return false;
    13671367
    1368         $post    = get_post( $comment->comment_post_ID );
    1369         $author  = get_userdata( $post->post_author );
    1370 
    1371         // Who to notify? By default, just the post author, but others can be added.
    1372         $emails = array();
    1373         if ( $author ) {
    1374                 $emails[] = $author->user_email;
    1375         }
    1376 
    13771368        /**
    1378          * Filter the list of email addresses to receive a comment notification.
     1369         * Hook to add functions that notify the post author.
    13791370         *
    1380          * By default, only post authors are notified of comments. This filter allows
    1381          * others to be added.
     1371         * @since
    13821372         *
    1383          * @since 3.7.0
    1384          *
    1385          * @param array $emails     An array of email addresses to receive a comment notification.
    1386          * @param int   $comment_id The comment ID.
     1373         * @param int   $comment_id Comment ID.
    13871374         */
    1388         $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
    1389         $emails = array_filter( $emails );
    1390 
    1391         // If there are no addresses to send the comment to, bail.
    1392         if ( ! count( $emails ) ) {
    1393                 return false;
    1394         }
    1395 
    1396         // Facilitate unsetting below without knowing the keys.
    1397         $emails = array_flip( $emails );
    1398 
    1399         /**
    1400          * Filter whether to notify comment authors of their comments on their own posts.
    1401          *
    1402          * By default, comment authors aren't notified of their comments on their own
    1403          * posts. This filter allows you to override that.
    1404          *
    1405          * @since 3.8.0
    1406          *
    1407          * @param bool $notify     Whether to notify the post author of their own comment.
    1408          *                         Default false.
    1409          * @param int  $comment_id The comment ID.
    1410          */
    1411         $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id );
    1412 
    1413         // The comment was left by the author
    1414         if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
    1415                 unset( $emails[ $author->user_email ] );
    1416         }
    1417 
    1418         // The author moderated a comment on their own post
    1419         if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) {
    1420                 unset( $emails[ $author->user_email ] );
    1421         }
    1422 
    1423         // The post author is no longer a member of the blog
    1424         if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
    1425                 unset( $emails[ $author->user_email ] );
    1426         }
    1427 
    1428         // If there's no email to send the comment to, bail, otherwise flip array back around for use below
    1429         if ( ! count( $emails ) ) {
    1430                 return false;
    1431         } else {
    1432                 $emails = array_flip( $emails );
    1433         }
    1434 
    1435         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
    1436 
    1437         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1438         // we want to reverse this for the plain text arena of emails.
    1439         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    1440 
    1441         switch ( $comment->comment_type ) {
    1442                 case 'trackback':
    1443                         $notify_message  = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
    1444                         /* translators: 1: website name, 2: website IP, 3: website hostname */
    1445                         $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1446                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1447                         $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
    1448                         $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
    1449                         /* translators: 1: blog name, 2: post title */
    1450                         $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
    1451                         break;
    1452                 case 'pingback':
    1453                         $notify_message  = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
    1454                         /* translators: 1: website name, 2: website IP, 3: website hostname */
    1455                         $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1456                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1457                         $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
    1458                         $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
    1459                         /* translators: 1: blog name, 2: post title */
    1460                         $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
    1461                         break;
    1462                 default: // Comments
    1463                         $notify_message  = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
    1464                         /* translators: 1: comment author, 2: author IP, 3: author domain */
    1465                         $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1466                         $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
    1467                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1468                         $notify_message .= sprintf( __('Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
    1469                         $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n";
    1470                         /* translators: 1: blog name, 2: post title */
    1471                         $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
    1472                         break;
    1473         }
    1474         $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
    1475         $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n";
    1476 
    1477         if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) {
    1478                 if ( EMPTY_TRASH_DAYS )
    1479                         $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
    1480                 else
    1481                         $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
    1482                 $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
    1483         }
    1484 
    1485         $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
    1486 
    1487         if ( '' == $comment->comment_author ) {
    1488                 $from = "From: \"$blogname\" <$wp_email>";
    1489                 if ( '' != $comment->comment_author_email )
    1490                         $reply_to = "Reply-To: $comment->comment_author_email";
    1491         } else {
    1492                 $from = "From: \"$comment->comment_author\" <$wp_email>";
    1493                 if ( '' != $comment->comment_author_email )
    1494                         $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
    1495         }
    1496 
    1497         $message_headers = "$from\n"
    1498                 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    1499 
    1500         if ( isset($reply_to) )
    1501                 $message_headers .= $reply_to . "\n";
    1502 
    1503         /**
    1504          * Filter the comment notification email text.
    1505          *
    1506          * @since 1.5.2
    1507          *
    1508          * @param string $notify_message The comment notification email text.
    1509          * @param int    $comment_id     Comment ID.
    1510          */
    1511         $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id );
    1512 
    1513         /**
    1514          * Filter the comment notification email subject.
    1515          *
    1516          * @since 1.5.2
    1517          *
    1518          * @param string $subject    The comment notification email subject.
    1519          * @param int    $comment_id Comment ID.
    1520          */
    1521         $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id );
    1522 
    1523         /**
    1524          * Filter the comment notification email headers.
    1525          *
    1526          * @since 1.5.2
    1527          *
    1528          * @param string $message_headers Headers for the comment notification email.
    1529          * @param int    $comment_id      Comment ID.
    1530          */
    1531         $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );
    1532 
    1533         foreach ( $emails as $email ) {
    1534                 @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
    1535         }
    1536 
     1375        do_action( 'wp_notify_postauthor', $comment_id );
    15371376        return true;
    15381377}
    15391378endif;
     
    15501389 * @return true Always returns true
    15511390 */
    15521391function wp_notify_moderator($comment_id) {
    1553         global $wpdb;
    1554 
    15551392        if ( 0 == get_option( 'moderation_notify' ) )
    15561393                return true;
    15571394
    1558         $comment = get_comment($comment_id);
    1559         $post = get_post($comment->comment_post_ID);
    1560         $user = get_userdata( $post->post_author );
    1561         // Send to the administration and to the post author if the author can modify the comment.
    1562         $emails = array( get_option( 'admin_email' ) );
    1563         if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
    1564                 if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) )
    1565                         $emails[] = $user->user_email;
    1566         }
    1567 
    1568         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
    1569         $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
    1570 
    1571         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1572         // we want to reverse this for the plain text arena of emails.
    1573         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    1574 
    1575         switch ( $comment->comment_type ) {
    1576                 case 'trackback':
    1577                         $notify_message  = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
    1578                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
    1579                         /* translators: 1: website name, 2: website IP, 3: website hostname */
    1580                         $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1581                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1582                         $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
    1583                         break;
    1584                 case 'pingback':
    1585                         $notify_message  = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
    1586                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
    1587                         /* translators: 1: website name, 2: website IP, 3: website hostname */
    1588                         $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1589                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1590                         $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
    1591                         break;
    1592                 default: // Comments
    1593                         $notify_message  = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
    1594                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
    1595                         $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
    1596                         $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
    1597                         $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
    1598                         $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n";
    1599                         break;
    1600         }
    1601 
    1602         $notify_message .= sprintf( __('Approve it: %s'),  admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n";
    1603         if ( EMPTY_TRASH_DAYS )
    1604                 $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
    1605         else
    1606                 $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
    1607         $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
    1608 
    1609         $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',
    1610                 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n";
    1611         $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n";
    1612 
    1613         $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
    1614         $message_headers = '';
    1615 
    16161395        /**
    1617          * Filter the list of recipients for comment moderation emails.
     1396         * Hook to add functions that notify the moderator.
    16181397         *
    1619          * @since 3.7.0
     1398         * @since
    16201399         *
    1621          * @param array $emails     List of email addresses to notify for comment moderation.
    16221400         * @param int   $comment_id Comment ID.
    16231401         */
    1624         $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
    1625 
    1626         /**
    1627          * Filter the comment moderation email text.
    1628          *
    1629          * @since 1.5.2
    1630          *
    1631          * @param string $notify_message Text of the comment moderation email.
    1632          * @param int    $comment_id     Comment ID.
    1633          */
    1634         $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
    1635 
    1636         /**
    1637          * Filter the comment moderation email subject.
    1638          *
    1639          * @since 1.5.2
    1640          *
    1641          * @param string $subject    Subject of the comment moderation email.
    1642          * @param int    $comment_id Comment ID.
    1643          */
    1644         $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
    1645 
    1646         /**
    1647          * Filter the comment moderation email headers.
    1648          *
    1649          * @since 2.8.0
    1650          *
    1651          * @param string $message_headers Headers for the comment moderation email.
    1652          * @param int    $comment_id      Comment ID.
    1653          */
    1654         $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
    1655 
    1656         foreach ( $emails as $email ) {
    1657                 @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
    1658         }
    1659 
     1402        do_action( 'wp_notify_moderator', $comment_id );
    16601403        return true;
    16611404}
    16621405endif;