我正在尝试使用wp\\u mail函数发送邮件,当对特定帖子发表新评论时,其中自定义字段是用邮件编译的。
该功能可以工作,但当我试图将其限制为未批准或已批准的评论(不是针对垃圾邮件)时,它将无法工作。我有一个功能,可以将每个新评论发送到垃圾邮件,在版主批准该评论或将其从垃圾邮件文件夹中移出(因此状态将更改为已批准或未批准)后,我想将邮件发送到特定地址:
// SEND NEW COMMENTS TO SPAM
function set_new_comment_to_spam($commentId) {
wp_set_comment_status($commentId, \'spam\');
}
add_action(\'comment_post\', \'set_new_comment_to_spam\', 10, 1);
// SEND MAIL TO CUSTOM FIELD
function send_comment_email_notification( $comment_ID, $comment_approved, $commentdata) {
$comment = get_comment( $comment_ID );
$postid = $comment->comment_post_ID;
$master_email = get_post_meta( $postid, \'email_custom\', true);
if( $comment_approved != \'spam\' && isset( $master_email ) && is_email( $master_email ) ) {
$message = \'New comment\';
add_filter( \'wp_mail_content_type\', create_function( \'\', \'return "text/html";\' ) );
wp_mail( $master_email, \'New comment\', $message );
}
}
add_action( \'comment_post\', \'send_comment_email_notification\', 11, 3 );