0

我似乎无法让这段代码工作。我正在尝试通过动态检索作者的电子邮件地址来更改 Gravity Forms/Wordpress 上的通知电子邮件。

如果我将作者的电子邮件地址硬编码到 '$notification['to']',则下面的代码有效。

我只是不确定我一定做错了什么。

感谢帮助。谢谢。

add_filter( 'gform_notification_19', 'change_notification_email', 10, 3 );
function change_notification_email( $user_email, $notification, $form, $entry ) {


    //There is no concept of admin notifications anymore, so we will need to target notifications based on other criteria, such as name
    if ( $notification['name'] == 'Applicant' ) {

        global $post;
        $author_id=$post->post_author;
        $user_email = get_the_author_meta( 'user_email' , $author_id );

        // toType can be routing or email
        $notification['toType'] = 'email'; 
        $notification['to'] = '$user_email';

    }

    return $notification;
}
4

1 回答 1

0

根据法典,这应该有效。还尝试打印变量以查看它们是否获得了正确的值。另外,您的过滤器是否正确?

add_filter( 'gform_notification_19', 'change_notification_email', 10, 3 );
function change_notification_email( $user_email, $notification, $form, $entry ) {


    //There is no concept of admin notifications anymore, so we will need to target notifications based on other criteria, such as name
    if ( $notification['name'] == 'Applicant' ) {

        global $post;
        $author_id=$post->post_author;
        $user_email = get_the_author_meta( 'user_email' , $author_id );

        // toType can be routing or email
        $notification['toType'] = 'email'; 
        $notification['to'] = $user_email;

    }

    return $notification;
}
于 2017-07-31T12:49:57.213 回答