Created
January 26, 2012 18:20
-
-
Save rachelbaker/1684169 to your computer and use it in GitHub Desktop.
WordPress Testimonial Widget - adds custom widget to WordPress Widget Dashboard
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
/** | |
* Creating custom Testimonial Widget Area | |
*/ | |
class Testimonial_Widget extends WP_Widget { | |
function Testimonial_Widget() { | |
$widget_ops = array('classname' => 'testimonial_sidebar_widget', 'description' => 'Custom Testimonial Widget' ); | |
$this->WP_Widget('testimonial_widget', 'Testimonial Widget', $widget_ops); | |
} | |
function widget($args, $instance) { | |
extract($args, EXTR_SKIP); | |
echo $before_widget; | |
$testimonial_content = empty($instance['testimonial_content']) ? ' ' : apply_filters('widget_testimonial_content', $instance['testimonial_content']); | |
$testimonial_source = empty($instance['testimonial_source']) ? ' ' : apply_filters('widget_testimonial_source', $instance['testimonial_source']); | |
echo '<blockquote>'; | |
echo ' <p>' . $testimonial_content . '</p>'; | |
echo ' <p>' . $testimonial_source . '</p>'; | |
echo '</blockquote>'; | |
echo $after_widget; | |
} | |
function update($new_instance, $old_instance) { | |
$instance = $old_instance; | |
$instance['title'] = strip_tags($new_instance['title']); | |
$instance['testimonial_content'] = strip_tags($new_instance['testimonial_content']); | |
$instance['testimonial_source'] = strip_tags($new_instance['testimonial_source']); | |
return $instance; | |
} | |
function form($instance) { | |
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'testimonial_content' => '', 'testimonial_source' => '' ) ); | |
$testimonial_content = strip_tags($instance['testimonial_content']); | |
$testimonial_source = strip_tags($instance['testimonial_source']); | |
?> | |
<p><label for="<?php echo $this->get_field_id('testimonial_content'); ?>">Testimonial Content: <textarea class="widefat" id="<?php echo $this->get_field_id('testimonial_content'); ?>" name="<?php echo $this->get_field_name('testimonial_content'); ?>" type="text" cols="30" rows="4" /><?php echo attribute_escape($testimonial_content); ?></textarea></label></p> | |
<p><label for="<?php echo $this->get_field_id('testimonial_source'); ?>">Testimonial Source: <input class="widefat" id="<?php echo $this->get_field_id('testimonial_source'); ?>" name="<?php echo $this->get_field_name('testimonial_source'); ?>" type="text" value="<?php echo attribute_escape($testimonial_source); ?>" /></label></p> | |
<?php | |
} | |
} | |
register_widget('Testimonial_Widget'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment