我编写了一个自定义 Wordpress 功能,用于在向该页面发布新评论时向用户发送电子邮件。我以为我的代码只有在评论被批准后才会发送电子邮件。但即使评论被 WordPress 标记为垃圾,它似乎也在发送电子邮件。
我的代码:
add_action('comment_post', 'pulse_alert', 11, 2);
function pulse_alert($comment_ID, $approved) {
//if the comment is approved
if ($approved)
{
global $post;
$username = $post->post_title;
$user = get_user_by('login', $username);
//if the user exists
if ($user)
{
//get pulse config details
$userid = $user->ID;
$alerts = get_cimyFieldValue($userid, 'PULSEALERT');
$emailformat = get_cimyFieldValue($userid, 'PULSEALERTFORMAT');
if($alerts == 'YES')
{
//user details
$user_info = get_userdata($userid);
$user_email = $user_info->user_email;
//for page link
$email_newpulse_pagelink = $username;
//for email title
$email_newpulse_companyname = get_cimyFieldValue($userid, 'COMPANYNAME');
//Code for Pulse alert emails
include_once('email/email_newpulse.php');
$headers[] = 'From: The PartnerPulse team <hello@partnerpulse.co>';
$headers[] = 'Bcc: The PartnerPulse team <hello@partnerpulse.co>';
//Send email
$mail = wp_mail($user_email, $email_newpulse_subject, $email_newpulse_body, $headers);
}
}
}
}
似乎 $approved var 不起作用。有任何想法吗?