14 class WP_Widget_Pages extends WP_Widget {
16 public function __construct() {
17 $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A list of your site’s Pages.') );
18 parent::__construct('pages', __('Pages'), $widget_ops);
23 * @param array $instance
25 public function widget( $args, $instance ) {
28 * Filter the widget title.
32 * @param string $title The widget title. Default 'Pages'.
33 * @param array $instance An array of the widget's settings.
34 * @param mixed $id_base The widget ID.
36 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
38 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
39 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
41 if ( $sortby == 'menu_order' )
42 $sortby = 'menu_order, post_title';
45 * Filter the arguments for the Pages widget.
49 * @see wp_list_pages()
51 * @param array $args An array of arguments to retrieve the pages list.
53 $out = wp_list_pages( apply_filters( 'widget_pages_args', array(
56 'sort_column' => $sortby,
60 if ( ! empty( $out ) ) {
61 echo $args['before_widget'];
63 echo $args['before_title'] . $title . $args['after_title'];
70 echo $args['after_widget'];
75 * @param array $new_instance
76 * @param array $old_instance
79 public function update( $new_instance, $old_instance ) {
80 $instance = $old_instance;
81 $instance['title'] = strip_tags($new_instance['title']);
82 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
83 $instance['sortby'] = $new_instance['sortby'];
85 $instance['sortby'] = 'menu_order';
88 $instance['exclude'] = strip_tags( $new_instance['exclude'] );
94 * @param array $instance
96 public function form( $instance ) {
98 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
99 $title = esc_attr( $instance['title'] );
100 $exclude = esc_attr( $instance['exclude'] );
102 <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>
104 <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
105 <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
106 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
107 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
108 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
112 <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" />
114 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
126 class WP_Widget_Links extends WP_Widget {
128 public function __construct() {
129 $widget_ops = array('description' => __( "Your blogroll" ) );
130 parent::__construct('links', __('Links'), $widget_ops);
135 * @param array $instance
137 public function widget( $args, $instance ) {
138 $show_description = isset($instance['description']) ? $instance['description'] : false;
139 $show_name = isset($instance['name']) ? $instance['name'] : false;
140 $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
141 $show_images = isset($instance['images']) ? $instance['images'] : true;
142 $category = isset($instance['category']) ? $instance['category'] : false;
143 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
144 $order = $orderby == 'rating' ? 'DESC' : 'ASC';
145 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
147 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
150 * Filter the arguments for the Links widget.
154 * @see wp_list_bookmarks()
156 * @param array $args An array of arguments to retrieve the links list.
158 wp_list_bookmarks( apply_filters( 'widget_links_args', array(
159 'title_before' => $args['before_title'], 'title_after' => $args['after_title'],
160 'category_before' => $before_widget, 'category_after' => $args['after_widget'],
161 'show_images' => $show_images, 'show_description' => $show_description,
162 'show_name' => $show_name, 'show_rating' => $show_rating,
163 'category' => $category, 'class' => 'linkcat widget',
164 'orderby' => $orderby, 'order' => $order,
170 * @param array $new_instance
171 * @param array $old_instance
174 public function update( $new_instance, $old_instance ) {
175 $new_instance = (array) $new_instance;
176 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
177 foreach ( $instance as $field => $val ) {
178 if ( isset($new_instance[$field]) )
179 $instance[$field] = 1;
182 $instance['orderby'] = 'name';
183 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
184 $instance['orderby'] = $new_instance['orderby'];
186 $instance['category'] = intval( $new_instance['category'] );
187 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
193 * @param array $instance
195 public function form( $instance ) {
198 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
199 $link_cats = get_terms( 'link_category' );
200 if ( ! $limit = intval( $instance['limit'] ) )
204 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
205 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
206 <option value=""><?php _ex('All Links', 'links widget'); ?></option>
208 foreach ( $link_cats as $link_cat ) {
209 echo '<option value="' . intval( $link_cat->term_id ) . '"'
210 . selected( $instance['category'], $link_cat->term_id, false )
211 . '>' . $link_cat->name . "</option>\n";
215 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
216 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
217 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
218 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
219 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
220 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>
224 <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'); ?>" />
225 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
226 <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'); ?>" />
227 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
228 <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'); ?>" />
229 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
230 <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'); ?>" />
231 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
234 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
235 <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" />
242 * Search widget class
246 class WP_Widget_Search extends WP_Widget {
248 public function __construct() {
249 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );
250 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
255 * @param array $instance
257 public function widget( $args, $instance ) {
258 /** This filter is documented in wp-includes/default-widgets.php */
259 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
261 echo $args['before_widget'];
263 echo $args['before_title'] . $title . $args['after_title'];
266 // Use current theme search form if it exists
269 echo $args['after_widget'];
273 * @param array $instance
275 public function form( $instance ) {
276 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
277 $title = $instance['title'];
279 <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>
284 * @param array $new_instance
285 * @param array $old_instance
288 public function update( $new_instance, $old_instance ) {
289 $instance = $old_instance;
290 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
291 $instance['title'] = strip_tags($new_instance['title']);
298 * Archives widget class
302 class WP_Widget_Archives extends WP_Widget {
304 public function __construct() {
305 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );
306 parent::__construct('archives', __('Archives'), $widget_ops);
311 * @param array $instance
313 public function widget( $args, $instance ) {
314 $c = ! empty( $instance['count'] ) ? '1' : '0';
315 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
317 /** This filter is documented in wp-includes/default-widgets.php */
318 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
320 echo $args['before_widget'];
322 echo $args['before_title'] . $title . $args['after_title'];
326 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
328 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
329 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
332 * Filter the arguments for the Archives widget drop-down.
336 * @see wp_get_archives()
338 * @param array $args An array of Archives widget drop-down arguments.
340 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
342 'format' => 'option',
343 'show_post_count' => $c
346 switch ( $dropdown_args['type'] ) {
348 $label = __( 'Select Year' );
351 $label = __( 'Select Month' );
354 $label = __( 'Select Day' );
357 $label = __( 'Select Week' );
360 $label = __( 'Select Post' );
365 <option value=""><?php echo esc_attr( $label ); ?></option>
366 <?php wp_get_archives( $dropdown_args ); ?>
375 * Filter the arguments for the Archives widget.
379 * @see wp_get_archives()
381 * @param array $args An array of Archives option arguments.
383 wp_get_archives( apply_filters( 'widget_archives_args', array(
385 'show_post_count' => $c
392 echo $args['after_widget'];
396 * @param array $new_instance
397 * @param array $old_instance
400 public function update( $new_instance, $old_instance ) {
401 $instance = $old_instance;
402 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
403 $instance['title'] = strip_tags($new_instance['title']);
404 $instance['count'] = $new_instance['count'] ? 1 : 0;
405 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
411 * @param array $instance
413 public function form( $instance ) {
414 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
415 $title = strip_tags($instance['title']);
416 $count = $instance['count'] ? 'checked="checked"' : '';
417 $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
419 <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>
421 <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>
423 <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>
432 * Displays log in/out, RSS feed links, etc.
436 class WP_Widget_Meta extends WP_Widget {
438 public function __construct() {
439 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") );
440 parent::__construct('meta', __('Meta'), $widget_ops);
445 * @param array $instance
447 public function widget( $args, $instance ) {
448 /** This filter is documented in wp-includes/default-widgets.php */
449 $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
451 echo $args['before_widget'];
453 echo $args['before_title'] . $title . $args['after_title'];
457 <?php wp_register(); ?>
458 <li><?php wp_loginout(); ?></li>
459 <li><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
460 <li><a href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
463 * Filter the "Powered by WordPress" text in the Meta widget.
467 * @param string $title_text Default title text for the WordPress.org link.
469 echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
470 esc_url( __( 'https://wordpress.org/' ) ),
471 esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
472 _x( 'WordPress.org', 'meta widget link text' )
479 echo $args['after_widget'];
483 * @param array $new_instance
484 * @param array $old_instance
487 public function update( $new_instance, $old_instance ) {
488 $instance = $old_instance;
489 $instance['title'] = strip_tags($new_instance['title']);
495 * @param array $instance
497 public function form( $instance ) {
498 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
499 $title = strip_tags($instance['title']);
501 <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>
507 * Calendar widget class
511 class WP_Widget_Calendar extends WP_Widget {
513 public function __construct() {
514 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s Posts.') );
515 parent::__construct('calendar', __('Calendar'), $widget_ops);
520 * @param array $instance
522 public function widget( $args, $instance ) {
523 /** This filter is documented in wp-includes/default-widgets.php */
524 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
526 echo $args['before_widget'];
528 echo $args['before_title'] . $title . $args['after_title'];
530 echo '<div id="calendar_wrap">';
533 echo $args['after_widget'];
537 * @param array $new_instance
538 * @param array $old_instance
541 public function update( $new_instance, $old_instance ) {
542 $instance = $old_instance;
543 $instance['title'] = strip_tags($new_instance['title']);
549 * @param array $instance
551 public function form( $instance ) {
552 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
553 $title = strip_tags($instance['title']);
555 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
556 <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>
566 class WP_Widget_Text extends WP_Widget {
568 public function __construct() {
569 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.'));
570 $control_ops = array('width' => 400, 'height' => 350);
571 parent::__construct('text', __('Text'), $widget_ops, $control_ops);
576 * @param array $instance
578 public function widget( $args, $instance ) {
579 /** This filter is documented in wp-includes/default-widgets.php */
580 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
583 * Filter the content of the Text widget.
587 * @param string $widget_text The widget content.
588 * @param WP_Widget $instance WP_Widget instance.
590 $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
591 echo $args['before_widget'];
592 if ( ! empty( $title ) ) {
593 echo $args['before_title'] . $title . $args['after_title'];
595 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
597 echo $args['after_widget'];
601 * @param array $new_instance
602 * @param array $old_instance
605 public function update( $new_instance, $old_instance ) {
606 $instance = $old_instance;
607 $instance['title'] = strip_tags($new_instance['title']);
608 if ( current_user_can('unfiltered_html') )
609 $instance['text'] = $new_instance['text'];
611 $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
612 $instance['filter'] = ! empty( $new_instance['filter'] );
617 * @param array $instance
619 public function form( $instance ) {
620 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
621 $title = strip_tags($instance['title']);
622 $text = esc_textarea($instance['text']);
624 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
625 <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>
627 <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
628 <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></p>
630 <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>
636 * Categories widget class
640 class WP_Widget_Categories extends WP_Widget {
642 public function __construct() {
643 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) );
644 parent::__construct('categories', __('Categories'), $widget_ops);
648 * @staticvar bool $first_dropdown
651 * @param array $instance
653 public function widget( $args, $instance ) {
654 static $first_dropdown = true;
656 /** This filter is documented in wp-includes/default-widgets.php */
657 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
659 $c = ! empty( $instance['count'] ) ? '1' : '0';
660 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
661 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
663 echo $args['before_widget'];
665 echo $args['before_title'] . $title . $args['after_title'];
675 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
676 $first_dropdown = false;
678 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
680 $cat_args['show_option_none'] = __( 'Select Category' );
681 $cat_args['id'] = $dropdown_id;
684 * Filter the arguments for the Categories widget drop-down.
688 * @see wp_dropdown_categories()
690 * @param array $cat_args An array of Categories widget drop-down arguments.
692 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
695 <script type='text/javascript'>
698 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
699 function onCatChange() {
700 if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
701 location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
704 dropdown.onchange = onCatChange;
714 $cat_args['title_li'] = '';
717 * Filter the arguments for the Categories widget.
721 * @param array $cat_args An array of Categories widget options.
723 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
729 echo $args['after_widget'];
733 * @param array $new_instance
734 * @param array $old_instance
737 public function update( $new_instance, $old_instance ) {
738 $instance = $old_instance;
739 $instance['title'] = strip_tags($new_instance['title']);
740 $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
741 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
742 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
748 * @param array $instance
750 public function form( $instance ) {
752 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
753 $title = esc_attr( $instance['title'] );
754 $count = isset($instance['count']) ? (bool) $instance['count'] :false;
755 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
756 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
758 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
759 <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>
761 <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 ); ?> />
762 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
764 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
765 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
767 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
768 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
775 * Recent_Posts widget class
779 class WP_Widget_Recent_Posts extends WP_Widget {
781 public function __construct() {
782 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") );
783 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
784 $this->alt_option_name = 'widget_recent_entries';
786 add_action( 'save_post', array($this, 'flush_widget_cache') );
787 add_action( 'deleted_post', array($this, 'flush_widget_cache') );
788 add_action( 'switch_theme', array($this, 'flush_widget_cache') );
793 * @param array $instance
795 public function widget( $args, $instance ) {
797 if ( ! $this->is_preview() ) {
798 $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
801 if ( ! is_array( $cache ) ) {
805 if ( ! isset( $args['widget_id'] ) ) {
806 $args['widget_id'] = $this->id;
809 if ( isset( $cache[ $args['widget_id'] ] ) ) {
810 echo $cache[ $args['widget_id'] ];
816 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
818 /** This filter is documented in wp-includes/default-widgets.php */
819 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
821 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
824 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
827 * Filter the arguments for the Recent Posts widget.
831 * @see WP_Query::get_posts()
833 * @param array $args An array of arguments used to retrieve the recent posts.
835 $r = new WP_Query( apply_filters( 'widget_posts_args', array(
836 'posts_per_page' => $number,
837 'no_found_rows' => true,
838 'post_status' => 'publish',
839 'ignore_sticky_posts' => true
842 if ($r->have_posts()) :
844 <?php echo $args['before_widget']; ?>
845 <?php if ( $title ) {
846 echo $args['before_title'] . $title . $args['after_title'];
849 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
851 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
852 <?php if ( $show_date ) : ?>
853 <span class="post-date"><?php echo get_the_date(); ?></span>
858 <?php echo $args['after_widget']; ?>
860 // Reset the global $the_post as this query will have stomped on it
865 if ( ! $this->is_preview() ) {
866 $cache[ $args['widget_id'] ] = ob_get_flush();
867 wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
874 * @param array $new_instance
875 * @param array $old_instance
878 public function update( $new_instance, $old_instance ) {
879 $instance = $old_instance;
880 $instance['title'] = strip_tags($new_instance['title']);
881 $instance['number'] = (int) $new_instance['number'];
882 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
883 $this->flush_widget_cache();
885 $alloptions = wp_cache_get( 'alloptions', 'options' );
886 if ( isset($alloptions['widget_recent_entries']) )
887 delete_option('widget_recent_entries');
895 public function flush_widget_cache() {
896 wp_cache_delete('widget_recent_posts', 'widget');
900 * @param array $instance
902 public function form( $instance ) {
903 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
904 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
905 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
907 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
908 <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>
910 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
911 <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>
913 <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' ); ?>" />
914 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
920 * Recent_Comments widget class
924 class WP_Widget_Recent_Comments extends WP_Widget {
926 public function __construct() {
927 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site’s most recent comments.' ) );
928 parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
929 $this->alt_option_name = 'widget_recent_comments';
931 if ( is_active_widget(false, false, $this->id_base) )
932 add_action( 'wp_head', array($this, 'recent_comments_style') );
934 add_action( 'comment_post', array($this, 'flush_widget_cache') );
935 add_action( 'edit_comment', array($this, 'flush_widget_cache') );
936 add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
942 public function recent_comments_style() {
944 * Filter the Recent Comments default widget styles.
948 * @param bool $active Whether the widget is active. Default true.
949 * @param string $id_base The widget ID.
951 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
952 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
955 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
962 public function flush_widget_cache() {
963 wp_cache_delete('widget_recent_comments', 'widget');
967 * @global array $comments
968 * @global object $comment
971 * @param array $instance
973 public function widget( $args, $instance ) {
974 global $comments, $comment;
977 if ( ! $this->is_preview() ) {
978 $cache = wp_cache_get('widget_recent_comments', 'widget');
980 if ( ! is_array( $cache ) ) {
984 if ( ! isset( $args['widget_id'] ) )
985 $args['widget_id'] = $this->id;
987 if ( isset( $cache[ $args['widget_id'] ] ) ) {
988 echo $cache[ $args['widget_id'] ];
994 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
996 /** This filter is documented in wp-includes/default-widgets.php */
997 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
999 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
1004 * Filter the arguments for the Recent Comments widget.
1008 * @see WP_Comment_Query::query() for information on accepted arguments.
1010 * @param array $comment_args An array of arguments used to retrieve the recent comments.
1012 $comments = get_comments( apply_filters( 'widget_comments_args', array(
1013 'number' => $number,
1014 'status' => 'approve',
1015 'post_status' => 'publish'
1018 $output .= $args['before_widget'];
1020 $output .= $args['before_title'] . $title . $args['after_title'];
1023 $output .= '<ul id="recentcomments">';
1024 if ( is_array( $comments ) && $comments ) {
1025 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
1026 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
1027 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
1029 foreach ( (array) $comments as $comment) {
1030 $output .= '<li class="recentcomments">';
1031 /* translators: comments widget: 1: comment author, 2: post link */
1032 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
1033 '<span class="comment-author-link">' . get_comment_author_link() . '</span>',
1034 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
1040 $output .= $args['after_widget'];
1044 if ( ! $this->is_preview() ) {
1045 $cache[ $args['widget_id'] ] = $output;
1046 wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
1051 * @param array $new_instance
1052 * @param array $old_instance
1055 public function update( $new_instance, $old_instance ) {
1056 $instance = $old_instance;
1057 $instance['title'] = strip_tags($new_instance['title']);
1058 $instance['number'] = absint( $new_instance['number'] );
1059 $this->flush_widget_cache();
1061 $alloptions = wp_cache_get( 'alloptions', 'options' );
1062 if ( isset($alloptions['widget_recent_comments']) )
1063 delete_option('widget_recent_comments');
1069 * @param array $instance
1071 public function form( $instance ) {
1072 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
1073 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
1075 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
1076 <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>
1078 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
1079 <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>
1089 class WP_Widget_RSS extends WP_Widget {
1091 public function __construct() {
1092 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
1093 $control_ops = array( 'width' => 400, 'height' => 200 );
1094 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
1098 * @param array $args
1099 * @param array $instance
1101 public function widget( $args, $instance ) {
1102 if ( isset($instance['error']) && $instance['error'] )
1105 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
1106 while ( stristr($url, 'http') != $url )
1107 $url = substr($url, 1);
1112 // self-url destruction sequence
1113 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
1116 $rss = fetch_feed($url);
1117 $title = $instance['title'];
1121 if ( ! is_wp_error($rss) ) {
1122 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
1123 if ( empty($title) )
1124 $title = esc_html(strip_tags($rss->get_title()));
1125 $link = esc_url(strip_tags($rss->get_permalink()));
1126 while ( stristr($link, 'http') != $link )
1127 $link = substr($link, 1);
1130 if ( empty($title) )
1131 $title = empty($desc) ? __('Unknown Feed') : $desc;
1133 /** This filter is documented in wp-includes/default-widgets.php */
1134 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
1136 $url = esc_url(strip_tags($url));
1137 $icon = includes_url('images/rss.png');
1139 $title = "<a class='rsswidget' href='$url'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link'>$title</a>";
1141 echo $args['before_widget'];
1143 echo $args['before_title'] . $title . $args['after_title'];
1145 wp_widget_rss_output( $rss, $instance );
1146 echo $args['after_widget'];
1148 if ( ! is_wp_error($rss) )
1154 * @param array $new_instance
1155 * @param array $old_instance
1158 public function update( $new_instance, $old_instance ) {
1159 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
1160 return wp_widget_rss_process( $new_instance, $testurl );
1164 * @param array $instance
1166 public function form( $instance ) {
1167 if ( empty( $instance ) ) {
1168 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
1170 $instance['number'] = $this->number;
1172 wp_widget_rss_form( $instance );
1177 * Display the RSS entries in a list.
1181 * @param string|array|object $rss RSS url.
1182 * @param array $args Widget arguments.
1184 function wp_widget_rss_output( $rss, $args = array() ) {
1185 if ( is_string( $rss ) ) {
1186 $rss = fetch_feed($rss);
1187 } elseif ( is_array($rss) && isset($rss['url']) ) {
1189 $rss = fetch_feed($rss['url']);
1190 } elseif ( !is_object($rss) ) {
1194 if ( is_wp_error($rss) ) {
1195 if ( is_admin() || current_user_can('manage_options') )
1196 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
1200 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
1201 $args = wp_parse_args( $args, $default_args );
1203 $items = (int) $args['items'];
1204 if ( $items < 1 || 20 < $items )
1206 $show_summary = (int) $args['show_summary'];
1207 $show_author = (int) $args['show_author'];
1208 $show_date = (int) $args['show_date'];
1210 if ( !$rss->get_item_quantity() ) {
1211 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
1218 foreach ( $rss->get_items( 0, $items ) as $item ) {
1219 $link = $item->get_link();
1220 while ( stristr( $link, 'http' ) != $link ) {
1221 $link = substr( $link, 1 );
1223 $link = esc_url( strip_tags( $link ) );
1225 $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
1226 if ( empty( $title ) ) {
1227 $title = __( 'Untitled' );
1230 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
1231 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) );
1234 if ( $show_summary ) {
1237 // Change existing [...] to […].
1238 if ( '[...]' == substr( $summary, -5 ) ) {
1239 $summary = substr( $summary, 0, -5 ) . '[…]';
1242 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
1247 $date = $item->get_date( 'U' );
1250 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
1255 if ( $show_author ) {
1256 $author = $item->get_author();
1257 if ( is_object($author) ) {
1258 $author = $author->get_name();
1259 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
1263 if ( $link == '' ) {
1264 echo "<li>$title{$date}{$summary}{$author}</li>";
1265 } elseif ( $show_summary ) {
1266 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";
1268 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";
1277 * Display RSS widget options form.
1279 * The options for what fields are displayed for the RSS form are all booleans
1280 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
1285 * @param array|string $args Values for input fields.
1286 * @param array $inputs Override default display options.
1288 function wp_widget_rss_form( $args, $inputs = null ) {
1289 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
1290 $inputs = wp_parse_args( $inputs, $default_inputs );
1292 $args['number'] = esc_attr( $args['number'] );
1293 $args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
1294 $args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
1295 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
1297 if ( $args['items'] < 1 || 20 < $args['items'] ) {
1298 $args['items'] = 10;
1301 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
1302 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
1303 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
1305 if ( ! empty( $args['error'] ) ) {
1306 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
1309 if ( $inputs['url'] ) :
1311 <p><label for="rss-url-<?php echo $args['number']; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>
1312 <input class="widefat" id="rss-url-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][url]" type="text" value="<?php echo $args['url']; ?>" /></p>
1313 <?php endif; if ( $inputs['title'] ) : ?>
1314 <p><label for="rss-title-<?php echo $args['number']; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>
1315 <input class="widefat" id="rss-title-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][title]" type="text" value="<?php echo $args['title']; ?>" /></p>
1316 <?php endif; if ( $inputs['items'] ) : ?>
1317 <p><label for="rss-items-<?php echo $args['number']; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>
1318 <select id="rss-items-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][items]">
1320 for ( $i = 1; $i <= 20; ++$i ) {
1321 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";
1325 <?php endif; if ( $inputs['show_summary'] ) : ?>
1326 <p><input id="rss-show-summary-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> />
1327 <label for="rss-show-summary-<?php echo $args['number']; ?>"><?php _e( 'Display item content?' ); ?></label></p>
1328 <?php endif; if ( $inputs['show_author'] ) : ?>
1329 <p><input id="rss-show-author-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> />
1330 <label for="rss-show-author-<?php echo $args['number']; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>
1331 <?php endif; if ( $inputs['show_date'] ) : ?>
1332 <p><input id="rss-show-date-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>
1333 <label for="rss-show-date-<?php echo $args['number']; ?>"><?php _e( 'Display item date?' ); ?></label></p>
1336 foreach ( array_keys($default_inputs) as $input ) :
1337 if ( 'hidden' === $inputs[$input] ) :
1338 $id = str_replace( '_', '-', $input );
1340 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][<?php echo $input; ?>]" value="<?php echo $args[ $input ]; ?>" />
1347 * Process RSS feed widget data and optionally retrieve feed items.
1349 * The feed widget can not have more than 20 items or it will reset back to the
1350 * default, which is 10.
1352 * The resulting array has the feed title, feed url, feed link (from channel),
1353 * feed items, error (if any), and whether to show summary, author, and date.
1354 * All respectively in the order of the array elements.
1358 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
1359 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
1362 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
1363 $items = (int) $widget_rss['items'];
1364 if ( $items < 1 || 20 < $items )
1366 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
1367 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
1368 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
1369 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
1370 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
1372 if ( $check_feed ) {
1373 $rss = fetch_feed($url);
1376 if ( is_wp_error($rss) ) {
1377 $error = $rss->get_error_message();
1379 $link = esc_url(strip_tags($rss->get_permalink()));
1380 while ( stristr($link, 'http') != $link )
1381 $link = substr($link, 1);
1388 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
1392 * Tag cloud widget class
1396 class WP_Widget_Tag_Cloud extends WP_Widget {
1398 public function __construct() {
1399 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );
1400 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
1404 * @param array $args
1405 * @param array $instance
1407 public function widget( $args, $instance ) {
1408 $current_taxonomy = $this->_get_current_taxonomy($instance);
1409 if ( !empty($instance['title']) ) {
1410 $title = $instance['title'];
1412 if ( 'post_tag' == $current_taxonomy ) {
1413 $title = __('Tags');
1415 $tax = get_taxonomy($current_taxonomy);
1416 $title = $tax->labels->name;
1420 /** This filter is documented in wp-includes/default-widgets.php */
1421 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
1423 echo $args['before_widget'];
1425 echo $args['before_title'] . $title . $args['after_title'];
1427 echo '<div class="tagcloud">';
1430 * Filter the taxonomy used in the Tag Cloud widget.
1433 * @since 3.0.0 Added taxonomy drop-down.
1435 * @see wp_tag_cloud()
1437 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
1439 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
1440 'taxonomy' => $current_taxonomy
1444 echo $args['after_widget'];
1448 * @param array $new_instance
1449 * @param array $old_instance
1452 public function update( $new_instance, $old_instance ) {
1453 $instance = array();
1454 $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1455 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
1460 * @param array $instance
1462 public function form( $instance ) {
1463 $current_taxonomy = $this->_get_current_taxonomy($instance);
1465 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1466 <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>
1467 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
1468 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
1469 <?php foreach ( get_taxonomies() as $taxonomy ) :
1470 $tax = get_taxonomy($taxonomy);
1471 if ( !$tax->show_tagcloud || empty($tax->labels->name) )
1474 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
1475 <?php endforeach; ?>
1480 * @param array $instance
1483 public function _get_current_taxonomy($instance) {
1484 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1485 return $instance['taxonomy'];
1492 * Navigation Menu widget class
1496 class WP_Nav_Menu_Widget extends WP_Widget {
1498 public function __construct() {
1499 $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
1500 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1504 * @param array $args
1505 * @param array $instance
1507 public function widget( $args, $instance ) {
1509 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
1514 /** This filter is documented in wp-includes/default-widgets.php */
1515 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
1517 echo $args['before_widget'];
1519 if ( !empty($instance['title']) )
1520 echo $args['before_title'] . $instance['title'] . $args['after_title'];
1522 $nav_menu_args = array(
1523 'fallback_cb' => '',
1528 * Filter the arguments for the Custom Menu widget.
1532 * @param array $nav_menu_args {
1533 * An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
1535 * @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
1536 * @type mixed $menu Menu ID, slug, or name.
1538 * @param stdClass $nav_menu Nav menu object for the current menu.
1539 * @param array $args Display arguments for the current widget.
1541 wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) );
1543 echo $args['after_widget'];
1547 * @param array $new_instance
1548 * @param array $old_instance
1551 public function update( $new_instance, $old_instance ) {
1552 $instance = array();
1553 if ( ! empty( $new_instance['title'] ) ) {
1554 $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
1556 if ( ! empty( $new_instance['nav_menu'] ) ) {
1557 $instance['nav_menu'] = (int) $new_instance['nav_menu'];
1563 * @param array $instance
1565 public function form( $instance ) {
1566 $title = isset( $instance['title'] ) ? $instance['title'] : '';
1567 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1570 $menus = wp_get_nav_menus();
1572 // If no menus exists, direct the user to go and create some.
1574 <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
1576 if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
1577 // @todo When expanding a panel, the JS should be smart enough to collapse any existing panels and sections.
1578 $url = 'javascript: wp.customize.section.each(function( section ){ section.collapse(); }); wp.customize.panel( "nav_menus" ).focus();';
1580 $url = admin_url( 'nav-menus.php' );
1583 <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
1585 <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
1587 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
1588 <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>"/>
1591 <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
1592 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
1593 <option value="0"><?php _e( '— Select —' ); ?></option>
1594 <?php foreach ( $menus as $menu ) : ?>
1595 <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
1596 <?php echo esc_html( $menu->name ); ?>
1598 <?php endforeach; ?>
1607 * Register all of the default WordPress widgets on startup.
1609 * Calls 'widgets_init' action after all of the WordPress widgets have been
1614 function wp_widgets_init() {
1615 if ( !is_blog_installed() )
1618 register_widget('WP_Widget_Pages');
1620 register_widget('WP_Widget_Calendar');
1622 register_widget('WP_Widget_Archives');
1624 if ( get_option( 'link_manager_enabled' ) )
1625 register_widget('WP_Widget_Links');
1627 register_widget('WP_Widget_Meta');
1629 register_widget('WP_Widget_Search');
1631 register_widget('WP_Widget_Text');
1633 register_widget('WP_Widget_Categories');
1635 register_widget('WP_Widget_Recent_Posts');
1637 register_widget('WP_Widget_Recent_Comments');
1639 register_widget('WP_Widget_RSS');
1641 register_widget('WP_Widget_Tag_Cloud');
1643 register_widget('WP_Nav_Menu_Widget');
1646 * Fires after all default WordPress widgets have been registered.
1650 do_action( 'widgets_init' );