Skip to content

Instantly share code, notes, and snippets.

@taiju
Created March 24, 2011 10:02
Show Gist options
  • Save taiju/884827 to your computer and use it in GitHub Desktop.
Save taiju/884827 to your computer and use it in GitHub Desktop.
WP_Widget_Text
<?php
/**
* HTML widget class
*
* WPINC/default-widgets.php内にある
* WP_Widget_Textを使いやすいように改変したもの
*
*/
class WP_Widget_HTML extends WP_Widget {
function WP_Widget_HTML() {
$widget_ops = array('classname' => 'widget_html', 'description' => '入力したHTMLを出力する');
$control_ops = array('width' => 400, 'height' => 350);
$this->WP_Widget('html', __('HTML'), $widget_ops, $control_ops);
}
function widget( $args, $instance ) {
add_filter('widget_html', 'do_shortcode');
extract($args);
$html = apply_filters('widget_html', $instance['html'], $instance );
echo $before_widget;
echo $html;
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
if ( current_user_can('unfiltered_html') )
$instance['html'] = $new_instance['html'];
else
$instance['html'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['html']) ) ); // wp_filter_post_kses() expects slashed
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'html' => '' ) );
$html = format_to_edit($instance['html']);
?>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('html'); ?>" name="<?php echo $this->get_field_name('html'); ?>"><?php echo $html; ?></textarea>
<?php
}
}
register_widget('WP_Widget_HTML');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment