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;
105 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
106 $order = $orderby == 'rating' ? 'DESC' : 'ASC';
107 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
109 $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
110 wp_list_bookmarks(apply_filters('widget_links_args', array(
111 'title_before' => $before_title, 'title_after' => $after_title,
112 'category_before' => $before_widget, 'category_after' => $after_widget,
113 'show_images' => $show_images, 'show_description' => $show_description,
114 'show_name' => $show_name, 'show_rating' => $show_rating,
115 'category' => $category, 'class' => 'linkcat widget',
116 'orderby' => $orderby, 'order' => $order,
121 function update( $new_instance, $old_instance ) {
122 $new_instance = (array) $new_instance;
123 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
124 foreach ( $instance as $field => $val ) {
125 if ( isset($new_instance[$field]) )
126 $instance[$field] = 1;
129 $instance['orderby'] = 'name';
130 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
131 $instance['orderby'] = $new_instance['orderby'];
133 $instance['category'] = intval( $new_instance['category'] );
134 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
139 function form( $instance ) {
142 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
143 $link_cats = get_terms( 'link_category' );
144 if ( ! $limit = intval( $instance['limit'] ) )
148 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
149 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
150 <option value=""><?php _ex('All Links', 'links widget'); ?></option>
152 foreach ( $link_cats as $link_cat ) {
153 echo '<option value="' . intval( $link_cat->term_id ) . '"'
154 . selected( $instance['category'], $link_cat->term_id, false )
155 . '>' . $link_cat->name . "</option>\n";
159 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
160 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
161 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
162 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
163 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
164 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>
168 <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'); ?>" />
169 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
170 <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'); ?>" />
171 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
172 <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'); ?>" />
173 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
174 <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'); ?>" />
175 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
178 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
179 <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
186 * Search widget class
190 class WP_Widget_Search extends WP_Widget {
192 function __construct() {
193 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
194 parent::__construct('search', __('Search'), $widget_ops);
197 function widget( $args, $instance ) {
199 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
203 echo $before_title . $title . $after_title;
205 // Use current theme search form if it exists
211 function form( $instance ) {
212 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
213 $title = $instance['title'];
215 <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>
219 function update( $new_instance, $old_instance ) {
220 $instance = $old_instance;
221 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
222 $instance['title'] = strip_tags($new_instance['title']);
229 * Archives widget class
233 class WP_Widget_Archives extends WP_Widget {
235 function __construct() {
236 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') );
237 parent::__construct('archives', __('Archives'), $widget_ops);
240 function widget( $args, $instance ) {
242 $c = ! empty( $instance['count'] ) ? '1' : '0';
243 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
244 $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
248 echo $before_title . $title . $after_title;
252 <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>
257 <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
265 function update( $new_instance, $old_instance ) {
266 $instance = $old_instance;
267 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
268 $instance['title'] = strip_tags($new_instance['title']);
269 $instance['count'] = $new_instance['count'] ? 1 : 0;
270 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
275 function form( $instance ) {
276 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
277 $title = strip_tags($instance['title']);
278 $count = $instance['count'] ? 'checked="checked"' : '';
279 $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
281 <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>
283 <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>
285 <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>
294 * Displays log in/out, RSS feed links, etc.
298 class WP_Widget_Meta extends WP_Widget {
300 function __construct() {
301 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
302 parent::__construct('meta', __('Meta'), $widget_ops);
305 function widget( $args, $instance ) {
307 $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
311 echo $before_title . $title . $after_title;
314 <?php wp_register(); ?>
315 <li><?php wp_loginout(); ?></li>
316 <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>
317 <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>
318 <?php echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
319 esc_url( __( 'http://wordpress.org/' ) ),
320 esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
321 _x( 'WordPress.org', 'meta widget link text' )
329 function update( $new_instance, $old_instance ) {
330 $instance = $old_instance;
331 $instance['title'] = strip_tags($new_instance['title']);
336 function form( $instance ) {
337 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
338 $title = strip_tags($instance['title']);
340 <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>
346 * Calendar widget class
350 class WP_Widget_Calendar extends WP_Widget {
352 function __construct() {
353 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts') );
354 parent::__construct('calendar', __('Calendar'), $widget_ops);
357 function widget( $args, $instance ) {
359 $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
362 echo $before_title . $title . $after_title;
363 echo '<div id="calendar_wrap">';
369 function update( $new_instance, $old_instance ) {
370 $instance = $old_instance;
371 $instance['title'] = strip_tags($new_instance['title']);
376 function form( $instance ) {
377 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
378 $title = strip_tags($instance['title']);
380 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
381 <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>
391 class WP_Widget_Text extends WP_Widget {
393 function __construct() {
394 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
395 $control_ops = array('width' => 400, 'height' => 350);
396 parent::__construct('text', __('Text'), $widget_ops, $control_ops);
399 function widget( $args, $instance ) {
401 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
402 $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
404 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
405 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
410 function update( $new_instance, $old_instance ) {
411 $instance = $old_instance;
412 $instance['title'] = strip_tags($new_instance['title']);
413 if ( current_user_can('unfiltered_html') )
414 $instance['text'] = $new_instance['text'];
416 $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
417 $instance['filter'] = isset($new_instance['filter']);
421 function form( $instance ) {
422 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
423 $title = strip_tags($instance['title']);
424 $text = esc_textarea($instance['text']);
426 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
427 <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>
429 <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>
431 <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>
437 * Categories widget class
441 class WP_Widget_Categories extends WP_Widget {
443 function __construct() {
444 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
445 parent::__construct('categories', __('Categories'), $widget_ops);
448 function widget( $args, $instance ) {
451 $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
452 $c = ! empty( $instance['count'] ) ? '1' : '0';
453 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
454 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
458 echo $before_title . $title . $after_title;
460 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
463 $cat_args['show_option_none'] = __('Select Category');
464 wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
467 <script type='text/javascript'>
469 var dropdown = document.getElementById("cat");
470 function onCatChange() {
471 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
472 location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
475 dropdown.onchange = onCatChange;
484 $cat_args['title_li'] = '';
485 wp_list_categories(apply_filters('widget_categories_args', $cat_args));
494 function update( $new_instance, $old_instance ) {
495 $instance = $old_instance;
496 $instance['title'] = strip_tags($new_instance['title']);
497 $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
498 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
499 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
504 function form( $instance ) {
506 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
507 $title = esc_attr( $instance['title'] );
508 $count = isset($instance['count']) ? (bool) $instance['count'] :false;
509 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
510 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
512 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
513 <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>
515 <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 ); ?> />
516 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
518 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
519 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
521 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
522 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
529 * Recent_Posts widget class
533 class WP_Widget_Recent_Posts extends WP_Widget {
535 function __construct() {
536 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
537 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
538 $this->alt_option_name = 'widget_recent_entries';
540 add_action( 'save_post', array($this, 'flush_widget_cache') );
541 add_action( 'deleted_post', array($this, 'flush_widget_cache') );
542 add_action( 'switch_theme', array($this, 'flush_widget_cache') );
545 function widget($args, $instance) {
546 $cache = wp_cache_get('widget_recent_posts', 'widget');
548 if ( !is_array($cache) )
551 if ( ! isset( $args['widget_id'] ) )
552 $args['widget_id'] = $this->id;
554 if ( isset( $cache[ $args['widget_id'] ] ) ) {
555 echo $cache[ $args['widget_id'] ];
562 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
563 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
564 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 10;
567 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
569 $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
570 if ($r->have_posts()) :
572 <?php echo $before_widget; ?>
573 <?php if ( $title ) echo $before_title . $title . $after_title; ?>
575 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
577 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
578 <?php if ( $show_date ) : ?>
579 <span class="post-date"><?php echo get_the_date(); ?></span>
584 <?php echo $after_widget; ?>
586 // Reset the global $the_post as this query will have stomped on it
591 $cache[$args['widget_id']] = ob_get_flush();
592 wp_cache_set('widget_recent_posts', $cache, 'widget');
595 function update( $new_instance, $old_instance ) {
596 $instance = $old_instance;
597 $instance['title'] = strip_tags($new_instance['title']);
598 $instance['number'] = (int) $new_instance['number'];
599 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
600 $this->flush_widget_cache();
602 $alloptions = wp_cache_get( 'alloptions', 'options' );
603 if ( isset($alloptions['widget_recent_entries']) )
604 delete_option('widget_recent_entries');
609 function flush_widget_cache() {
610 wp_cache_delete('widget_recent_posts', 'widget');
613 function form( $instance ) {
614 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
615 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
616 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
618 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
619 <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>
621 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
622 <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>
624 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
625 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
631 * Recent_Comments widget class
635 class WP_Widget_Recent_Comments extends WP_Widget {
637 function __construct() {
638 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
639 parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
640 $this->alt_option_name = 'widget_recent_comments';
642 if ( is_active_widget(false, false, $this->id_base) )
643 add_action( 'wp_head', array($this, 'recent_comments_style') );
645 add_action( 'comment_post', array($this, 'flush_widget_cache') );
646 add_action( 'edit_comment', array($this, 'flush_widget_cache') );
647 add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
650 function recent_comments_style() {
651 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
652 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
655 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
659 function flush_widget_cache() {
660 wp_cache_delete('widget_recent_comments', 'widget');
663 function widget( $args, $instance ) {
664 global $comments, $comment;
666 $cache = wp_cache_get('widget_recent_comments', 'widget');
668 if ( ! is_array( $cache ) )
671 if ( ! isset( $args['widget_id'] ) )
672 $args['widget_id'] = $this->id;
674 if ( isset( $cache[ $args['widget_id'] ] ) ) {
675 echo $cache[ $args['widget_id'] ];
679 extract($args, EXTR_SKIP);
682 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
683 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
684 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
688 $comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
689 $output .= $before_widget;
691 $output .= $before_title . $title . $after_title;
693 $output .= '<ul id="recentcomments">';
695 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
696 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
697 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
699 foreach ( (array) $comments as $comment) {
700 $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>';
704 $output .= $after_widget;
707 $cache[$args['widget_id']] = $output;
708 wp_cache_set('widget_recent_comments', $cache, 'widget');
711 function update( $new_instance, $old_instance ) {
712 $instance = $old_instance;
713 $instance['title'] = strip_tags($new_instance['title']);
714 $instance['number'] = absint( $new_instance['number'] );
715 $this->flush_widget_cache();
717 $alloptions = wp_cache_get( 'alloptions', 'options' );
718 if ( isset($alloptions['widget_recent_comments']) )
719 delete_option('widget_recent_comments');
724 function form( $instance ) {
725 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
726 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
728 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
729 <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>
731 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
732 <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>
742 class WP_Widget_RSS extends WP_Widget {
744 function __construct() {
745 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
746 $control_ops = array( 'width' => 400, 'height' => 200 );
747 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
750 function widget($args, $instance) {
752 if ( isset($instance['error']) && $instance['error'] )
755 extract($args, EXTR_SKIP);
757 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
758 while ( stristr($url, 'http') != $url )
759 $url = substr($url, 1);
764 // self-url destruction sequence
765 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
768 $rss = fetch_feed($url);
769 $title = $instance['title'];
773 if ( ! is_wp_error($rss) ) {
774 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
776 $title = esc_html(strip_tags($rss->get_title()));
777 $link = esc_url(strip_tags($rss->get_permalink()));
778 while ( stristr($link, 'http') != $link )
779 $link = substr($link, 1);
783 $title = empty($desc) ? __('Unknown Feed') : $desc;
785 $title = apply_filters('widget_title', $title, $instance, $this->id_base);
786 $url = esc_url(strip_tags($url));
787 $icon = includes_url('images/rss.png');
789 $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>";
793 echo $before_title . $title . $after_title;
794 wp_widget_rss_output( $rss, $instance );
797 if ( ! is_wp_error($rss) )
802 function update($new_instance, $old_instance) {
803 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
804 return wp_widget_rss_process( $new_instance, $testurl );
807 function form($instance) {
809 if ( empty($instance) )
810 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
811 $instance['number'] = $this->number;
813 wp_widget_rss_form( $instance );
818 * Display the RSS entries in a list.
822 * @param string|array|object $rss RSS url.
823 * @param array $args Widget arguments.
825 function wp_widget_rss_output( $rss, $args = array() ) {
826 if ( is_string( $rss ) ) {
827 $rss = fetch_feed($rss);
828 } elseif ( is_array($rss) && isset($rss['url']) ) {
830 $rss = fetch_feed($rss['url']);
831 } elseif ( !is_object($rss) ) {
835 if ( is_wp_error($rss) ) {
836 if ( is_admin() || current_user_can('manage_options') )
837 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
841 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
842 $args = wp_parse_args( $args, $default_args );
843 extract( $args, EXTR_SKIP );
845 $items = (int) $items;
846 if ( $items < 1 || 20 < $items )
848 $show_summary = (int) $show_summary;
849 $show_author = (int) $show_author;
850 $show_date = (int) $show_date;
852 if ( !$rss->get_item_quantity() ) {
853 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
860 foreach ( $rss->get_items(0, $items) as $item ) {
861 $link = $item->get_link();
862 while ( stristr($link, 'http') != $link )
863 $link = substr($link, 1);
864 $link = esc_url(strip_tags($link));
865 $title = esc_attr(strip_tags($item->get_title()));
867 $title = __('Untitled');
869 $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
870 $excerpt = wp_html_excerpt( $desc, 360 );
872 // Append ellipsis. Change existing [...] to […].
873 if ( '[...]' == substr( $excerpt, -5 ) )
874 $excerpt = substr( $excerpt, 0, -5 ) . '[…]';
875 elseif ( '[…]' != substr( $excerpt, -10 ) && $desc != $excerpt )
876 $excerpt .= ' […]';
878 $excerpt = esc_html( $excerpt );
880 if ( $show_summary ) {
881 $summary = "<div class='rssSummary'>$excerpt</div>";
888 $date = $item->get_date( 'U' );
891 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
896 if ( $show_author ) {
897 $author = $item->get_author();
898 if ( is_object($author) ) {
899 $author = $author->get_name();
900 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
905 echo "<li>$title{$date}{$summary}{$author}</li>";
907 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
916 * Display RSS widget options form.
918 * The options for what fields are displayed for the RSS form are all booleans
919 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
924 * @param array|string $args Values for input fields.
925 * @param array $inputs Override default display options.
927 function wp_widget_rss_form( $args, $inputs = null ) {
929 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
930 $inputs = wp_parse_args( $inputs, $default_inputs );
932 extract( $inputs, EXTR_SKIP );
934 $number = esc_attr( $number );
935 $title = esc_attr( $title );
936 $url = esc_url( $url );
937 $items = (int) $items;
938 if ( $items < 1 || 20 < $items )
940 $show_summary = (int) $show_summary;
941 $show_author = (int) $show_author;
942 $show_date = (int) $show_date;
944 if ( !empty($error) )
945 echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
947 if ( $inputs['url'] ) :
949 <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
950 <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
951 <?php endif; if ( $inputs['title'] ) : ?>
952 <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
953 <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
954 <?php endif; if ( $inputs['items'] ) : ?>
955 <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
956 <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
958 for ( $i = 1; $i <= 20; ++$i )
959 echo "<option value='$i' " . selected( $items, $i, false ) . ">$i</option>";
962 <?php endif; if ( $inputs['show_summary'] ) : ?>
963 <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"'; ?>/>
964 <label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
965 <?php endif; if ( $inputs['show_author'] ) : ?>
966 <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"'; ?>/>
967 <label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
968 <?php endif; if ( $inputs['show_date'] ) : ?>
969 <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"'; ?>/>
970 <label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
973 foreach ( array_keys($default_inputs) as $input ) :
974 if ( 'hidden' === $inputs[$input] ) :
975 $id = str_replace( '_', '-', $input );
977 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
984 * Process RSS feed widget data and optionally retrieve feed items.
986 * The feed widget can not have more than 20 items or it will reset back to the
987 * default, which is 10.
989 * The resulting array has the feed title, feed url, feed link (from channel),
990 * feed items, error (if any), and whether to show summary, author, and date.
991 * All respectively in the order of the array elements.
995 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
996 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
999 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
1000 $items = (int) $widget_rss['items'];
1001 if ( $items < 1 || 20 < $items )
1003 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
1004 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
1005 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
1006 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
1007 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
1009 if ( $check_feed ) {
1010 $rss = fetch_feed($url);
1013 if ( is_wp_error($rss) ) {
1014 $error = $rss->get_error_message();
1016 $link = esc_url(strip_tags($rss->get_permalink()));
1017 while ( stristr($link, 'http') != $link )
1018 $link = substr($link, 1);
1025 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
1029 * Tag cloud widget class
1033 class WP_Widget_Tag_Cloud extends WP_Widget {
1035 function __construct() {
1036 $widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
1037 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
1040 function widget( $args, $instance ) {
1042 $current_taxonomy = $this->_get_current_taxonomy($instance);
1043 if ( !empty($instance['title']) ) {
1044 $title = $instance['title'];
1046 if ( 'post_tag' == $current_taxonomy ) {
1047 $title = __('Tags');
1049 $tax = get_taxonomy($current_taxonomy);
1050 $title = $tax->labels->name;
1053 $title = apply_filters('widget_title', $title, $instance, $this->id_base);
1055 echo $before_widget;
1057 echo $before_title . $title . $after_title;
1058 echo '<div class="tagcloud">';
1059 wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
1064 function update( $new_instance, $old_instance ) {
1065 $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1066 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
1070 function form( $instance ) {
1071 $current_taxonomy = $this->_get_current_taxonomy($instance);
1073 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1074 <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>
1075 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
1076 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
1077 <?php foreach ( get_taxonomies() as $taxonomy ) :
1078 $tax = get_taxonomy($taxonomy);
1079 if ( !$tax->show_tagcloud || empty($tax->labels->name) )
1082 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
1083 <?php endforeach; ?>
1087 function _get_current_taxonomy($instance) {
1088 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1089 return $instance['taxonomy'];
1096 * Navigation Menu widget class
1100 class WP_Nav_Menu_Widget extends WP_Widget {
1102 function __construct() {
1103 $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
1104 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1107 function widget($args, $instance) {
1109 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
1114 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
1116 echo $args['before_widget'];
1118 if ( !empty($instance['title']) )
1119 echo $args['before_title'] . $instance['title'] . $args['after_title'];
1121 wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
1123 echo $args['after_widget'];
1126 function update( $new_instance, $old_instance ) {
1127 $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
1128 $instance['nav_menu'] = (int) $new_instance['nav_menu'];
1132 function form( $instance ) {
1133 $title = isset( $instance['title'] ) ? $instance['title'] : '';
1134 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1137 $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
1139 // If no menus exists, direct the user to go and create some.
1141 echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
1146 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1147 <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; ?>" />
1150 <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
1151 <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
1153 foreach ( $menus as $menu ) {
1154 echo '<option value="' . $menu->term_id . '"'
1155 . selected( $nav_menu, $menu->term_id, false )
1156 . '>'. $menu->name . '</option>';
1166 * Register all of the default WordPress widgets on startup.
1168 * Calls 'widgets_init' action after all of the WordPress widgets have been
1173 function wp_widgets_init() {
1174 if ( !is_blog_installed() )
1177 register_widget('WP_Widget_Pages');
1179 register_widget('WP_Widget_Calendar');
1181 register_widget('WP_Widget_Archives');
1183 if ( get_option( 'link_manager_enabled' ) )
1184 register_widget('WP_Widget_Links');
1186 register_widget('WP_Widget_Meta');
1188 register_widget('WP_Widget_Search');
1190 register_widget('WP_Widget_Text');
1192 register_widget('WP_Widget_Categories');
1194 register_widget('WP_Widget_Recent_Posts');
1196 register_widget('WP_Widget_Recent_Comments');
1198 register_widget('WP_Widget_RSS');
1200 register_widget('WP_Widget_Tag_Cloud');
1202 register_widget('WP_Nav_Menu_Widget');
1204 do_action('widgets_init');
1207 add_action('init', 'wp_widgets_init', 1);