Skip to content

Instantly share code, notes, and snippets.

@todd-uams
Last active November 6, 2019 17:26
Show Gist options
  • Save todd-uams/336235d7e4002cee7855b0e4b2846c47 to your computer and use it in GitHub Desktop.
Save todd-uams/336235d7e4002cee7855b0e4b2846c47 to your computer and use it in GitHub Desktop.
Generate Users List per site for WPMU
function tell_all() {
global $wpdb;
$all_sites = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE archived = FALSE" ); // Hide archived sites
$list = array();
foreach( $all_sites as $site ) {
$args = array(
'blog_id' => $site,
'fields' => 'user_email',
'role' => 'Editor',
);
$url = get_blogaddress_by_id( $site );
$list[$url] = array();
$editors = get_users( $args );
$args['role'] = 'Administrator';
$administrators = get_users( $args );
$users = array_merge( $editors, $administrators );
foreach( $users as $user ) {
$user_info = get_userdata($user);
$user_name = $user_info->display_name;
$user_email = $user_info->user_email;
$user_roles = implode(', ', $user_info->roles);
$user_roles = $user_roles ? '['.$user_roles.']' : '';
$list[$url][$user] = $user_name .", ". $user_email . $user_roles;
}
}
return $list;
}
$list = tell_all();
$sites = array_keys($list);
$i = 1;
echo '<table>';
foreach ($sites as $site) {
echo '<tr>';
echo '<td>'.$i.'</td>';
echo '<td>'.$site.'</td>';
echo '<td>';
foreach($list[$site] as $users){
echo $users.'</br>';
}
echo '<td>';
echo '</tr>';
$i++;
}
echo '</table>';
@todd-uams
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment