Jan 7, 2019
Get All Super Admin Users in WordPress
WordPressโ get_super_admins()
function can be used to get the logins for all the users on the current site. Its return value is in array that looks like: [ 'maryann123', 'johnsmith456', 'annie-mcarthur' ]
. If you want WP_User
objects for each of those users though, you can use the get_users()
function and pass in get_super_admins()
as the login__in
argument, like this:
/**
* Get all Super Admin users on the current site.
*
* @return array WP_User objects.
*/
function get_all_superadmin_users() {
return get_users([
'login__in' => get_super_admins()
]);
}
Get Non-Super Admins
If you want to do the opposite and get all non-Super Admins, you can use login__not_in
instead, like this:
/**
* Get all non-Super Admin users on the current site.
*
* @return array WP_User objects.
*/
function get_all_non_superadmin_users() {
return get_users([
'login__not_in' => get_super_admins()
]);
}