How to Add Super Admin for WordPress multi-site

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.”;
}

I have put this code inside PHP file and put that file in root folder.
When I run this file it Create “Admin” user for only main site.
I want code that will create “super admin” which can access all the multi-site.

Read more here:: How to Add Super Admin for WordPress multi-site

Leave a Reply

Your email address will not be published. Required fields are marked *