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);
21 public function widget( $args, $instance ) {
24 * Filter the widget title.
28 * @param string $title The widget title. Default 'Pages'.
29 * @param array $instance An array of the widget's settings.
30 * @param mixed $id_base The widget ID.
32 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
34 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
35 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
37 if ( $sortby == 'menu_order' )
38 $sortby = 'menu_order, post_title';
41 * Filter the arguments for the Pages widget.
45 * @see wp_list_pages()
47 * @param array $args An array of arguments to retrieve the pages list.
49 $out = wp_list_pages( apply_filters( 'widget_pages_args', array(
52 'sort_column' => $sortby,
56 if ( ! empty( $out ) ) {
57 echo $args['before_widget'];
59 echo $args['before_title'] . $title . $args['after_title'];
66 echo $args['after_widget'];
70 public function update( $new_instance, $old_instance ) {
71 $instance = $old_instance;
72 $instance['title'] = strip_tags($new_instance['title']);
73 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
74 $instance['sortby'] = $new_instance['sortby'];
76 $instance['sortby'] = 'menu_order';
79 $instance['exclude'] = strip_tags( $new_instance['exclude'] );
84 public function form( $instance ) {
86 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
87 $title = esc_attr( $instance['title'] );
88 $exclude = esc_attr( $instance['exclude'] );
90 <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>
92 <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
93 <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
94 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
95 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
96 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
100 <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" />
102 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
114 class WP_Widget_Links extends WP_Widget {
116 public function __construct() {
117 $widget_ops = array('description' => __( "Your blogroll" ) );
118 parent::__construct('links', __('Links'), $widget_ops);
121 public function widget( $args, $instance ) {
123 $show_description = isset($instance['description']) ? $instance['description'] : false;
124 $show_name = isset($instance['name']) ? $instance['name'] : false;
125 $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
126 $show_images = isset($instance['images']) ? $instance['images'] : true;
127 $category = isset($instance['category']) ? $instance['category'] : false;
128 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
129 $order = $orderby == 'rating' ? 'DESC' : 'ASC';
130 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
132 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
135 * Filter the arguments for the Links widget.
139 * @see wp_list_bookmarks()
141 * @param array $args An array of arguments to retrieve the links list.
143 wp_list_bookmarks( apply_filters( 'widget_links_args', array(
144 'title_before' => $args['before_title'], 'title_after' => $args['after_title'],
145 'category_before' => $before_widget, 'category_after' => $args['after_widget'],
146 'show_images' => $show_images, 'show_description' => $show_description,
147 'show_name' => $show_name, 'show_rating' => $show_rating,
148 'category' => $category, 'class' => 'linkcat widget',
149 'orderby' => $orderby, 'order' => $order,
154 public function update( $new_instance, $old_instance ) {
155 $new_instance = (array) $new_instance;
156 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
157 foreach ( $instance as $field => $val ) {
158 if ( isset($new_instance[$field]) )
159 $instance[$field] = 1;
162 $instance['orderby'] = 'name';
163 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
164 $instance['orderby'] = $new_instance['orderby'];
166 $instance['category'] = intval( $new_instance['category'] );
167 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
172 public function form( $instance ) {
175 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
176 $link_cats = get_terms( 'link_category' );
177 if ( ! $limit = intval( $instance['limit'] ) )
181 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
182 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
183 <option value=""><?php _ex('All Links', 'links widget'); ?></option>
185 foreach ( $link_cats as $link_cat ) {
186 echo '<option value="' . intval( $link_cat->term_id ) . '"'
187 . selected( $instance['category'], $link_cat->term_id, false )
188 . '>' . $link_cat->name . "</option>\n";
192 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
193 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
194 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
195 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
196 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
197 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>
201 <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'); ?>" />
202 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
203 <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'); ?>" />
204 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
205 <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'); ?>" />
206 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
207 <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'); ?>" />
208 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
211 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
212 <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" />
219 * Search widget class
223 class WP_Widget_Search extends WP_Widget {
225 public function __construct() {
226 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );
227 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
230 public function widget( $args, $instance ) {
232 /** This filter is documented in wp-includes/default-widgets.php */
233 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
235 echo $args['before_widget'];
237 echo $args['before_title'] . $title . $args['after_title'];
240 // Use current theme search form if it exists
243 echo $args['after_widget'];
246 public function form( $instance ) {
247 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
248 $title = $instance['title'];
250 <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>
254 public function update( $new_instance, $old_instance ) {
255 $instance = $old_instance;
256 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
257 $instance['title'] = strip_tags($new_instance['title']);
264 * Archives widget class
268 class WP_Widget_Archives extends WP_Widget {
270 public function __construct() {
271 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );
272 parent::__construct('archives', __('Archives'), $widget_ops);
275 public function widget( $args, $instance ) {
276 $c = ! empty( $instance['count'] ) ? '1' : '0';
277 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
279 /** This filter is documented in wp-includes/default-widgets.php */
280 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
282 echo $args['before_widget'];
284 echo $args['before_title'] . $title . $args['after_title'];
288 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
290 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
291 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
294 * Filter the arguments for the Archives widget drop-down.
298 * @see wp_get_archives()
300 * @param array $args An array of Archives widget drop-down arguments.
302 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
304 'format' => 'option',
305 'show_post_count' => $c
308 switch ( $dropdown_args['type'] ) {
310 $label = __( 'Select Year' );
313 $label = __( 'Select Month' );
316 $label = __( 'Select Day' );
319 $label = __( 'Select Week' );
322 $label = __( 'Select Post' );
327 <option value=""><?php echo esc_attr( $label ); ?></option>
328 <?php wp_get_archives( $dropdown_args ); ?>
337 * Filter the arguments for the Archives widget.
341 * @see wp_get_archives()
343 * @param array $args An array of Archives option arguments.
345 wp_get_archives( apply_filters( 'widget_archives_args', array(
347 'show_post_count' => $c
354 echo $args['after_widget'];
357 public function update( $new_instance, $old_instance ) {
358 $instance = $old_instance;
359 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
360 $instance['title'] = strip_tags($new_instance['title']);
361 $instance['count'] = $new_instance['count'] ? 1 : 0;
362 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
367 public function form( $instance ) {
368 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
369 $title = strip_tags($instance['title']);
370 $count = $instance['count'] ? 'checked="checked"' : '';
371 $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
373 <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>
375 <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>
377 <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>
386 * Displays log in/out, RSS feed links, etc.
390 class WP_Widget_Meta extends WP_Widget {
392 public function __construct() {
393 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") );
394 parent::__construct('meta', __('Meta'), $widget_ops);
397 public function widget( $args, $instance ) {
399 /** This filter is documented in wp-includes/default-widgets.php */
400 $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
402 echo $args['before_widget'];
404 echo $args['before_title'] . $title . $args['after_title'];
408 <?php wp_register(); ?>
409 <li><?php wp_loginout(); ?></li>
410 <li><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
411 <li><a href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
414 * Filter the "Powered by WordPress" text in the Meta widget.
418 * @param string $title_text Default title text for the WordPress.org link.
420 echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
421 esc_url( __( 'https://wordpress.org/' ) ),
422 esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
423 _x( 'WordPress.org', 'meta widget link text' )
430 echo $args['after_widget'];
433 public function update( $new_instance, $old_instance ) {
434 $instance = $old_instance;
435 $instance['title'] = strip_tags($new_instance['title']);
440 public function form( $instance ) {
441 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
442 $title = strip_tags($instance['title']);
444 <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>
450 * Calendar widget class
454 class WP_Widget_Calendar extends WP_Widget {
456 public function __construct() {
457 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s Posts.') );
458 parent::__construct('calendar', __('Calendar'), $widget_ops);
461 public function widget( $args, $instance ) {
463 /** This filter is documented in wp-includes/default-widgets.php */
464 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
466 echo $args['before_widget'];
468 echo $args['before_title'] . $title . $args['after_title'];
470 echo '<div id="calendar_wrap">';
473 echo $args['after_widget'];
476 public function update( $new_instance, $old_instance ) {
477 $instance = $old_instance;
478 $instance['title'] = strip_tags($new_instance['title']);
483 public function form( $instance ) {
484 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
485 $title = strip_tags($instance['title']);
487 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
488 <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>
498 class WP_Widget_Text extends WP_Widget {
500 public function __construct() {
501 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.'));
502 $control_ops = array('width' => 400, 'height' => 350);
503 parent::__construct('text', __('Text'), $widget_ops, $control_ops);
506 public function widget( $args, $instance ) {
508 /** This filter is documented in wp-includes/default-widgets.php */
509 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
512 * Filter the content of the Text widget.
516 * @param string $widget_text The widget content.
517 * @param WP_Widget $instance WP_Widget instance.
519 $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
520 echo $args['before_widget'];
521 if ( ! empty( $title ) ) {
522 echo $args['before_title'] . $title . $args['after_title'];
524 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
526 echo $args['after_widget'];
529 public function update( $new_instance, $old_instance ) {
530 $instance = $old_instance;
531 $instance['title'] = strip_tags($new_instance['title']);
532 if ( current_user_can('unfiltered_html') )
533 $instance['text'] = $new_instance['text'];
535 $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
536 $instance['filter'] = ! empty( $new_instance['filter'] );
540 public function form( $instance ) {
541 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
542 $title = strip_tags($instance['title']);
543 $text = esc_textarea($instance['text']);
545 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
546 <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>
548 <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>
550 <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>
556 * Categories widget class
560 class WP_Widget_Categories extends WP_Widget {
562 public function __construct() {
563 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) );
564 parent::__construct('categories', __('Categories'), $widget_ops);
567 public function widget( $args, $instance ) {
569 /** This filter is documented in wp-includes/default-widgets.php */
570 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
572 $c = ! empty( $instance['count'] ) ? '1' : '0';
573 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
574 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
576 echo $args['before_widget'];
578 echo $args['before_title'] . $title . $args['after_title'];
588 static $first_dropdown = true;
590 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
591 $first_dropdown = false;
593 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
595 $cat_args['show_option_none'] = __( 'Select Category' );
596 $cat_args['id'] = $dropdown_id;
599 * Filter the arguments for the Categories widget drop-down.
603 * @see wp_dropdown_categories()
605 * @param array $cat_args An array of Categories widget drop-down arguments.
607 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
610 <script type='text/javascript'>
613 var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
614 function onCatChange() {
615 if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
616 location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
619 dropdown.onchange = onCatChange;
629 $cat_args['title_li'] = '';
632 * Filter the arguments for the Categories widget.
636 * @param array $cat_args An array of Categories widget options.
638 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
644 echo $args['after_widget'];
647 public function update( $new_instance, $old_instance ) {
648 $instance = $old_instance;
649 $instance['title'] = strip_tags($new_instance['title']);
650 $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
651 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
652 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
657 public function form( $instance ) {
659 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
660 $title = esc_attr( $instance['title'] );
661 $count = isset($instance['count']) ? (bool) $instance['count'] :false;
662 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
663 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
665 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
666 <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>
668 <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 ); ?> />
669 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
671 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
672 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
674 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
675 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
682 * Recent_Posts widget class
686 class WP_Widget_Recent_Posts extends WP_Widget {
688 public function __construct() {
689 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") );
690 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
691 $this->alt_option_name = 'widget_recent_entries';
693 add_action( 'save_post', array($this, 'flush_widget_cache') );
694 add_action( 'deleted_post', array($this, 'flush_widget_cache') );
695 add_action( 'switch_theme', array($this, 'flush_widget_cache') );
698 public function widget($args, $instance) {
700 if ( ! $this->is_preview() ) {
701 $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
704 if ( ! is_array( $cache ) ) {
708 if ( ! isset( $args['widget_id'] ) ) {
709 $args['widget_id'] = $this->id;
712 if ( isset( $cache[ $args['widget_id'] ] ) ) {
713 echo $cache[ $args['widget_id'] ];
719 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
721 /** This filter is documented in wp-includes/default-widgets.php */
722 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
724 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
727 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
730 * Filter the arguments for the Recent Posts widget.
734 * @see WP_Query::get_posts()
736 * @param array $args An array of arguments used to retrieve the recent posts.
738 $r = new WP_Query( apply_filters( 'widget_posts_args', array(
739 'posts_per_page' => $number,
740 'no_found_rows' => true,
741 'post_status' => 'publish',
742 'ignore_sticky_posts' => true
745 if ($r->have_posts()) :
747 <?php echo $args['before_widget']; ?>
748 <?php if ( $title ) {
749 echo $args['before_title'] . $title . $args['after_title'];
752 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
754 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
755 <?php if ( $show_date ) : ?>
756 <span class="post-date"><?php echo get_the_date(); ?></span>
761 <?php echo $args['after_widget']; ?>
763 // Reset the global $the_post as this query will have stomped on it
768 if ( ! $this->is_preview() ) {
769 $cache[ $args['widget_id'] ] = ob_get_flush();
770 wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
776 public function update( $new_instance, $old_instance ) {
777 $instance = $old_instance;
778 $instance['title'] = strip_tags($new_instance['title']);
779 $instance['number'] = (int) $new_instance['number'];
780 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
781 $this->flush_widget_cache();
783 $alloptions = wp_cache_get( 'alloptions', 'options' );
784 if ( isset($alloptions['widget_recent_entries']) )
785 delete_option('widget_recent_entries');
790 public function flush_widget_cache() {
791 wp_cache_delete('widget_recent_posts', 'widget');
794 public function form( $instance ) {
795 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
796 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
797 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
799 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
800 <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>
802 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
803 <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>
805 <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' ); ?>" />
806 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
812 * Recent_Comments widget class
816 class WP_Widget_Recent_Comments extends WP_Widget {
818 public function __construct() {
819 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site’s most recent comments.' ) );
820 parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
821 $this->alt_option_name = 'widget_recent_comments';
823 if ( is_active_widget(false, false, $this->id_base) )
824 add_action( 'wp_head', array($this, 'recent_comments_style') );
826 add_action( 'comment_post', array($this, 'flush_widget_cache') );
827 add_action( 'edit_comment', array($this, 'flush_widget_cache') );
828 add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
831 public function recent_comments_style() {
834 * Filter the Recent Comments default widget styles.
838 * @param bool $active Whether the widget is active. Default true.
839 * @param string $id_base The widget ID.
841 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
842 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
845 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
849 public function flush_widget_cache() {
850 wp_cache_delete('widget_recent_comments', 'widget');
853 public function widget( $args, $instance ) {
854 global $comments, $comment;
857 if ( ! $this->is_preview() ) {
858 $cache = wp_cache_get('widget_recent_comments', 'widget');
860 if ( ! is_array( $cache ) ) {
864 if ( ! isset( $args['widget_id'] ) )
865 $args['widget_id'] = $this->id;
867 if ( isset( $cache[ $args['widget_id'] ] ) ) {
868 echo $cache[ $args['widget_id'] ];
874 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );
876 /** This filter is documented in wp-includes/default-widgets.php */
877 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
879 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
884 * Filter the arguments for the Recent Comments widget.
888 * @see WP_Comment_Query::query() for information on accepted arguments.
890 * @param array $comment_args An array of arguments used to retrieve the recent comments.
892 $comments = get_comments( apply_filters( 'widget_comments_args', array(
894 'status' => 'approve',
895 'post_status' => 'publish'
898 $output .= $args['before_widget'];
900 $output .= $args['before_title'] . $title . $args['after_title'];
903 $output .= '<ul id="recentcomments">';
905 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
906 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
907 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
909 foreach ( (array) $comments as $comment) {
910 $output .= '<li class="recentcomments">';
911 /* translators: comments widget: 1: comment author, 2: post link */
912 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
913 '<span class="comment-author-link">' . get_comment_author_link() . '</span>',
914 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
920 $output .= $args['after_widget'];
924 if ( ! $this->is_preview() ) {
925 $cache[ $args['widget_id'] ] = $output;
926 wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
930 public function update( $new_instance, $old_instance ) {
931 $instance = $old_instance;
932 $instance['title'] = strip_tags($new_instance['title']);
933 $instance['number'] = absint( $new_instance['number'] );
934 $this->flush_widget_cache();
936 $alloptions = wp_cache_get( 'alloptions', 'options' );
937 if ( isset($alloptions['widget_recent_comments']) )
938 delete_option('widget_recent_comments');
943 public function form( $instance ) {
944 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
945 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
947 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
948 <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>
950 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
951 <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>
961 class WP_Widget_RSS extends WP_Widget {
963 public function __construct() {
964 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
965 $control_ops = array( 'width' => 400, 'height' => 200 );
966 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
969 public function widget($args, $instance) {
971 if ( isset($instance['error']) && $instance['error'] )
974 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
975 while ( stristr($url, 'http') != $url )
976 $url = substr($url, 1);
981 // self-url destruction sequence
982 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
985 $rss = fetch_feed($url);
986 $title = $instance['title'];
990 if ( ! is_wp_error($rss) ) {
991 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
993 $title = esc_html(strip_tags($rss->get_title()));
994 $link = esc_url(strip_tags($rss->get_permalink()));
995 while ( stristr($link, 'http') != $link )
996 $link = substr($link, 1);
1000 $title = empty($desc) ? __('Unknown Feed') : $desc;
1002 /** This filter is documented in wp-includes/default-widgets.php */
1003 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
1005 $url = esc_url(strip_tags($url));
1006 $icon = includes_url('images/rss.png');
1008 $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>";
1010 echo $args['before_widget'];
1012 echo $args['before_title'] . $title . $args['after_title'];
1014 wp_widget_rss_output( $rss, $instance );
1015 echo $args['after_widget'];
1017 if ( ! is_wp_error($rss) )
1022 public function update($new_instance, $old_instance) {
1023 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
1024 return wp_widget_rss_process( $new_instance, $testurl );
1027 public function form($instance) {
1029 if ( empty($instance) )
1030 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
1031 $instance['number'] = $this->number;
1033 wp_widget_rss_form( $instance );
1038 * Display the RSS entries in a list.
1042 * @param string|array|object $rss RSS url.
1043 * @param array $args Widget arguments.
1045 function wp_widget_rss_output( $rss, $args = array() ) {
1046 if ( is_string( $rss ) ) {
1047 $rss = fetch_feed($rss);
1048 } elseif ( is_array($rss) && isset($rss['url']) ) {
1050 $rss = fetch_feed($rss['url']);
1051 } elseif ( !is_object($rss) ) {
1055 if ( is_wp_error($rss) ) {
1056 if ( is_admin() || current_user_can('manage_options') )
1057 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
1061 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
1062 $args = wp_parse_args( $args, $default_args );
1064 $items = (int) $args['items'];
1065 if ( $items < 1 || 20 < $items )
1067 $show_summary = (int) $args['show_summary'];
1068 $show_author = (int) $args['show_author'];
1069 $show_date = (int) $args['show_date'];
1071 if ( !$rss->get_item_quantity() ) {
1072 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
1079 foreach ( $rss->get_items( 0, $items ) as $item ) {
1080 $link = $item->get_link();
1081 while ( stristr( $link, 'http' ) != $link ) {
1082 $link = substr( $link, 1 );
1084 $link = esc_url( strip_tags( $link ) );
1086 $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
1087 if ( empty( $title ) ) {
1088 $title = __( 'Untitled' );
1091 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
1092 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) );
1095 if ( $show_summary ) {
1098 // Change existing [...] to […].
1099 if ( '[...]' == substr( $summary, -5 ) ) {
1100 $summary = substr( $summary, 0, -5 ) . '[…]';
1103 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
1108 $date = $item->get_date( 'U' );
1111 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
1116 if ( $show_author ) {
1117 $author = $item->get_author();
1118 if ( is_object($author) ) {
1119 $author = $author->get_name();
1120 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
1124 if ( $link == '' ) {
1125 echo "<li>$title{$date}{$summary}{$author}</li>";
1126 } elseif ( $show_summary ) {
1127 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";
1129 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";
1138 * Display RSS widget options form.
1140 * The options for what fields are displayed for the RSS form are all booleans
1141 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
1146 * @param array|string $args Values for input fields.
1147 * @param array $inputs Override default display options.
1149 function wp_widget_rss_form( $args, $inputs = null ) {
1150 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
1151 $inputs = wp_parse_args( $inputs, $default_inputs );
1153 $args['number'] = esc_attr( $args['number'] );
1154 $args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
1155 $args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
1156 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
1158 if ( $args['items'] < 1 || 20 < $args['items'] ) {
1159 $args['items'] = 10;
1162 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
1163 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
1164 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
1166 if ( ! empty( $args['error'] ) ) {
1167 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
1170 if ( $inputs['url'] ) :
1172 <p><label for="rss-url-<?php echo $args['number']; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>
1173 <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>
1174 <?php endif; if ( $inputs['title'] ) : ?>
1175 <p><label for="rss-title-<?php echo $args['number']; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>
1176 <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>
1177 <?php endif; if ( $inputs['items'] ) : ?>
1178 <p><label for="rss-items-<?php echo $args['number']; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>
1179 <select id="rss-items-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][items]">
1181 for ( $i = 1; $i <= 20; ++$i ) {
1182 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";
1186 <?php endif; if ( $inputs['show_summary'] ) : ?>
1187 <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'] ); ?> />
1188 <label for="rss-show-summary-<?php echo $args['number']; ?>"><?php _e( 'Display item content?' ); ?></label></p>
1189 <?php endif; if ( $inputs['show_author'] ) : ?>
1190 <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'] ); ?> />
1191 <label for="rss-show-author-<?php echo $args['number']; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>
1192 <?php endif; if ( $inputs['show_date'] ) : ?>
1193 <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'] ); ?>/>
1194 <label for="rss-show-date-<?php echo $args['number']; ?>"><?php _e( 'Display item date?' ); ?></label></p>
1197 foreach ( array_keys($default_inputs) as $input ) :
1198 if ( 'hidden' === $inputs[$input] ) :
1199 $id = str_replace( '_', '-', $input );
1201 <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 ]; ?>" />
1208 * Process RSS feed widget data and optionally retrieve feed items.
1210 * The feed widget can not have more than 20 items or it will reset back to the
1211 * default, which is 10.
1213 * The resulting array has the feed title, feed url, feed link (from channel),
1214 * feed items, error (if any), and whether to show summary, author, and date.
1215 * All respectively in the order of the array elements.
1219 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
1220 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
1223 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
1224 $items = (int) $widget_rss['items'];
1225 if ( $items < 1 || 20 < $items )
1227 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
1228 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
1229 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
1230 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
1231 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
1233 if ( $check_feed ) {
1234 $rss = fetch_feed($url);
1237 if ( is_wp_error($rss) ) {
1238 $error = $rss->get_error_message();
1240 $link = esc_url(strip_tags($rss->get_permalink()));
1241 while ( stristr($link, 'http') != $link )
1242 $link = substr($link, 1);
1249 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
1253 * Tag cloud widget class
1257 class WP_Widget_Tag_Cloud extends WP_Widget {
1259 public function __construct() {
1260 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );
1261 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
1264 public function widget( $args, $instance ) {
1265 $current_taxonomy = $this->_get_current_taxonomy($instance);
1266 if ( !empty($instance['title']) ) {
1267 $title = $instance['title'];
1269 if ( 'post_tag' == $current_taxonomy ) {
1270 $title = __('Tags');
1272 $tax = get_taxonomy($current_taxonomy);
1273 $title = $tax->labels->name;
1277 /** This filter is documented in wp-includes/default-widgets.php */
1278 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
1280 echo $args['before_widget'];
1282 echo $args['before_title'] . $title . $args['after_title'];
1284 echo '<div class="tagcloud">';
1287 * Filter the taxonomy used in the Tag Cloud widget.
1290 * @since 3.0.0 Added taxonomy drop-down.
1292 * @see wp_tag_cloud()
1294 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
1296 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
1297 'taxonomy' => $current_taxonomy
1301 echo $args['after_widget'];
1304 public function update( $new_instance, $old_instance ) {
1305 $instance = array();
1306 $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1307 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
1311 public function form( $instance ) {
1312 $current_taxonomy = $this->_get_current_taxonomy($instance);
1314 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1315 <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>
1316 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
1317 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
1318 <?php foreach ( get_taxonomies() as $taxonomy ) :
1319 $tax = get_taxonomy($taxonomy);
1320 if ( !$tax->show_tagcloud || empty($tax->labels->name) )
1323 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
1324 <?php endforeach; ?>
1328 public function _get_current_taxonomy($instance) {
1329 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1330 return $instance['taxonomy'];
1337 * Navigation Menu widget class
1341 class WP_Nav_Menu_Widget extends WP_Widget {
1343 public function __construct() {
1344 $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
1345 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1348 public function widget($args, $instance) {
1350 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
1355 /** This filter is documented in wp-includes/default-widgets.php */
1356 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
1358 echo $args['before_widget'];
1360 if ( !empty($instance['title']) )
1361 echo $args['before_title'] . $instance['title'] . $args['after_title'];
1363 $nav_menu_args = array(
1364 'fallback_cb' => '',
1369 * Filter the arguments for the Custom Menu widget.
1373 * @param array $nav_menu_args {
1374 * An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
1376 * @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
1377 * @type mixed $menu Menu ID, slug, or name.
1379 * @param stdClass $nav_menu Nav menu object for the current menu.
1380 * @param array $args Display arguments for the current widget.
1382 wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) );
1384 echo $args['after_widget'];
1387 public function update( $new_instance, $old_instance ) {
1388 $instance = array();
1389 if ( ! empty( $new_instance['title'] ) ) {
1390 $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
1392 if ( ! empty( $new_instance['nav_menu'] ) ) {
1393 $instance['nav_menu'] = (int) $new_instance['nav_menu'];
1398 public function form( $instance ) {
1399 $title = isset( $instance['title'] ) ? $instance['title'] : '';
1400 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1403 $menus = wp_get_nav_menus();
1405 // If no menus exists, direct the user to go and create some.
1407 echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
1412 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1413 <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 ); ?>" />
1416 <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
1417 <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
1418 <option value="0"><?php _e( '— Select —' ) ?></option>
1420 foreach ( $menus as $menu ) {
1421 echo '<option value="' . $menu->term_id . '"'
1422 . selected( $nav_menu, $menu->term_id, false )
1423 . '>'. esc_html( $menu->name ) . '</option>';
1433 * Register all of the default WordPress widgets on startup.
1435 * Calls 'widgets_init' action after all of the WordPress widgets have been
1440 function wp_widgets_init() {
1441 if ( !is_blog_installed() )
1444 register_widget('WP_Widget_Pages');
1446 register_widget('WP_Widget_Calendar');
1448 register_widget('WP_Widget_Archives');
1450 if ( get_option( 'link_manager_enabled' ) )
1451 register_widget('WP_Widget_Links');
1453 register_widget('WP_Widget_Meta');
1455 register_widget('WP_Widget_Search');
1457 register_widget('WP_Widget_Text');
1459 register_widget('WP_Widget_Categories');
1461 register_widget('WP_Widget_Recent_Posts');
1463 register_widget('WP_Widget_Recent_Comments');
1465 register_widget('WP_Widget_RSS');
1467 register_widget('WP_Widget_Tag_Cloud');
1469 register_widget('WP_Nav_Menu_Widget');
1472 * Fires after all default WordPress widgets have been registered.
1476 do_action( 'widgets_init' );
1479 add_action('init', 'wp_widgets_init', 1);