我需要在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【WordPress在wp_users中插入新用户】尝试这个
$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') ) ;
推荐阅读
- 当在functions.php文件中调用WordPress时,WordPress无法从数据库获取值
- WordPress的是否可以使用钩子在帖子标题的标记之后插入标记()
- WordPress(在两个菜单项之间插入char)
- WordPress独立functions.php
- WordPress图片在iOS上显示不佳
- WordPress(我自动在wp-content/themes/mytheme/function.php中添加了一个代码)
- WordPress iframe中心
- 靶机DC-9
- #yyds干货盘点#算法给小码农堆排序至尊骨