get_super_admins: get the super admin usernames in WordPress
The get_super_admins
function in WordPress retrieves a list of usernames that have super admin privileges. Super admins have the highest level of access in a WordPress Multisite network, allowing them to manage network-wide settings and perform actions that affect all sites within the network.
This function can be useful for network administrators who need to identify which users have super admin capabilities. It provides a straightforward way to obtain this information, which can be used for administrative tasks, auditing, or security purposes. The returned list is an array of usernames, making it easy to process or display as needed.
Parameters
The get_super_admins
function does not accept any parameters.
Return Value
The function returns a list of super admin logins as an array of strings.
Examples
How to Retrieve and Display Super Admins
$super_admins = get_super_admins();
echo '<ul>';
foreach ($super_admins as $admin) {
echo '<li>' . esc_html($admin) . '</li>';
}
echo '</ul>';
This snippet retrieves the list of super admin logins using the get_super_admins
function and displays each super admin in an unordered list. The esc_html
function is used to ensure that the output is properly escaped for HTML.
How to Get the Number of Super Admins
$super_admins = get_super_admins();
$super_admin_count = count($super_admins);
echo '<p>There are ' . esc_html($super_admin_count) . ' super admins.</p>';
This snippet retrieves the list of super admin logins using the get_super_admins
function and then counts the number of super admins using the count
function. It outputs the total number of super admins in a paragraph.
Conclusion
The get_super_admins
function in WordPress provides a straightforward method to retrieve a list of all users who have super admin privileges within a multisite network. This function returns an array of usernames, allowing developers to easily identify and work with super administrators. It can be particularly useful for tasks such as network-wide administrative notifications, custom access controls, or any other scenario where distinguishing super admins from other users is necessary. By utilizing get_super_admins
, developers can effectively manage and leverage the capabilities of super administrators across their WordPress multisite installations.