Get All Super Admin Users in WordPress

January 07, 2019

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:

<?php
/**
* 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:

<?php
/**
* 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()
]);
}


Kellen Mace

Written by Kellen Mace, who lives in Rochester Hills, MI and builds cool stuff on the web. About Kellen // Follow him on Twitter →