WordPress MUのコメントを表示するwidgetのWordPressプラグインを書いてみた

PHPWordPressも全然知らないけど、デフォルトで入ってる、Hello Dollyとrecent commentをコピーして、1時間くらいで書いてみた。キャッシュもしないし、リンクにもなってないくらいヘボヘボだけど、1時間くらいでこんなのが書けるのは面白いですね。
ドキュメントが存在するというのはすばらしいことです。

<?php
/*
Plugin Name: MU recent comment
Plugin URI: http://d.hatena.ne.jp/shrkw/
Description: display recent comment at internal WordPress MU
Version: 0.1
Author: shrkw
Author URI: http://d.hatena.ne.jp/shrkw/
License: GPL
*/

function widget_mu_recent_comments_init() {
	if ( !function_exists('register_sidebar_widget') )
		return;

	function widget_mu_recent_comments($args) {
		global $wpdb, $comments, $comment;
		extract($args, EXTR_SKIP);
		$options = get_option('widget_mu_recent_comments');
		$title = "最近のコメント";

		$wpdb->show_errors();
		$blogs = $wpdb->get_results("SELECT blog_id FROM `mu_db`.wp_blogs ");

		$que = '';
		if ( $blogs ) : foreach ($blogs as $blog) :
				$que .= 'SELECT * FROM `mu_db`.wp_' .$blog->blog_id.'_comments union ';
			endforeach;
			$que = substr($que, 0, -6) . ' order by comment_date desc limit 10';
		endif;
		$mu_comments = $wpdb->get_results($que);
	?>

			<?php echo $before_widget; ?>
				<?php echo $before_title . $title . $after_title; ?>
				<ul id="MU_recentcomments"><?php
				if ( $mu_comments ) : foreach ($mu_comments as $mu_comment) :
				echo  '<li class="recentcomments">' .
				 $mu_comment->comment_content .
				 ' by '. $mu_comment->comment_author .
				 ' at '. date('m/d H:i', strtotime($mu_comment->comment_date)) .
				'</li>';
				endforeach; endif;?></ul>
			<?php echo $after_widget; ?>
	<?php
	}
	register_sidebar_widget('mu_recent_comment', 'widget_mu_recent_comments');
}
add_action('plugins_loaded', 'widget_mu_recent_comments_init');
?>