<?php
/*
Plugin Name: PJW WP Filter Manage Posts
Plugin URI: http://blog.ftwr.co.uk/wordpress/
Description: Enables you to manage posts by author and other such goodies.
Author: Peter Westwood
Version: 0.11
Author URI: http://blog.ftwr.co.uk/
*/

/*  Copyright 2006  Peter Westwood  (email : peter.westwood@ftwr.co.uk)

    This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

function pjw_wp_filter_manage_posts_by_author() {
	global $wpdb;
	$user_result = $wpdb->get_results("SELECT DISTINCT post_author AS user_ID FROM $wpdb->posts WHERE post_type = 'post'");

	if ( count($user_result) > 1 ) { ?>

				<select name='author'>
				<option value=''><?php _e('All authors') ?></option>
				<?php
				foreach ($user_result as $user_row) {

					if( isset($_GET['author']) && $user_row->user_ID == (int) $_GET['author'] )
						$default = 'selected="selected"';
					else
						$default = null;

					echo "<option $default value='$user_row->user_ID'>";
					$user = get_userdata($user_row->user_ID);
					echo $user->display_name;
					echo "</option>\n";
				}
				?>
				</select>
<?php
	} 
}

add_action('restrict_manage_posts', 'pjw_wp_filter_manage_posts_by_author');
