简体   繁体   English

WordPress用户已成功创建功能,但未发送“ SB欢迎电子邮件”

[英]WordPress user functionally created successfully but 'SB Welcome Email' not sent

I have created wp user by functions and it's working successfully. 我已经通过功能创建了wp用户,并且它可以成功运行。 Now the problem is SB Welcome Email not sent if the user created by function but If I created manually user from dashboard then mail has been sent. 现在的问题是,如果用户是按功能创建的,则不发送SB Welcome Email ,但是如果我是从仪表板手动创建的,则邮件已发送。 I don't want to use another custom wp_mail() for custom user creation by functions. 我不想使用其他自定义wp_mail()来通过函数创建自定义用户。 How can I overcome this? 我该如何克服? SB Welcome Email Code SB欢迎电子邮件代码

$user_login     =  wp_slash( $username );
    $user_email     =  wp_slash( $email );
    $display_name   =  wp_slash( $full_name );
    $first_name     =  wp_slash( $f_name );
    $last_name      =  wp_slash( $l_name );
    $user_pass      =  $password;
    $role           =  'student';
    $exists = email_exists( $user_email );

    if ( username_exists( $user_login ) && !email_exists( $user_email ) ) {
        $user_login = $user_login.'_student';
    } else {
        $user_login = $user_login;
    }


    if ( !$exists ) {
        $userdata = compact( 'user_login', 'user_email', 'user_pass', 'display_name', 'first_name', 'last_name', 'role' );
        //return wp_insert_user( $userdata );
        $user_id = wp_insert_user( $userdata ) ;

    }else{
        $user   = get_user_by( 'email', $user_email );
        $user_id = $user->ID;
    }

My guess is that you are missing a hook that is used by this 'SB Welcome Email' plugin. 我的猜测是您缺少此“ SB Welcome Email”插件使用的挂钩。

The one hook I can think of is user_register ( documentation ). 我能想到的一个钩子是user_registerdocumentation )。 But by default it is part from the wp_insert_user ( documentation ), so it should be triggered when you add the new user. 但默认情况下,它是wp_insert_user文档 )的一部分,因此在添加新用户时应触发它。 In this case you should check the 'SB Welcome Email' code and search for that functionality that sends the actual code and see if there isn't some other hook that the plugin is using. 在这种情况下,您应该检查“ SB欢迎电子邮件”代码并搜索发送实际代码的功能,然后查看插件是否正在使用其他挂钩。

I have found a solution to this. 我找到了解决方案。 Need to use this functions wp_new_user_notification($user_ids, false, 'both') 需要使用此功能wp_new_user_notification($user_ids, false, 'both')

The function sb_we_send_new_user_notification will be called once the user created. 一旦用户创建,函数sb_we_send_new_user_notification将被调用。 This action hook allows call a function for a new user immediately after they are added to the database. 此操作挂钩允许将新用户添加到数据库后立即为新用户调用函数。 The user id is passed to hook as an argument. 用户ID作为参数传递给hook。

add_action( 'user_register', 'myplugin_registration_save', 10, 1 );

function myplugin_registration_save( $user_id ) {

    sb_we_send_new_user_notification($user_id, true, true);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM