Wordpress 的用户名或电子邮件密码不正确,使用 "wp_insert_user" 添加

Wordpress incorret password for username or email, added using "wp_insert_user"

所以我使用下面的代码创建了自己的用户。我非常确定我登录时的密码是正确的。但出于某种我不知道的原因,我总是有“您为电子邮件 address/username 输入的密码不正确”。谁能给我一些启发!!!

 function insert_into_wp_users(){
    // Check for nonce security      
    if (!wp_verify_nonce( $_POST['nonce'], 'active-aupair-nonce-string' ) ) {
        die();
    }
    $user_id = wp_insert_user( array(
       'user_email'   => $_POST['email'],
       'user_password'=> $_POST['password'],
    //    'first_name'   => $_POST['firstName'],
    //    'last_name'    => $_POST['lastName'],
       'user_login'   => $_POST['userLogin'],
       'role'         => 'subscriber'
     ));
     if( is_wp_error( $user_id  ) ) {
        wp_send_json_error($user_id->get_error_message());
    } else {
        wp_send_json_success($user_id);
    }
    die();
}

P.S 我确认我的用户存在。 Wordpress 无法验证密码。

编辑

您正在使用 user_password 而不是 user_pass

I lost an hour using your parameters.


此外,您似乎也应该能够使用 wp_create_user(),因为您没有做任何花哨的事情。

wp_create_user()

Creates a new user with just the username, password, and email. For more complex user creation use wp_insert_user() to specify more information.

add_action( 'init', 'wpso66859906' );
if ( ! function_exists( 'wpso66859906' ) ) {
    function wpso66859906() {

        $user = 'thomas';
        $email = 'thomas@pesquet.com';
        $password = 'password';

        if ( ! username_exists( sanitize_user( $user ) ) && is_email( sanitize_email( $email ) ) && ! email_exists( sanitize_email( $email ) ) ) {
            
            wp_create_user( sanitize_user( $user ), trim( $password ), sanitize_email( $email ) );
            
        };
    };
};