0

I try to add a filter to the comment notification recipients function, for adding different recipients/moderators depending on the taxonomy terms of each post.

This is my code so far, but it doesn't work:

function se_comment_moderation_recipients( $emails, $comment_id ) {
    $emails = array( 'moderator@email.com' );
        if ( has_term('myterm','mytaxonomy') )
    return $emails;
}
add_filter( 'comment_moderation_recipients', 'se_comment_moderation_recipients', 11, 2 );
add_filter( 'comment_notification_recipients', 'se_comment_moderation_recipients', 11, 2 );

Any help would be really really appreciate.

0

Finally I found the right code, if it can be usefull to someone:

function sp_comment_moderation_recipients( $emails, $comment_id ) {

    $comment = get_comment( $comment_id );
    $post = get_post( $comment->comment_post_ID );

    if ( has_term('myterm','mytaxonomy', $post->ID) ) {

    return array( 'moderator@email.com' );
        }

    return $emails;
}

add_filter( 'comment_moderation_recipients', 'sp_comment_moderation_recipients', 10, 2 );
add_filter( 'comment_notification_recipients', 'sp_comment_moderation_recipients', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.