Created
December 18, 2017 16:34
-
-
Save acodesmith/29863ac8a2b2704af1ca2c7f63c6d1db to your computer and use it in GitHub Desktop.
Filter super admins from WordPress user list for multisite single site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove all super admins from a non-main site user list. | |
**/ | |
filter_super_admins( $args ) { | |
global $wpdb; | |
if ( ! is_main_site() ) { | |
$user_logins = "'" . implode( "', '", get_super_admins() ) . "'"; | |
$prefix = $wpdb->base_prefix; | |
$query = "SELECT ID from `" . $prefix . "users` WHERE user_login IN ( $user_logins )"; | |
$results = $wpdb->get_results( $query ); | |
if ( ! empty( $results ) ) { | |
$user_ids = array_map( function ( $user ) { | |
return $user->ID; | |
}, $results ); | |
$args['exclude'] = $user_ids; | |
} | |
} | |
return $args; | |
} | |
add_filter( 'users_list_table_query_args', 'filter_super_admins' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment