我需要在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;
}
#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
}
#2
尝试这个
$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') ) ;
评论前必须登录!
注册