バッチ処理で出力した HTML ファイルをサイドバーに表示させるためにウィジェットを作成しました。超シンプルでウィジェットの雛形として使えそうだったので置いておきます。

指定した HTML ファイルを表示するウィジェット
管理画面で表示させたい HTML ファイルを指定し、それを表示するだけの簡素なウィジェットです。以下のコードを functions.php に追加します。
add_action( 'widgets_init', function(){
class Widget_Display_HTML_File extends WP_Widget {
function __construct() {
parent::__construct(
'widget_display_html', // ウィジェットのベースID
'Display HTML File', // ウィジェットの名前
array( 'description' => 'Display Specific HTML File' ) // ウィジェットの説明
);
}
/**
* ウィジェット コンテンツの出力
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget.
*/
function widget( $args, $instance ) {
$title = $instance['title'];
$file = $instance['file'];
echo $args['before_widget'];
if ( !empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
$content = file_get_contents( ABSPATH . $file );
if ( $content ) echo $content; else echo '<p>Error: Check your html file or path.</p>';
echo $args['after_widget'];
}
/**
* ウィジェットの設定フォーム(管理画面)
* @param array $instance Current settings.
*/
function form( $instance ){
$title = $instance['title'];
$file = $instance['file'];
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id('file'); ?>">File Path:<br><?php echo ABSPATH; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('file'); ?>" name="<?php echo $this->get_field_name('file'); ?>" type="text" value="<?php echo esc_attr( $file ); ?>">
</p>
<?php
}
/**
* ウィジェットの設定保存(管理画面)
* @param array $new_instance New settings for this instance as input by the user
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
function update( $new_instance, $old_instance ) {
return $new_instance;
}
}
register_widget( 'Widget_Display_HTML_File' );
} );
参考情報
WordPress のデフォルト ウィジェットが参考になると思います。
/wp-includes/default-widgets.php
また、継承元の WP_Widget クラスは以下のファイルで定義されています。
/wp-includes/widgets.php
ウィジェットを自作しようと考える方々には、これくらいのシンプルな情報が丁度いいような気がする。というわけで簡単ですが以上です!