I can add an administrator like this:
$password = wp_generate_password();
$userData = array(
'user_pass' => $password,
'user_login' => $email,
'user_nicename' => sanitize_title($name),
'user_email' => $email,
'display_name' => $name,
'role' => 'administrator'
);
$user_id = wp_insert_user($userData);
That works fine, but how do I add a super user? What is the role name?
I tried ‘role’ => ‘super user’, ‘super_user’, ‘superuser’, … but nothing works.
The other answers are basically correct, but it is better to use built-in functions from WordPress whenever possible. The function you are looking for is
grant_super_admin()
.Based on your example code:
I had a quick flick through the WordPress code and I believe the option you are looking for is actually “site_admin”
There is no such role.
The super admins are stored as site options as you can see in the function
get_super_admins
.In
is_super_admin
it is checked whether the user’s login is in the array returned by the former function.Usually this is only the user with the login name admin. What you need to to is
This looks like it’s working:
1) Set user role to “site_admin”
2) Add user as administrator for every blog
3) As Alex said, add to site_admins: