Skip to content

Instantly share code, notes, and snippets.

@acodesmith
Created December 18, 2017 16:34
Show Gist options
  • Save acodesmith/29863ac8a2b2704af1ca2c7f63c6d1db to your computer and use it in GitHub Desktop.
Save acodesmith/29863ac8a2b2704af1ca2c7f63c6d1db to your computer and use it in GitHub Desktop.
Filter super admins from WordPress user list for multisite single site.
<?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