Automating parts of a multi-user blog
I manage a "topic blog" for work. For the uninitiated, a "topic blog" has posts from a community of interest on a given topic. Often, topic blogs have lots of contributors. That’s the case for Communicat.us. Managing lots of users requires some tools and some automation.
Today’s tasks included adding 15 new users, sending out the "getting started" guide to everyone, and updating the "authors" page. To make the least work of it all, I added a Dragon Design’s Import Users plug-in for WordPress. That made shore order of adding the 15 new users. But, before I did the upload, I found out how to modify the email that get’s sent for each new user.
WordPress supports "pluggable functions". Fortunately for me, the wp_new_user_notification() function is one of those. Steve Taylor got me started with his basic code for extending the email that gets sent out. Here is what I ended up with …
<?php
/*
Plugin Name: Custom New User Email
Description: Changes the copy in the email sent out to new users
*/
// Redefine user notification function
if ( !function_exists(‘wp_new_user_notification’) ) {
function wp_new_user_notification( $user_id, $plaintext_pass = ” ) {
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$message = "New user registration for " . get_option(‘blogname’) . ":\r\n\r\n";
$message .= "Username: " . $user_login . "\r\n";
$message .= "E-mail: " . $user_email . "\r\n";
@wp_mail(get_option(‘admin_email’), get_option(‘blogname’)." – New User Registration", $message);
if ( empty($plaintext_pass) )
return;
$message .= "\r\n\r\n";
$message .= "To log in:\r\n";
$message .= wp_login_url() . "\r\n";
$message .= "Username: " . $user_login . "\r\n";
$message .= "Password: " . $plaintext_pass . "\r\n\r\n";
$message .= "You will find the \"getting started\" guide at: ".get_option(‘upload_url_path’)."/getting_started.pdf"."\r\n";
wp_mail($user_email, "You have been added to " . get_option(‘blogname’), $message);
}
}
?>
… Feel free to copy this into a file called "new_user_email.php", upload it to your plugins directory and activate it. Don’t forget to also upload your getting_started.pdf to your upload directory and double check you have set the upload path under Administration >> Settings >> Miscellaneous
Everything was working well but then I noticed the automated "Authors" page was full of the new users with no photos, "nice names" or biographies. The page is generated using an "authors.php" file added to the theme. The problem is that is shows all registered authors. What would be better is if it only showed authors who had actually contributed to the blog. So, I set about to some good ol’ trial and error with "SELECT", "COUNT", "WHERE", "GROUP BY", and "ORDER BY" … aka SQL code. Here is a snippet of the final results …
<table border=0>
<?php
// Get the authors from the database ordered by user nicename, but only include those with posts
global $wpdb;
$query = "SELECT wusers.ID as ID, wusers.user_nicename as user_nicename, COUNT(wposts.post_author) as thecount ";
$query .= "FROM $wpdb->users wusers, $wpdb->posts wposts ";
$query .= "WHERE wposts.post_status = ‘publish’ AND wposts.post_type = ‘post’ AND wposts.post_author = wusers.ID ";
$query .= "GROUP BY wusers.ID ORDER BY wusers.user_nicename";
$author_ids = $wpdb->get_results($query);
// Loop through each author
foreach($author_ids as $author) :
// Get user data
$curauth = get_userdata($author->ID);
// If user level is above 0 or login name is not called "admin", display profile
if($curauth->user_level > 0 || $curauth->user_login != ‘admin’) :
?>
<tr><td>
// show the user profile
<?php echo (profilepic_internal_profile($author->ID)); ?>
// show how many posts they have and give a link to posts
<a href="/index.php?author=<?php echo $author->ID; ?>"><i><?php echo "View " . $curauth->first_name . "’s " . $author->thecount . " post(s)"; ?></i></a>
</td></tr>
<?php
endif;
endforeach;
?>
</table>
So, now I can add new users quickly. New users get the same information to start blogging (both some guides on what is a good blog post as well as the tools they can use to write their posts. Once a users starts to contribute, they will automatically appear on the page of authors.
It was all pretty easy. If you manage a multi-user blog, feel free to use these techniques and take the above code.


There are two answers to the question of “what’s the difference between RSS and
What can you do with ATOM and the HTTP operations ? You could write a blog. More important, you could edit a blog. You could search for a list of artists who have recorded a particular song or search for songs that contain a lyric. Then you could select one title and pay for it and get a link to download it. You could have you computer at home automatically publish updates to your friends or co-workers. You might have a little measuring device in your hot water heater or your air conditioner that provides electric usage to the power company. The power company might send new settings to your hot water heater or air condition to make it conserve electricity. A website could get news from the Associated Press news wire, relevant photos from Flickr, clips from searching blogs, and video from CNN and loads it all into an electronic news paper that refreshes every morning just as your coffee pot finishes brewing. This last one is partially here today using
I was reading
I collaborate with a number of like minded groups. Mind you, each group is “like minded” but there is not much overlap between the groups. Within each group, we have common topics of interest but very few common sources of information. Sharing blog entries that are informative or of interest has been relegated to either emailing links or cut/paste links into chat windows. Both of these methods escalates blogs to a higher priority which is precisely what we don’t want to do. Blogs and blog reading is a low priority task that should be set aside for prescribed amounts of time and not serve as an interrupt – but I am way off topic at this point so back to Google Reader and sharing information. Let me pull all the important info together now …

