我需要在wp_users表中创建一个新用户,但是wp_create_user和wp_insert_user都不起作用。 我正在尝试这种方式,但是没有插入用户。
$newUser = $wpdb->insert(
'wp_users',
array(
'user_login' => $userRow->email,
'user_pass' => $userRow->password,
'user_nicename' => $userRow->firstname,
'user_email' => $userRow->email,
'user_url' => '',
'user_registered' => $userRow->registration,
'user_status' => 0,
'display_name' => $userRow->firstname
)
);
if(!$newUser) {
echo '<script>alert("User has not been created.")</script>';
return;
}
答案 0 :(得分:1)
使用类似的方法在WP中创建用户
确保变量具有值
$username = $userRow->email;
$email = $userRow->email;
$password = $userRow->password;
$user = wp_insert_user(array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
));
if( !is_wp_error( $user ) ){
} else {
// success message
}
答案 1 :(得分:0)
尝试
$WP_array = array (
'user_login' => 'username',
'user_email' => 'emailID',
'user_pass' => 'Password',
) ;
$id = wp_insert_user( $WP_array ) ;
// if you want to add role to user
wp_update_user( array ('ID' => $id, 'role' => 'editor') ) ;