サイドバーで使うようなプラグインで、ウィジェットがなく関数のみが提供されているものは、自分でウィジェット化しておくと、管理画面から取り外し出来るので便利です。
関数をラップするだけだったら、ほとんど Widgets API « WordPress Codex のサンプルそのままで、ウィジェット名とウィジェットの出力部分を変更するだけです。
ということで、関数だけでウィジェットがない Compact Archives プラグインをウィジェットにしてみます。コード中のcompact_archive('numeric'); は、Compact Archives 提供のの関数です。
テーマの functions.php
class MyCompactArchive extends WP_Widget {
function MyCompactArchive() {
parent::WP_Widget(false, $name = 'MyCompactArchive');
}
function form($instance) {
$title = esc_attr($instance['title']);
echo '<p>';
echo '<label for="' . $this->get_field_id('title') . '">' . _e('Title:');
echo '<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
echo '<ul class="compact-archives-widget">';
compact_archive('numeric');
echo '</ul>';
echo $after_widget;
}
}
add_action('widgets_init', create_function('', 'return register_widget("MyCompactArchive");'));