Using WordPress ‘get_super_admins()’ PHP function

The get_super_admins() WordPress PHP function retrieves a list of super admins.

Usage

$super_admins = get_super_admins();

Parameters

  • None

More information

See WordPress Developer Resources: get_super_admins()

Examples

Display a list of super admin users

$super_admins = get_super_admins();
echo __('List of super-admin users:', 'textdomain');
if (!empty($super_admins)) {
    echo '<ul>';
    foreach ($super_admins as $admin) {
        echo '<li>' . $admin . '</li>';
    }
    echo '</ul>';
}

Check if a user is a super admin

$user_login = 'example_user';
$super_admins = get_super_admins();
$is_super_admin = in_array($user_login, $super_admins);

Count the number of super admin users

$super_admins = get_super_admins();
$super_admin_count = count($super_admins);

Send a message to all super admin users

$super_admins = get_super_admins();
$message = 'Hello, this is an important message for super admins.';
foreach ($super_admins as $admin) {
    wp_mail($admin, 'Important Message', $message);
}

Remove a user from the super admin list

$user_login = 'example_user';
$super_admins = get_super_admins();
if (in_array($user_login, $super_admins)) {
    revoke_super_admin($user_login);
}