Generate a user list per site to communicate upgrade plans

My team has inherited a large WordPress Networks install. Updates need to be run and we need to communicate this to our editors and administrators. My system admin has asked me for a list of URLs and email address matched to those URLs. We plan to contact them site-by-site to manage a system wide upgrade.

What would be an efficient way to go about this?

I can get a list of emails from the wp_users table. Is there a tool that does this already (and properly)?

Most importantly: How can I group these users to their individual WP sites in the Networks install?

In other words, how might I get a report like this from within the WP-Admin? My client would like to use a plug-in if possible to produce this report inside of the admin interface.

site one
- smellyPete
- bilboBaggins989 
site two
- sallysue997
- billyBob

etc, etc

6 Answers
6

This should do the trick. Read along with the comments for some explanation.

// get users with specified roles -- this can go in functions
function get_users_with_role( $roles ) {
    global $wpdb;
    if ( ! is_array( $roles ) )
        $roles = array_walk( explode( ",", $roles ), 'trim' );
    $sql="
        SELECT  ID 
        FROM        " . $wpdb->users . ' INNER JOIN ' . $wpdb->usermeta . '
        ON          ' . $wpdb->users . '.ID             =       ' . $wpdb->usermeta . '.user_id
        WHERE       ' . $wpdb->usermeta . '.meta_key        =       \'' . $wpdb->prefix . 'capabilities\'
        AND     (
    ';
    $i = 1;
    foreach ( $roles as $role ) {
        $sql .= ' ' . $wpdb->usermeta . '.meta_value    LIKE    \'%"' . $role . '"%\' ';
        if ( $i < count( $roles ) ) $sql .= ' OR ';
        $i++;
    }
    $sql .= ' ) ';
    $sql .= ' ORDER BY display_name ';
    $userIDs = $wpdb->get_col( $sql );
    return $userIDs;
}

////// everything else could go in a custom page template just for viewing temporarily.

// poll database for users we need, using custom function (listed above)
$editors_and_admins = get_users_with_role(array('editor', 'administrator'));

// get user objects
$editors_and_admins = get_users(array('include' => $editors_and_admins);

echo '<table>';
// spit out as table - not sure what output you need. could easily create CSV by modifying this
foreach($editors_and_admins as $constituent){
    echo '<tr>'
    // get name
    echo '<td>'.get_the_author_meta('first_name', $constituent->ID).' '.get_the_author_meta('last_name', $constituent->ID).'</td>';
    // get email
    echo '<td><a href="https://wordpress.stackexchange.com/questions/101043/mailto:".$constituent->user_email'">'.$constituent->user_email.'</a></td>';
    // get URL
    echo '<td><a href="'.$constituent->user_url.'">'.$constituent->user_url.'</a></td>';
    echo '</tr>';
}
echo '</table>';

Leave a Comment