The granted_super_admin WordPress PHP action fires after a user is granted Super Admin privileges.
Super admin privileges allow users to access and manage all sites and features on a WordPress multisite network.
Usage
add_action('granted_super_admin', 'your_custom_function', 10, 1); function your_custom_function($user_id) { // your custom code here }
Parameters
$user_id
(int): ID of the user that was granted Super Admin privileges.
More information
See WordPress Developer Resources: granted_super_admin
Examples
Send a welcome email to new Super Admins
Send a welcome email to the user after they are granted Super Admin privileges.
add_action('granted_super_admin', 'send_welcome_email_to_super_admin', 10, 1); function send_welcome_email_to_super_admin($user_id) { $user_info = get_userdata($user_id); $email_subject = 'Welcome to Super Admin Role'; $email_body = 'Congratulations! You have been granted Super Admin privileges.'; wp_mail($user_info->user_email, $email_subject, $email_body); }
Log Super Admin promotions
Log when a user is promoted to Super Admin in a custom log file.
add_action('granted_super_admin', 'log_super_admin_promotion', 10, 1); function log_super_admin_promotion($user_id) { $user_info = get_userdata($user_id); $log_message = sprintf('User %s (ID: %d) was promoted to Super Admin.', $user_info->user_login, $user_id); error_log($log_message, 3, '/path/to/your/custom/log/file.log'); }
Notify other Super Admins of new Super Admin
Send an email notification to all existing Super Admins when a new user is granted Super Admin privileges.
add_action('granted_super_admin', 'notify_super_admins_of_new_super_admin', 10, 1); function notify_super_admins_of_new_super_admin($user_id) { $new_super_admin = get_userdata($user_id); $super_admins = get_super_admins(); foreach ($super_admins as $admin) { $admin_info = get_user_by('login', $admin); if ($admin_info->ID !== $user_id) { $email_subject = 'New Super Admin Added'; $email_body = sprintf('User %s (ID: %d) has been granted Super Admin privileges.', $new_super_admin->user_login, $user_id); wp_mail($admin_info->user_email, $email_subject, $email_body); } } }
Add a custom role to new Super Admins
Assign a custom role to the user when they are granted Super Admin privileges.
add_action('granted_super_admin', 'add_custom_role_to_super_admin', 10, 1); function add_custom_role_to_super_admin($user_id) { $user = new WP_User($user_id); $user->add_role('your_custom_role'); }
Remove specific capabilities from new Super Admins
Remove certain capabilities from a user when they are granted Super Admin privileges.
add_action('granted_super_admin', 'remove_capabilities_from_super_admin', 10, 1); function remove_capabilities_from_super_admin($user_id) { $user = new WP_User($user_id); $user->remove_cap('some_capability'); $user->remove_cap('another_capability'); }