14 class WP_Widget_Pages extends WP_Widget {
16 function __construct() {
17 $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') );
18 parent::__construct('pages', __('Pages'), $widget_ops);
21 function widget( $args, $instance ) {
24 $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
25 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
26 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
28 if ( $sortby == 'menu_order' )
29 $sortby = 'menu_order, post_title';
31 $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) );
33 if ( !empty( $out ) ) {
36 echo $before_title . $title . $after_title;
46 function update( $new_instance, $old_instance ) {
47 $instance = $old_instance;
48 $instance['title'] = strip_tags($new_instance['title']);
49 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
50 $instance['sortby'] = $new_instance['sortby'];
52 $instance['sortby'] = 'menu_order';
55 $instance['exclude'] = strip_tags( $new_instance['exclude'] );
60 function form( $instance ) {
62 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
63 $title = esc_attr( $instance['title'] );
64 $exclude = esc_attr( $instance['exclude'] );
66 <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 $title; ?>" /></p>
68 <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
69 <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
70 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
71 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
72 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
76 <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
78 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
90 class WP_Widget_Links extends WP_Widget {
92 function __construct() {
93 $widget_ops = array('description' => __( "Your blogroll" ) );
94 parent::__construct('links', __('Links'), $widget_ops);
97 function widget( $args, $instance ) {
98 extract($args, EXTR_SKIP);
100 $show_description = isset($instance['description']) ? $instance['description'] : false;
101 $show_name = isset($instance['name']) ? $instance['name'] : false;
102 $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
103 $show_images = isset($instance['images']) ? $instance['images'] : true;
104 $category = isset($instance['category']) ? $instance['category'] : false;
106 if ( is_admin() && !$category ) {
107 // Display All Links widget as such in the widgets screen
108 echo $before_widget . $before_title . _x('All Links', 'links widget') . $after_title . $after_widget;
112 $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
113 wp_list_bookmarks(apply_filters('widget_links_args', array(
114 'title_before' => $before_title, 'title_after' => $after_title,
115 'category_before' => $before_widget, 'category_after' => $after_widget,
116 'show_images' => $show_images, 'show_description' => $show_description,
117 'show_name' => $show_name, 'show_rating' => $show_rating,
118 'category' => $category, 'class' => 'linkcat widget'
122 function update( $new_instance, $old_instance ) {
123 $new_instance = (array) $new_instance;
124 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
125 foreach ( $instance as $field => $val ) {
126 if ( isset($new_instance[$field]) )
127 $instance[$field] = 1;
129 $instance['category'] = intval($new_instance['category']);
134 function form( $instance ) {
137 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
138 $link_cats = get_terms( 'link_category');
141 <label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
142 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
143 <option value=""><?php _ex('All Links', 'links widget'); ?></option>
145 foreach ( $link_cats as $link_cat ) {
146 echo '<option value="' . intval($link_cat->term_id) . '"'
147 . ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
148 . '>' . $link_cat->name . "</option>\n";
153 <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
154 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
155 <input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
156 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
157 <input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
158 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
159 <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
160 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
167 * Search widget class
171 class WP_Widget_Search extends WP_Widget {
173 function __construct() {
174 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
175 parent::__construct('search', __('Search'), $widget_ops);
178 function widget( $args, $instance ) {
180 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
184 echo $before_title . $title . $after_title;
186 // Use current theme search form if it exists
192 function form( $instance ) {
193 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
194 $title = $instance['title'];
196 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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); ?>" /></label></p>
200 function update( $new_instance, $old_instance ) {
201 $instance = $old_instance;
202 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
203 $instance['title'] = strip_tags($new_instance['title']);
210 * Archives widget class
214 class WP_Widget_Archives extends WP_Widget {
216 function __construct() {
217 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') );
218 parent::__construct('archives', __('Archives'), $widget_ops);
221 function widget( $args, $instance ) {
223 $c = ! empty( $instance['count'] ) ? '1' : '0';
224 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
225 $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
229 echo $before_title . $title . $after_title;
233 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
238 <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
246 function update( $new_instance, $old_instance ) {
247 $instance = $old_instance;
248 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
249 $instance['title'] = strip_tags($new_instance['title']);
250 $instance['count'] = $new_instance['count'] ? 1 : 0;
251 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
256 function form( $instance ) {
257 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
258 $title = strip_tags($instance['title']);
259 $count = $instance['count'] ? 'checked="checked"' : '';
260 $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
262 <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($title); ?>" /></p>
264 <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
266 <input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
275 * Displays log in/out, RSS feed links, etc.
279 class WP_Widget_Meta extends WP_Widget {
281 function __construct() {
282 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
283 parent::__construct('meta', __('Meta'), $widget_ops);
286 function widget( $args, $instance ) {
288 $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
292 echo $before_title . $title . $after_title;
295 <?php wp_register(); ?>
296 <li><?php wp_loginout(); ?></li>
297 <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
298 <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
299 <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
306 function update( $new_instance, $old_instance ) {
307 $instance = $old_instance;
308 $instance['title'] = strip_tags($new_instance['title']);
313 function form( $instance ) {
314 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
315 $title = strip_tags($instance['title']);
317 <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($title); ?>" /></p>
323 * Calendar widget class
327 class WP_Widget_Calendar extends WP_Widget {
329 function __construct() {
330 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts') );
331 parent::__construct('calendar', __('Calendar'), $widget_ops);
334 function widget( $args, $instance ) {
336 $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base);
339 echo $before_title . $title . $after_title;
340 echo '<div id="calendar_wrap">';
346 function update( $new_instance, $old_instance ) {
347 $instance = $old_instance;
348 $instance['title'] = strip_tags($new_instance['title']);
353 function form( $instance ) {
354 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
355 $title = strip_tags($instance['title']);
357 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
358 <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>
368 class WP_Widget_Text extends WP_Widget {
370 function __construct() {
371 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
372 $control_ops = array('width' => 400, 'height' => 350);
373 parent::__construct('text', __('Text'), $widget_ops, $control_ops);
376 function widget( $args, $instance ) {
378 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
379 $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
381 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
382 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
387 function update( $new_instance, $old_instance ) {
388 $instance = $old_instance;
389 $instance['title'] = strip_tags($new_instance['title']);
390 if ( current_user_can('unfiltered_html') )
391 $instance['text'] = $new_instance['text'];
393 $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
394 $instance['filter'] = isset($new_instance['filter']);
398 function form( $instance ) {
399 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
400 $title = strip_tags($instance['title']);
401 $text = esc_textarea($instance['text']);
403 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
404 <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>
406 <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 $text; ?></textarea>
408 <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>
414 * Categories widget class
418 class WP_Widget_Categories extends WP_Widget {
420 function __construct() {
421 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
422 parent::__construct('categories', __('Categories'), $widget_ops);
425 function widget( $args, $instance ) {
428 $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
429 $c = ! empty( $instance['count'] ) ? '1' : '0';
430 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
431 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
435 echo $before_title . $title . $after_title;
437 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
440 $cat_args['show_option_none'] = __('Select Category');
441 wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
444 <script type='text/javascript'>
446 var dropdown = document.getElementById("cat");
447 function onCatChange() {
448 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
449 location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
452 dropdown.onchange = onCatChange;
461 $cat_args['title_li'] = '';
462 wp_list_categories(apply_filters('widget_categories_args', $cat_args));
471 function update( $new_instance, $old_instance ) {
472 $instance = $old_instance;
473 $instance['title'] = strip_tags($new_instance['title']);
474 $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
475 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
476 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
481 function form( $instance ) {
483 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
484 $title = esc_attr( $instance['title'] );
485 $count = isset($instance['count']) ? (bool) $instance['count'] :false;
486 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
487 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
489 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
490 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
492 <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
493 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
495 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
496 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
498 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
499 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
506 * Recent_Posts widget class
510 class WP_Widget_Recent_Posts extends WP_Widget {
512 function __construct() {
513 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
514 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
515 $this->alt_option_name = 'widget_recent_entries';
517 add_action( 'save_post', array(&$this, 'flush_widget_cache') );
518 add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
519 add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
522 function widget($args, $instance) {
523 $cache = wp_cache_get('widget_recent_posts', 'widget');
525 if ( !is_array($cache) )
528 if ( ! isset( $args['widget_id'] ) )
529 $args['widget_id'] = $this->id;
531 if ( isset( $cache[ $args['widget_id'] ] ) ) {
532 echo $cache[ $args['widget_id'] ];
539 $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
540 if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
543 $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
544 if ($r->have_posts()) :
546 <?php echo $before_widget; ?>
547 <?php if ( $title ) echo $before_title . $title . $after_title; ?>
549 <?php while ($r->have_posts()) : $r->the_post(); ?>
550 <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
553 <?php echo $after_widget; ?>
555 // Reset the global $the_post as this query will have stomped on it
560 $cache[$args['widget_id']] = ob_get_flush();
561 wp_cache_set('widget_recent_posts', $cache, 'widget');
564 function update( $new_instance, $old_instance ) {
565 $instance = $old_instance;
566 $instance['title'] = strip_tags($new_instance['title']);
567 $instance['number'] = (int) $new_instance['number'];
568 $this->flush_widget_cache();
570 $alloptions = wp_cache_get( 'alloptions', 'options' );
571 if ( isset($alloptions['widget_recent_entries']) )
572 delete_option('widget_recent_entries');
577 function flush_widget_cache() {
578 wp_cache_delete('widget_recent_posts', 'widget');
581 function form( $instance ) {
582 $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
583 $number = isset($instance['number']) ? absint($instance['number']) : 5;
585 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
586 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
588 <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
589 <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
595 * Recent_Comments widget class
599 class WP_Widget_Recent_Comments extends WP_Widget {
601 function __construct() {
602 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
603 parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
604 $this->alt_option_name = 'widget_recent_comments';
606 if ( is_active_widget(false, false, $this->id_base) )
607 add_action( 'wp_head', array(&$this, 'recent_comments_style') );
609 add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
610 add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
613 function recent_comments_style() {
614 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
615 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
618 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
622 function flush_widget_cache() {
623 wp_cache_delete('widget_recent_comments', 'widget');
626 function widget( $args, $instance ) {
627 global $comments, $comment;
629 $cache = wp_cache_get('widget_recent_comments', 'widget');
631 if ( ! is_array( $cache ) )
634 if ( ! isset( $args['widget_id'] ) )
635 $args['widget_id'] = $this->id;
637 if ( isset( $cache[ $args['widget_id'] ] ) ) {
638 echo $cache[ $args['widget_id'] ];
642 extract($args, EXTR_SKIP);
644 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Recent Comments' ) : $instance['title'], $instance, $this->id_base );
646 if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
649 $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) );
650 $output .= $before_widget;
652 $output .= $before_title . $title . $after_title;
654 $output .= '<ul id="recentcomments">';
656 foreach ( (array) $comments as $comment) {
657 $output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
661 $output .= $after_widget;
664 $cache[$args['widget_id']] = $output;
665 wp_cache_set('widget_recent_comments', $cache, 'widget');
668 function update( $new_instance, $old_instance ) {
669 $instance = $old_instance;
670 $instance['title'] = strip_tags($new_instance['title']);
671 $instance['number'] = absint( $new_instance['number'] );
672 $this->flush_widget_cache();
674 $alloptions = wp_cache_get( 'alloptions', 'options' );
675 if ( isset($alloptions['widget_recent_comments']) )
676 delete_option('widget_recent_comments');
681 function form( $instance ) {
682 $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
683 $number = isset($instance['number']) ? absint($instance['number']) : 5;
685 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
686 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
688 <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
689 <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
699 class WP_Widget_RSS extends WP_Widget {
701 function __construct() {
702 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
703 $control_ops = array( 'width' => 400, 'height' => 200 );
704 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
707 function widget($args, $instance) {
709 if ( isset($instance['error']) && $instance['error'] )
712 extract($args, EXTR_SKIP);
714 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
715 while ( stristr($url, 'http') != $url )
716 $url = substr($url, 1);
721 // self-url destruction sequence
722 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
725 $rss = fetch_feed($url);
726 $title = $instance['title'];
730 if ( ! is_wp_error($rss) ) {
731 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
733 $title = esc_html(strip_tags($rss->get_title()));
734 $link = esc_url(strip_tags($rss->get_permalink()));
735 while ( stristr($link, 'http') != $link )
736 $link = substr($link, 1);
740 $title = empty($desc) ? __('Unknown Feed') : $desc;
742 $title = apply_filters('widget_title', $title, $instance, $this->id_base);
743 $url = esc_url(strip_tags($url));
744 $icon = includes_url('images/rss.png');
746 $title = "<a class='rsswidget' href='$url' title='" . esc_attr__( 'Syndicate this content' ) ."'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
750 echo $before_title . $title . $after_title;
751 wp_widget_rss_output( $rss, $instance );
754 if ( ! is_wp_error($rss) )
759 function update($new_instance, $old_instance) {
760 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
761 return wp_widget_rss_process( $new_instance, $testurl );
764 function form($instance) {
766 if ( empty($instance) )
767 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
768 $instance['number'] = $this->number;
770 wp_widget_rss_form( $instance );
775 * Display the RSS entries in a list.
779 * @param string|array|object $rss RSS url.
780 * @param array $args Widget arguments.
782 function wp_widget_rss_output( $rss, $args = array() ) {
783 if ( is_string( $rss ) ) {
784 $rss = fetch_feed($rss);
785 } elseif ( is_array($rss) && isset($rss['url']) ) {
787 $rss = fetch_feed($rss['url']);
788 } elseif ( !is_object($rss) ) {
792 if ( is_wp_error($rss) ) {
793 if ( is_admin() || current_user_can('manage_options') )
794 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
798 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
799 $args = wp_parse_args( $args, $default_args );
800 extract( $args, EXTR_SKIP );
802 $items = (int) $items;
803 if ( $items < 1 || 20 < $items )
805 $show_summary = (int) $show_summary;
806 $show_author = (int) $show_author;
807 $show_date = (int) $show_date;
809 if ( !$rss->get_item_quantity() ) {
810 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
817 foreach ( $rss->get_items(0, $items) as $item ) {
818 $link = $item->get_link();
819 while ( stristr($link, 'http') != $link )
820 $link = substr($link, 1);
821 $link = esc_url(strip_tags($link));
822 $title = esc_attr(strip_tags($item->get_title()));
824 $title = __('Untitled');
826 $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
827 $desc = wp_html_excerpt( $desc, 360 );
829 // Append ellipsis. Change existing [...] to […].
830 if ( '[...]' == substr( $desc, -5 ) )
831 $desc = substr( $desc, 0, -5 ) . '[…]';
832 elseif ( '[…]' != substr( $desc, -10 ) )
833 $desc .= ' […]';
835 $desc = esc_html( $desc );
837 if ( $show_summary ) {
838 $summary = "<div class='rssSummary'>$desc</div>";
845 $date = $item->get_date( 'U' );
848 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
853 if ( $show_author ) {
854 $author = $item->get_author();
855 if ( is_object($author) ) {
856 $author = $author->get_name();
857 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
862 echo "<li>$title{$date}{$summary}{$author}</li>";
864 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
875 * Display RSS widget options form.
877 * The options for what fields are displayed for the RSS form are all booleans
878 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
883 * @param array|string $args Values for input fields.
884 * @param array $inputs Override default display options.
886 function wp_widget_rss_form( $args, $inputs = null ) {
888 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
889 $inputs = wp_parse_args( $inputs, $default_inputs );
891 extract( $inputs, EXTR_SKIP);
893 $number = esc_attr( $number );
894 $title = esc_attr( $title );
895 $url = esc_url( $url );
896 $items = (int) $items;
897 if ( $items < 1 || 20 < $items )
899 $show_summary = (int) $show_summary;
900 $show_author = (int) $show_author;
901 $show_date = (int) $show_date;
903 if ( !empty($error) )
904 echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
906 if ( $inputs['url'] ) :
908 <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
909 <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
910 <?php endif; if ( $inputs['title'] ) : ?>
911 <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
912 <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
913 <?php endif; if ( $inputs['items'] ) : ?>
914 <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
915 <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
917 for ( $i = 1; $i <= 20; ++$i )
918 echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
921 <?php endif; if ( $inputs['show_summary'] ) : ?>
922 <p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
923 <label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
924 <?php endif; if ( $inputs['show_author'] ) : ?>
925 <p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
926 <label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
927 <?php endif; if ( $inputs['show_date'] ) : ?>
928 <p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
929 <label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
932 foreach ( array_keys($default_inputs) as $input ) :
933 if ( 'hidden' === $inputs[$input] ) :
934 $id = str_replace( '_', '-', $input );
936 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
943 * Process RSS feed widget data and optionally retrieve feed items.
945 * The feed widget can not have more than 20 items or it will reset back to the
946 * default, which is 10.
948 * The resulting array has the feed title, feed url, feed link (from channel),
949 * feed items, error (if any), and whether to show summary, author, and date.
950 * All respectively in the order of the array elements.
954 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
955 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
958 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
959 $items = (int) $widget_rss['items'];
960 if ( $items < 1 || 20 < $items )
962 $url = esc_url_raw(strip_tags( $widget_rss['url'] ));
963 $title = trim(strip_tags( $widget_rss['title'] ));
964 $show_summary = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
965 $show_author = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
966 $show_date = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;
969 $rss = fetch_feed($url);
972 if ( is_wp_error($rss) ) {
973 $error = $rss->get_error_message();
975 $link = esc_url(strip_tags($rss->get_permalink()));
976 while ( stristr($link, 'http') != $link )
977 $link = substr($link, 1);
984 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
988 * Tag cloud widget class
992 class WP_Widget_Tag_Cloud extends WP_Widget {
994 function __construct() {
995 $widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
996 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
999 function widget( $args, $instance ) {
1001 $current_taxonomy = $this->_get_current_taxonomy($instance);
1002 if ( !empty($instance['title']) ) {
1003 $title = $instance['title'];
1005 if ( 'post_tag' == $current_taxonomy ) {
1006 $title = __('Tags');
1008 $tax = get_taxonomy($current_taxonomy);
1009 $title = $tax->labels->name;
1012 $title = apply_filters('widget_title', $title, $instance, $this->id_base);
1014 echo $before_widget;
1016 echo $before_title . $title . $after_title;
1017 echo '<div class="tagcloud">';
1018 wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
1023 function update( $new_instance, $old_instance ) {
1024 $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1025 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
1029 function form( $instance ) {
1030 $current_taxonomy = $this->_get_current_taxonomy($instance);
1032 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1033 <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
1034 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
1035 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
1036 <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
1037 $tax = get_taxonomy($taxonomy);
1038 if ( !$tax->show_tagcloud || empty($tax->labels->name) )
1041 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
1042 <?php endforeach; ?>
1046 function _get_current_taxonomy($instance) {
1047 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1048 return $instance['taxonomy'];
1055 * Navigation Menu widget class
1059 class WP_Nav_Menu_Widget extends WP_Widget {
1061 function __construct() {
1062 $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
1063 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1066 function widget($args, $instance) {
1068 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
1073 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
1075 echo $args['before_widget'];
1077 if ( !empty($instance['title']) )
1078 echo $args['before_title'] . $instance['title'] . $args['after_title'];
1080 wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
1082 echo $args['after_widget'];
1085 function update( $new_instance, $old_instance ) {
1086 $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
1087 $instance['nav_menu'] = (int) $new_instance['nav_menu'];
1091 function form( $instance ) {
1092 $title = isset( $instance['title'] ) ? $instance['title'] : '';
1093 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1096 $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
1098 // If no menus exists, direct the user to go and create some.
1100 echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
1105 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1106 <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
1109 <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
1110 <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
1112 foreach ( $menus as $menu ) {
1113 $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
1114 echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
1124 * Register all of the default WordPress widgets on startup.
1126 * Calls 'widgets_init' action after all of the WordPress widgets have been
1131 function wp_widgets_init() {
1132 if ( !is_blog_installed() )
1135 register_widget('WP_Widget_Pages');
1137 register_widget('WP_Widget_Calendar');
1139 register_widget('WP_Widget_Archives');
1141 register_widget('WP_Widget_Links');
1143 register_widget('WP_Widget_Meta');
1145 register_widget('WP_Widget_Search');
1147 register_widget('WP_Widget_Text');
1149 register_widget('WP_Widget_Categories');
1151 register_widget('WP_Widget_Recent_Posts');
1153 register_widget('WP_Widget_Recent_Comments');
1155 register_widget('WP_Widget_RSS');
1157 register_widget('WP_Widget_Tag_Cloud');
1159 register_widget('WP_Nav_Menu_Widget');
1161 do_action('widgets_init');
1164 add_action('init', 'wp_widgets_init', 1);