Created
December 20, 2012 01:51
-
-
Save Viper007Bond/4342357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WP_Widget_Text_HTML_In_Title extends WP_Widget { | |
function __construct() { | |
$widget_ops = array( 'classname' => 'widget_text_html_in_title', 'description' => 'Arbitrary text or HTML. Allows HTML in title field.' ); | |
$control_ops = array( 'width' => 400, 'height' => 350 ); | |
parent::__construct( 'text-html-in-title', 'Text (Allows HTML In Title)', $widget_ops, $control_ops ); | |
} | |
function widget( $args, $instance ) { | |
extract($args); | |
$title = empty( $instance['title'] ) ? '' : $instance['title']; | |
$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); | |
echo $before_widget; | |
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> | |
<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> | |
<?php | |
echo $after_widget; | |
} | |
function update( $new_instance, $old_instance ) { | |
$instance = array(); | |
if ( current_user_can('unfiltered_html') ) { | |
$instance['title'] = $new_instance['title']; | |
$instance['text'] = $new_instance['text']; | |
} else { | |
$instance['title'] = wp_kses_post( $new_instance['title'] ); | |
$instance['text'] = wp_kses_post( $new_instance['text'] ); | |
} | |
$instance['filter'] = isset( $new_instance['filter'] ); | |
return $instance; | |
} | |
function form( $instance ) { | |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '', 'filter' => false ) ); | |
?> | |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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( $instance['title'] ); ?>" /></p> | |
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo esc_textarea( $instance['text'] ); ?></textarea> | |
<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p> | |
<?php | |
} | |
} | |
function widget_text_html_in_title_register() { | |
register_widget( 'WP_Widget_Text_HTML_In_Title' ); | |
} | |
add_action( 'widgets_init', 'widget_text_html_in_title_register'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment