Skip to content

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:
    $users = $wpdb->get_results(
    			  "SELECT id, user_email, display_name "
    			. "FROM $wpdb->users "
    			. $additional_sql_filter );
    
  3. Replace that line with the following code:
    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 ) " );
    		}
    

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?”.

Related posts:

  1. New WPMU plugin: Shared Blogroll
  2. New BuddyPress plugin: BuddyPress Group Email Subscription
  3. Adding an “email to members” checkbox to the BuddyPress group activity stream
  4. New BuddyPress plugin: BP Import Blog Activity
  5. Importing Ning users into WP

4 Comments

  1. Score!

    Great work, Kid Gorgeous.

    Posted on 21-Jan-10 at 2:58 am | Permalink
  2. Very nice. Will test and install.

    Posted on 21-Jan-10 at 3:55 am | Permalink
  3. Joseph Ugoretz

    Oh, how totally fantastic! This has been something I’ve really been wanting. Excellent!

    Posted on 21-Jan-10 at 9:52 am | Permalink
  4. Now this is something for me! I will definitely try to use this plugin. Thanks for the instructions!

    Posted on 23-Feb-10 at 9:40 pm | Permalink

+ 4 Tweets

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*