我已经将此代码放在PHP文件中,并将该文件放在根文件夹中。当我运行这个文件时,它只为主站点创建“Admin”用户。我想要的代码,将创建“超级管理员”,可以访问所有的多网站。
require (\'wp-blog-header.php\');
$newusername = \'USERNAME\';
$newpassword = \'PASSWORD\';
$newemail = \'EMAIL\';
if ($newpassword != \' \' && $newemail != \' \' && $newusername != \' \') {
if (!username_exists($newusername) && !email_exists($newemail)) {
$user_id = wp_create_user($newusername, $newpassword, $newemail);
if (is_int($user_id)) {
$wp_user_object = new WP_User($user_id);
$wp_user_object->set_role(\'administrator\');
echo \'Successfully created new admin user.\';
} else {
echo \'Error with wp_insert_user. No users were created.\';
}
} else {
echo \'This user or email already exists. Nothing was done.\';
}
} else {
echo "Whoops, looks like you didn\'t set a password, username, or
email before running the script. Set these variables and try again.";
}
最合适的回答,由SO网友:Ravi Patel 整理而成
More information for how to manage user manually
Manage This settings
if ( $newpassword != \' \' && $newemail != \' \' && $newusername !=\' \' ) {
if ( !username_exists($newusername) && !email_exists($newemail) ) {
$user_id = wp_create_user( $newusername, $newpassword, $newemail);
if ( is_int($user_id) ) {
$wp_user_object = new WP_User($user_id);
$wp_user_object->set_role(\'administrator\');
grant_super_admin($user_id); // Grants Super Admin privileges.
echo \'Successfully created new admin user.\';
} else {
echo \'Error with wp_insert_user. No users were created.\';
}
} else {
echo \'This user or email already exists. Nothing was done.\';
}
} else {
echo "Whoops, looks like you didn\'t set a password, username, or
email before running the script. Set these variables and try again.";
}