WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/21/2015 06:34:06 PM (6 years ago)
Author:
DrewAPicture
Message:

Comments: Introduce two new filters, notify_moderator and notify_post_author, both of which make it possible to selectively override site notification email settings for new comments.

The notify_moderator filter makes it possible to override the value for the moderation_notify option, which controls whether to send new comment emails to "site moderators", that is to say, the owner of the admin email for the site and the post author if they have the ability to modify the comment.

The notify_post_author filter likewise makes it possible to override the value for the comments_notify option, which controls whether to send new comment emails to the post author. If the post author is the comment author, default behavior is not to send the notification. Note: enabling or disabling notifications via this hook could also affect other recipients added via the 'comment_notification_recipients' filter in wp_notify_postauthor(), if hooked.

Passing a falsey value to either of the new filters will prevent notifications from being sent, regardless of their corresponding option values.

Adds tests.

Props coffee2code, adamsilverstein, DrewAPicture.
Fixes #761.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r35170 r35339  
    15621562if ( !function_exists('wp_notify_moderator') ) :
    15631563/**
    1564  * Notifies the moderator of the blog about a new comment that is awaiting approval.
     1564 * Notifies the moderator of the site about a new comment that is awaiting approval.
    15651565 *
    15661566 * @since 1.0.0
     
    15681568 * @global wpdb $wpdb WordPress database abstraction object.
    15691569 *
    1570  * @param int $comment_id Comment ID
    1571  * @return true Always returns true
     1570 * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator
     1571 * should be notified, overriding the site setting.
     1572 *
     1573 * @param int $comment_id Comment ID.
     1574 * @return true Always returns true.
    15721575 */
    15731576function wp_notify_moderator($comment_id) {
    15741577    global $wpdb;
    15751578
    1576     if ( 0 == get_option( 'moderation_notify' ) )
     1579    $maybe_notify = get_option( 'moderation_notify' );
     1580
     1581    /**
     1582     * Filter whether to send the site moderator email notifications, overriding the site setting.
     1583     *
     1584     * @since 4.4.0
     1585     *
     1586     * @param bool $maybe_notify Whether to notify blog moderator.
     1587     * @param int  $comment_ID   The id of the comment for the notification.
     1588     */
     1589    $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
     1590
     1591    if ( ! $maybe_notify ) {
    15771592        return true;
     1593    }
    15781594
    15791595    $comment = get_comment($comment_id);
     
    21732189                $use_random_int_functionality = false;
    21742190            }
    2175         } catch ( Throwable $t ) { 
     2191        } catch ( Throwable $t ) {
    21762192            $use_random_int_functionality = false;
    21772193        } catch ( Exception $e ) {
Note: See TracChangeset for help on using the changeset viewer.