Last active
November 6, 2019 17:26
-
-
Save todd-uams/336235d7e4002cee7855b0e4b2846c47 to your computer and use it in GitHub Desktop.
Generate Users List per site for WPMU
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
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>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The user information could include link to email, etc.
Based on https://wordpress.stackexchange.com/questions/101043/generate-a-user-list-per-site-to-communicate-upgrade-plans