Sending comment notifications to different recipients depending on taxonomy terms

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( '[email protected]' );
        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.

Topic terms notifications comments moderation Wordpress

Category Web


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( '[email protected]' );
        }

    return $emails;
}

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.