Blog-specific email plugin for WPMU users

A quick WPMU hack that I think will help a lot of people using an installation of WPMU for multiple classes.

The plugin Email Users by Vincent Prat allows blog authors/admins to email users in two different ways: 1) by emailing a group of users (such as those corresponding a particular role on your blog), or 2) by emailing individual users. The problem, though, is that this second option brings up a list of every single user on the installation of WPMU. This can be a bit of a pain for the normal blog user, as teachers or students in a class would probably only want to see a list of those people who are in the class, or on the blog.

Here’s a hack that will make the Email Users plugin show list only the members of the current blog for everyone except for the site admin:

  1. In the main plugin file (email-users.php), find the function mailusers_get_users. It should start around line 404.
  2. Look for the lines of code (414-417 in my version) that define the variable $users in the first conditional clause:
    [code language=”php”]
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . $additional_sql_filter );
    [/code]
  3. Replace that line with the following code:
    [code language=”php”]
    if ( is_site_admin() ) {
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . $additional_sql_filter );
    } else {
    $wp_user_search = new WP_User_Search(”, ”, ”);
    $user_list = $wp_user_search->get_results();
    $user_array = join(‘,’, $user_list);
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . “WHERE id IN ( $user_array ) ” );
    }
    [/code]

Here’s the use case I envision. The instructor for a class places the Add User Sidebar Widget (by my boys at UBC’s OLT!) in the sidebar of his or her blog. As part of the first assignment of the semester, the instructor asks each student to register for an account, and click the “Add Me” button on the instructor’s blog. That will automatically populate the email list above.

File this tip under “who needs Blackboard?”.

5 thoughts on “Blog-specific email plugin for WPMU users

  1. Luke

    Couple of notes… is_site_admin is depecrated; use is_super_admin instead. And, on the email users page I only seem to be getting 50 users, though I *believe* the emails are going out to all. Will have time to do more testing later this week… has anyone seen this 50 user thing before, though?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *