Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress功能用于发送电子邮件以获取新的和已批准的评论_Php_Wordpress_Email - Fatal编程技术网

Php Wordpress功能用于发送电子邮件以获取新的和已批准的评论

Php Wordpress功能用于发送电子邮件以获取新的和已批准的评论,php,wordpress,email,Php,Wordpress,Email,我已经编写了一个自定义的Wordpress函数,当一个新的评论发布到那个页面时,它会向用户发送一封电子邮件。我认为我的代码只有在评论被批准时才发送电子邮件。但即使WordPress将评论标记为垃圾,它似乎也在发送电子邮件 我的代码: add_action('comment_post', 'pulse_alert', 11, 2); function pulse_alert($comment_ID, $approved) { //if the comment is approved

我已经编写了一个自定义的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不起作用。有什么想法吗?

我相信$approved对于未批准/已批准或垃圾邮件将是0/1

您可以在本页的一半处看到:

您的if语句正在测试$approved,以查看它是否正确。如果$批准通过垃圾邮件,它将等同于PHP将考虑一个字符串true,除非它是空的或0。p>
将if语句更改为if$approved==1,然后查看结果。

我在源代码中检查时,在数据库中插入注释后立即触发此操作挂钩。所以应该在正确的钩

但实际上,$approved var可以有3个值:0、1或spam

所以你应该这样做:

add_action('comment_post', 'pulse_alert', 11, 2);
function pulse_alert($comment_ID, $approved) {  
    //if the comment is approved
    if ($approved == 1) 
    {

您可以检查该功能。

对于不同的状态,打印出的$approved是什么?