我尝试在“评论通知收件人”功能中添加一个过滤器,用于根据每个帖子的分类术语添加不同的收件人/版主。
到目前为止,这是我的代码,但它不起作用:
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 );
任何帮助都将不胜感激。
最合适的回答,由SO网友:Mahe Neel 整理而成
最后,我找到了正确的代码,如果它对某人有用的话:
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 );