Ticket #33413: 33413.diff
File 33413.diff, 762.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/default-widgets.php
6 6 * @subpackage Widgets 7 7 */ 8 8 9 /** 10 * Pages widget class 11 * 12 * @since 2.8.0 13 */ 14 class WP_Widget_Pages extends WP_Widget { 15 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); 19 } 20 21 /** 22 * @param array $args 23 * @param array $instance 24 */ 25 public function widget( $args, $instance ) { 26 27 /** 28 * Filter the widget title. 29 * 30 * @since 2.6.0 31 * 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. 35 */ 36 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base ); 37 38 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; 39 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; 40 41 if ( $sortby == 'menu_order' ) 42 $sortby = 'menu_order, post_title'; 43 44 /** 45 * Filter the arguments for the Pages widget. 46 * 47 * @since 2.8.0 48 * 49 * @see wp_list_pages() 50 * 51 * @param array $args An array of arguments to retrieve the pages list. 52 */ 53 $out = wp_list_pages( apply_filters( 'widget_pages_args', array( 54 'title_li' => '', 55 'echo' => 0, 56 'sort_column' => $sortby, 57 'exclude' => $exclude 58 ) ) ); 59 60 if ( ! empty( $out ) ) { 61 echo $args['before_widget']; 62 if ( $title ) { 63 echo $args['before_title'] . $title . $args['after_title']; 64 } 65 ?> 66 <ul> 67 <?php echo $out; ?> 68 </ul> 69 <?php 70 echo $args['after_widget']; 71 } 72 } 73 74 /** 75 * @param array $new_instance 76 * @param array $old_instance 77 * @return array 78 */ 79 public function update( $new_instance, $old_instance ) { 80 $instance = $old_instance; 81 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 82 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) { 83 $instance['sortby'] = $new_instance['sortby']; 84 } else { 85 $instance['sortby'] = 'menu_order'; 86 } 87 88 $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] ); 89 90 return $instance; 91 } 92 93 /** 94 * @param array $instance 95 */ 96 public function form( $instance ) { 97 //Defaults 98 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') ); 99 ?> 100 <p> 101 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label> 102 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> 103 </p> 104 <p> 105 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label> 106 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat"> 107 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option> 108 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option> 109 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> 110 </select> 111 </p> 112 <p> 113 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label> 114 <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" /> 115 <br /> 116 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small> 117 </p> 118 <?php 119 } 120 121 } 122 123 /** 124 * Links widget class 125 * 126 * @since 2.8.0 127 */ 128 class WP_Widget_Links extends WP_Widget { 129 130 public function __construct() { 131 $widget_ops = array('description' => __( "Your blogroll" ) ); 132 parent::__construct('links', __('Links'), $widget_ops); 133 } 134 135 /** 136 * @param array $args 137 * @param array $instance 138 */ 139 public function widget( $args, $instance ) { 140 $show_description = isset($instance['description']) ? $instance['description'] : false; 141 $show_name = isset($instance['name']) ? $instance['name'] : false; 142 $show_rating = isset($instance['rating']) ? $instance['rating'] : false; 143 $show_images = isset($instance['images']) ? $instance['images'] : true; 144 $category = isset($instance['category']) ? $instance['category'] : false; 145 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; 146 $order = $orderby == 'rating' ? 'DESC' : 'ASC'; 147 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; 148 149 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] ); 150 151 /** 152 * Filter the arguments for the Links widget. 153 * 154 * @since 2.6.0 155 * 156 * @see wp_list_bookmarks() 157 * 158 * @param array $args An array of arguments to retrieve the links list. 159 */ 160 wp_list_bookmarks( apply_filters( 'widget_links_args', array( 161 'title_before' => $args['before_title'], 'title_after' => $args['after_title'], 162 'category_before' => $before_widget, 'category_after' => $args['after_widget'], 163 'show_images' => $show_images, 'show_description' => $show_description, 164 'show_name' => $show_name, 'show_rating' => $show_rating, 165 'category' => $category, 'class' => 'linkcat widget', 166 'orderby' => $orderby, 'order' => $order, 167 'limit' => $limit, 168 ) ) ); 169 } 170 171 /** 172 * @param array $new_instance 173 * @param array $old_instance 174 * @return array 175 */ 176 public function update( $new_instance, $old_instance ) { 177 $new_instance = (array) $new_instance; 178 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); 179 foreach ( $instance as $field => $val ) { 180 if ( isset($new_instance[$field]) ) 181 $instance[$field] = 1; 182 } 183 184 $instance['orderby'] = 'name'; 185 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) 186 $instance['orderby'] = $new_instance['orderby']; 187 188 $instance['category'] = intval( $new_instance['category'] ); 189 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; 190 191 return $instance; 192 } 193 194 /** 195 * @param array $instance 196 */ 197 public function form( $instance ) { 198 199 //Defaults 200 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); 201 $link_cats = get_terms( 'link_category' ); 202 if ( ! $limit = intval( $instance['limit'] ) ) 203 $limit = -1; 204 ?> 205 <p> 206 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label> 207 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> 208 <option value=""><?php _ex('All Links', 'links widget'); ?></option> 209 <?php 210 foreach ( $link_cats as $link_cat ) { 211 echo '<option value="' . intval( $link_cat->term_id ) . '"' 212 . selected( $instance['category'], $link_cat->term_id, false ) 213 . '>' . $link_cat->name . "</option>\n"; 214 } 215 ?> 216 </select> 217 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label> 218 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat"> 219 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option> 220 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option> 221 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option> 222 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option> 223 </select> 224 </p> 225 <p> 226 <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'); ?>" /> 227 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br /> 228 <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'); ?>" /> 229 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br /> 230 <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'); ?>" /> 231 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br /> 232 <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'); ?>" /> 233 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label> 234 </p> 235 <p> 236 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label> 237 <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" /> 238 </p> 239 <?php 240 } 241 } 242 243 /** 244 * Search widget class 245 * 246 * @since 2.8.0 247 */ 248 class WP_Widget_Search extends WP_Widget { 249 250 public function __construct() { 251 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") ); 252 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); 253 } 254 255 /** 256 * @param array $args 257 * @param array $instance 258 */ 259 public function widget( $args, $instance ) { 260 /** This filter is documented in wp-includes/default-widgets.php */ 261 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 262 263 echo $args['before_widget']; 264 if ( $title ) { 265 echo $args['before_title'] . $title . $args['after_title']; 266 } 267 268 // Use current theme search form if it exists 269 get_search_form(); 270 271 echo $args['after_widget']; 272 } 273 274 /** 275 * @param array $instance 276 */ 277 public function form( $instance ) { 278 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); 279 $title = $instance['title']; 280 ?> 281 <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> 282 <?php 283 } 284 285 /** 286 * @param array $new_instance 287 * @param array $old_instance 288 * @return array 289 */ 290 public function update( $new_instance, $old_instance ) { 291 $instance = $old_instance; 292 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); 293 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 294 return $instance; 295 } 296 297 } 298 299 /** 300 * Archives widget class 301 * 302 * @since 2.8.0 303 */ 304 class WP_Widget_Archives extends WP_Widget { 305 306 public function __construct() { 307 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') ); 308 parent::__construct('archives', __('Archives'), $widget_ops); 309 } 310 311 /** 312 * @param array $args 313 * @param array $instance 314 */ 315 public function widget( $args, $instance ) { 316 $c = ! empty( $instance['count'] ) ? '1' : '0'; 317 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; 318 319 /** This filter is documented in wp-includes/default-widgets.php */ 320 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); 321 322 echo $args['before_widget']; 323 if ( $title ) { 324 echo $args['before_title'] . $title . $args['after_title']; 325 } 326 327 if ( $d ) { 328 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; 329 ?> 330 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label> 331 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 332 <?php 333 /** 334 * Filter the arguments for the Archives widget drop-down. 335 * 336 * @since 2.8.0 337 * 338 * @see wp_get_archives() 339 * 340 * @param array $args An array of Archives widget drop-down arguments. 341 */ 342 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array( 343 'type' => 'monthly', 344 'format' => 'option', 345 'show_post_count' => $c 346 ) ); 347 348 switch ( $dropdown_args['type'] ) { 349 case 'yearly': 350 $label = __( 'Select Year' ); 351 break; 352 case 'monthly': 353 $label = __( 'Select Month' ); 354 break; 355 case 'daily': 356 $label = __( 'Select Day' ); 357 break; 358 case 'weekly': 359 $label = __( 'Select Week' ); 360 break; 361 default: 362 $label = __( 'Select Post' ); 363 break; 364 } 365 ?> 366 367 <option value=""><?php echo esc_attr( $label ); ?></option> 368 <?php wp_get_archives( $dropdown_args ); ?> 369 370 </select> 371 <?php 372 } else { 373 ?> 374 <ul> 375 <?php 376 /** 377 * Filter the arguments for the Archives widget. 378 * 379 * @since 2.8.0 380 * 381 * @see wp_get_archives() 382 * 383 * @param array $args An array of Archives option arguments. 384 */ 385 wp_get_archives( apply_filters( 'widget_archives_args', array( 386 'type' => 'monthly', 387 'show_post_count' => $c 388 ) ) ); 389 ?> 390 </ul> 391 <?php 392 } 393 394 echo $args['after_widget']; 395 } 396 397 /** 398 * @param array $new_instance 399 * @param array $old_instance 400 * @return array 401 */ 402 public function update( $new_instance, $old_instance ) { 403 $instance = $old_instance; 404 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); 405 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 406 $instance['count'] = $new_instance['count'] ? 1 : 0; 407 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0; 408 409 return $instance; 410 } 411 412 /** 413 * @param array $instance 414 */ 415 public function form( $instance ) { 416 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); 417 $title = sanitize_text_field( $instance['title'] ); 418 ?> 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> 420 <p> 421 <input class="checkbox" type="checkbox" <?php checked( $instance['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> 422 <br/> 423 <input class="checkbox" type="checkbox" <?php checked( $instance['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> 424 </p> 425 <?php 426 } 427 } 428 429 /** 430 * Meta widget class 431 * 432 * Displays log in/out, RSS feed links, etc. 433 * 434 * @since 2.8.0 435 */ 436 class WP_Widget_Meta extends WP_Widget { 437 438 public function __construct() { 439 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") ); 440 parent::__construct('meta', __('Meta'), $widget_ops); 441 } 442 443 /** 444 * @param array $args 445 * @param array $instance 446 */ 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 ); 450 451 echo $args['before_widget']; 452 if ( $title ) { 453 echo $args['before_title'] . $title . $args['after_title']; 454 } 455 ?> 456 <ul> 457 <?php wp_register(); ?> 458 <li><?php wp_loginout(); ?></li> 459 <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> 460 <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li> 461 <?php 462 /** 463 * Filter the "Powered by WordPress" text in the Meta widget. 464 * 465 * @since 3.6.0 466 * 467 * @param string $title_text Default title text for the WordPress.org link. 468 */ 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' ) 473 ) ); 474 475 wp_meta(); 476 ?> 477 </ul> 478 <?php 479 echo $args['after_widget']; 480 } 481 482 /** 483 * @param array $new_instance 484 * @param array $old_instance 485 * @return array 486 */ 487 public function update( $new_instance, $old_instance ) { 488 $instance = $old_instance; 489 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 490 491 return $instance; 492 } 493 494 /** 495 * @param array $instance 496 */ 497 public function form( $instance ) { 498 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 499 $title = sanitize_text_field( $instance['title'] ); 500 ?> 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> 502 <?php 503 } 504 } 505 506 /** 507 * Calendar widget class 508 * 509 * @since 2.8.0 510 */ 511 class WP_Widget_Calendar extends WP_Widget { 512 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); 516 } 517 518 /** 519 * @param array $args 520 * @param array $instance 521 */ 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 ); 525 526 echo $args['before_widget']; 527 if ( $title ) { 528 echo $args['before_title'] . $title . $args['after_title']; 529 } 530 echo '<div id="calendar_wrap">'; 531 get_calendar(); 532 echo '</div>'; 533 echo $args['after_widget']; 534 } 535 536 /** 537 * @param array $new_instance 538 * @param array $old_instance 539 * @return array 540 */ 541 public function update( $new_instance, $old_instance ) { 542 $instance = $old_instance; 543 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 544 545 return $instance; 546 } 547 548 /** 549 * @param array $instance 550 */ 551 public function form( $instance ) { 552 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 553 $title = sanitize_text_field( $instance['title'] ); 554 ?> 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> 557 <?php 558 } 559 } 560 561 /** 562 * Text widget class 563 * 564 * @since 2.8.0 565 */ 566 class WP_Widget_Text extends WP_Widget { 567 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); 572 } 573 574 /** 575 * @param array $args 576 * @param array $instance 577 */ 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 ); 581 582 /** 583 * Filter the content of the Text widget. 584 * 585 * @since 2.3.0 586 * 587 * @param string $widget_text The widget content. 588 * @param WP_Widget $instance WP_Widget instance. 589 */ 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']; 594 } ?> 595 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> 596 <?php 597 echo $args['after_widget']; 598 } 599 600 /** 601 * @param array $new_instance 602 * @param array $old_instance 603 * @return array 604 */ 605 public function update( $new_instance, $old_instance ) { 606 $instance = $old_instance; 607 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 608 if ( current_user_can('unfiltered_html') ) 609 $instance['text'] = $new_instance['text']; 610 else 611 $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) ); 612 $instance['filter'] = ! empty( $new_instance['filter'] ); 613 return $instance; 614 } 615 616 /** 617 * @param array $instance 618 */ 619 public function form( $instance ) { 620 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) ); 621 $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0; 622 $title = sanitize_text_field( $instance['title'] ); 623 ?> 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> 626 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 esc_textarea( $instance['text'] ); ?></textarea></p> 629 630 <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked( $filter ); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p> 631 <?php 632 } 633 } 634 635 /** 636 * Categories widget class 637 * 638 * @since 2.8.0 639 */ 640 class WP_Widget_Categories extends WP_Widget { 641 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); 645 } 646 647 /** 648 * @staticvar bool $first_dropdown 649 * 650 * @param array $args 651 * @param array $instance 652 */ 653 public function widget( $args, $instance ) { 654 static $first_dropdown = true; 655 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 ); 658 659 $c = ! empty( $instance['count'] ) ? '1' : '0'; 660 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; 661 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; 662 663 echo $args['before_widget']; 664 if ( $title ) { 665 echo $args['before_title'] . $title . $args['after_title']; 666 } 667 668 $cat_args = array( 669 'orderby' => 'name', 670 'show_count' => $c, 671 'hierarchical' => $h 672 ); 673 674 if ( $d ) { 675 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}"; 676 $first_dropdown = false; 677 678 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>'; 679 680 $cat_args['show_option_none'] = __( 'Select Category' ); 681 $cat_args['id'] = $dropdown_id; 682 683 /** 684 * Filter the arguments for the Categories widget drop-down. 685 * 686 * @since 2.8.0 687 * 688 * @see wp_dropdown_categories() 689 * 690 * @param array $cat_args An array of Categories widget drop-down arguments. 691 */ 692 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) ); 693 ?> 694 695 <script type='text/javascript'> 696 /* <![CDATA[ */ 697 (function() { 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; 702 } 703 } 704 dropdown.onchange = onCatChange; 705 })(); 706 /* ]]> */ 707 </script> 708 709 <?php 710 } else { 711 ?> 712 <ul> 713 <?php 714 $cat_args['title_li'] = ''; 715 716 /** 717 * Filter the arguments for the Categories widget. 718 * 719 * @since 2.8.0 720 * 721 * @param array $cat_args An array of Categories widget options. 722 */ 723 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) ); 724 ?> 725 </ul> 726 <?php 727 } 728 729 echo $args['after_widget']; 730 } 731 732 /** 733 * @param array $new_instance 734 * @param array $old_instance 735 * @return array 736 */ 737 public function update( $new_instance, $old_instance ) { 738 $instance = $old_instance; 739 $instance['title'] = sanitize_text_field( $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; 743 744 return $instance; 745 } 746 747 /** 748 * @param array $instance 749 */ 750 public function form( $instance ) { 751 //Defaults 752 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); 753 $title = sanitize_text_field( $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; 757 ?> 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 esc_attr( $title ); ?>" /></p> 760 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 /> 763 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 /> 766 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> 769 <?php 770 } 771 772 } 773 774 /** 775 * Recent_Posts widget class 776 * 777 * @since 2.8.0 778 */ 779 class WP_Widget_Recent_Posts extends WP_Widget { 780 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'; 785 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') ); 789 } 790 791 /** 792 * @param array $args 793 * @param array $instance 794 */ 795 public function widget( $args, $instance ) { 796 $cache = array(); 797 if ( ! $this->is_preview() ) { 798 $cache = wp_cache_get( 'widget_recent_posts', 'widget' ); 799 } 800 801 if ( ! is_array( $cache ) ) { 802 $cache = array(); 803 } 804 805 if ( ! isset( $args['widget_id'] ) ) { 806 $args['widget_id'] = $this->id; 807 } 808 809 if ( isset( $cache[ $args['widget_id'] ] ) ) { 810 echo $cache[ $args['widget_id'] ]; 811 return; 812 } 813 814 ob_start(); 815 816 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); 817 818 /** This filter is documented in wp-includes/default-widgets.php */ 819 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 820 821 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; 822 if ( ! $number ) 823 $number = 5; 824 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; 825 826 /** 827 * Filter the arguments for the Recent Posts widget. 828 * 829 * @since 3.4.0 830 * 831 * @see WP_Query::get_posts() 832 * 833 * @param array $args An array of arguments used to retrieve the recent posts. 834 */ 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 840 ) ) ); 841 842 if ($r->have_posts()) : 843 ?> 844 <?php echo $args['before_widget']; ?> 845 <?php if ( $title ) { 846 echo $args['before_title'] . $title . $args['after_title']; 847 } ?> 848 <ul> 849 <?php while ( $r->have_posts() ) : $r->the_post(); ?> 850 <li> 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> 854 <?php endif; ?> 855 </li> 856 <?php endwhile; ?> 857 </ul> 858 <?php echo $args['after_widget']; ?> 859 <?php 860 // Reset the global $the_post as this query will have stomped on it 861 wp_reset_postdata(); 862 863 endif; 864 865 if ( ! $this->is_preview() ) { 866 $cache[ $args['widget_id'] ] = ob_get_flush(); 867 wp_cache_set( 'widget_recent_posts', $cache, 'widget' ); 868 } else { 869 ob_end_flush(); 870 } 871 } 872 873 /** 874 * @param array $new_instance 875 * @param array $old_instance 876 * @return array 877 */ 878 public function update( $new_instance, $old_instance ) { 879 $instance = $old_instance; 880 $instance['title'] = santize_text_field( $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(); 884 885 $alloptions = wp_cache_get( 'alloptions', 'options' ); 886 if ( isset($alloptions['widget_recent_entries']) ) 887 delete_option('widget_recent_entries'); 888 889 return $instance; 890 } 891 892 /** 893 * @access public 894 */ 895 public function flush_widget_cache() { 896 wp_cache_delete('widget_recent_posts', 'widget'); 897 } 898 899 /** 900 * @param array $instance 901 */ 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; 906 ?> 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> 909 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> 912 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> 915 <?php 916 } 917 } 918 919 /** 920 * Recent_Comments widget class 921 * 922 * @since 2.8.0 923 */ 924 class WP_Widget_Recent_Comments extends WP_Widget { 925 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'; 930 931 if ( is_active_widget(false, false, $this->id_base) ) 932 add_action( 'wp_head', array($this, 'recent_comments_style') ); 933 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') ); 937 } 938 939 /** 940 * @access public 941 */ 942 public function recent_comments_style() { 943 /** 944 * Filter the Recent Comments default widget styles. 945 * 946 * @since 3.1.0 947 * 948 * @param bool $active Whether the widget is active. Default true. 949 * @param string $id_base The widget ID. 950 */ 951 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876 952 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) ) 953 return; 954 ?> 955 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> 956 <?php 957 } 958 959 /** 960 * @access public 961 */ 962 public function flush_widget_cache() { 963 wp_cache_delete('widget_recent_comments', 'widget'); 964 } 965 966 /** 967 * @param array $args 968 * @param array $instance 969 */ 970 public function widget( $args, $instance ) { 971 $cache = array(); 972 if ( ! $this->is_preview() ) { 973 $cache = wp_cache_get('widget_recent_comments', 'widget'); 974 } 975 if ( ! is_array( $cache ) ) { 976 $cache = array(); 977 } 978 979 if ( ! isset( $args['widget_id'] ) ) 980 $args['widget_id'] = $this->id; 981 982 if ( isset( $cache[ $args['widget_id'] ] ) ) { 983 echo $cache[ $args['widget_id'] ]; 984 return; 985 } 986 987 $output = ''; 988 989 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' ); 990 991 /** This filter is documented in wp-includes/default-widgets.php */ 992 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 993 994 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; 995 if ( ! $number ) 996 $number = 5; 997 998 /** 999 * Filter the arguments for the Recent Comments widget. 1000 * 1001 * @since 3.4.0 1002 * 1003 * @see WP_Comment_Query::query() for information on accepted arguments. 1004 * 1005 * @param array $comment_args An array of arguments used to retrieve the recent comments. 1006 */ 1007 $comments = get_comments( apply_filters( 'widget_comments_args', array( 1008 'number' => $number, 1009 'status' => 'approve', 1010 'post_status' => 'publish' 1011 ) ) ); 1012 1013 $output .= $args['before_widget']; 1014 if ( $title ) { 1015 $output .= $args['before_title'] . $title . $args['after_title']; 1016 } 1017 1018 $output .= '<ul id="recentcomments">'; 1019 if ( is_array( $comments ) && $comments ) { 1020 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) 1021 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); 1022 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); 1023 1024 foreach ( (array) $comments as $comment ) { 1025 $output .= '<li class="recentcomments">'; 1026 /* translators: comments widget: 1: comment author, 2: post link */ 1027 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ), 1028 '<span class="comment-author-link">' . get_comment_author_link( $comment->comment_ID ) . '</span>', 1029 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' 1030 ); 1031 $output .= '</li>'; 1032 } 1033 } 1034 $output .= '</ul>'; 1035 $output .= $args['after_widget']; 1036 1037 echo $output; 1038 1039 if ( ! $this->is_preview() ) { 1040 $cache[ $args['widget_id'] ] = $output; 1041 wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); 1042 } 1043 } 1044 1045 /** 1046 * @param array $new_instance 1047 * @param array $old_instance 1048 * @return array 1049 */ 1050 public function update( $new_instance, $old_instance ) { 1051 $instance = $old_instance; 1052 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 1053 $instance['number'] = absint( $new_instance['number'] ); 1054 $this->flush_widget_cache(); 1055 1056 $alloptions = wp_cache_get( 'alloptions', 'options' ); 1057 if ( isset($alloptions['widget_recent_comments']) ) 1058 delete_option('widget_recent_comments'); 1059 1060 return $instance; 1061 } 1062 1063 /** 1064 * @param array $instance 1065 */ 1066 public function form( $instance ) { 1067 $title = isset( $instance['title'] ) ? $instance['title'] : ''; 1068 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; 1069 ?> 1070 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 1071 <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> 1072 1073 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label> 1074 <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> 1075 <?php 1076 } 1077 } 1078 1079 /** 1080 * RSS widget class 1081 * 1082 * @since 2.8.0 1083 */ 1084 class WP_Widget_RSS extends WP_Widget { 1085 1086 public function __construct() { 1087 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') ); 1088 $control_ops = array( 'width' => 400, 'height' => 200 ); 1089 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops ); 1090 } 1091 1092 /** 1093 * @param array $args 1094 * @param array $instance 1095 */ 1096 public function widget( $args, $instance ) { 1097 if ( isset($instance['error']) && $instance['error'] ) 1098 return; 1099 1100 $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; 1101 while ( stristr($url, 'http') != $url ) 1102 $url = substr($url, 1); 1103 1104 if ( empty($url) ) 1105 return; 1106 1107 // self-url destruction sequence 1108 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) 1109 return; 1110 1111 $rss = fetch_feed($url); 1112 $title = $instance['title']; 1113 $desc = ''; 1114 $link = ''; 1115 1116 if ( ! is_wp_error($rss) ) { 1117 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); 1118 if ( empty($title) ) 1119 $title = strip_tags( $rss->get_title() ); 1120 $link = strip_tags( $rss->get_permalink() ); 1121 while ( stristr($link, 'http') != $link ) 1122 $link = substr($link, 1); 1123 } 1124 1125 if ( empty($title) ) 1126 $title = empty($desc) ? __('Unknown Feed') : $desc; 1127 1128 /** This filter is documented in wp-includes/default-widgets.php */ 1129 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 1130 1131 $url = strip_tags( $url ); 1132 $icon = includes_url( 'images/rss.png' ); 1133 if ( $title ) 1134 $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">"'. esc_html( $title ) .'"</a>'; 1135 1136 echo $args['before_widget']; 1137 if ( $title ) { 1138 echo $args['before_title'] . $title . $args['after_title']; 1139 } 1140 wp_widget_rss_output( $rss, $instance ); 1141 echo $args['after_widget']; 1142 1143 if ( ! is_wp_error($rss) ) 1144 $rss->__destruct(); 1145 unset($rss); 1146 } 1147 1148 /** 1149 * @param array $new_instance 1150 * @param array $old_instance 1151 * @return array 1152 */ 1153 public function update( $new_instance, $old_instance ) { 1154 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); 1155 return wp_widget_rss_process( $new_instance, $testurl ); 1156 } 1157 1158 /** 1159 * @param array $instance 1160 */ 1161 public function form( $instance ) { 1162 if ( empty( $instance ) ) { 1163 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); 1164 } 1165 $instance['number'] = $this->number; 1166 1167 wp_widget_rss_form( $instance ); 1168 } 1169 } 1170 1171 /** 1172 * Display the RSS entries in a list. 1173 * 1174 * @since 2.5.0 1175 * 1176 * @param string|array|object $rss RSS url. 1177 * @param array $args Widget arguments. 1178 */ 1179 function wp_widget_rss_output( $rss, $args = array() ) { 1180 if ( is_string( $rss ) ) { 1181 $rss = fetch_feed($rss); 1182 } elseif ( is_array($rss) && isset($rss['url']) ) { 1183 $args = $rss; 1184 $rss = fetch_feed($rss['url']); 1185 } elseif ( !is_object($rss) ) { 1186 return; 1187 } 1188 1189 if ( is_wp_error($rss) ) { 1190 if ( is_admin() || current_user_can('manage_options') ) 1191 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; 1192 return; 1193 } 1194 1195 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); 1196 $args = wp_parse_args( $args, $default_args ); 1197 1198 $items = (int) $args['items']; 1199 if ( $items < 1 || 20 < $items ) 1200 $items = 10; 1201 $show_summary = (int) $args['show_summary']; 1202 $show_author = (int) $args['show_author']; 1203 $show_date = (int) $args['show_date']; 1204 1205 if ( !$rss->get_item_quantity() ) { 1206 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; 1207 $rss->__destruct(); 1208 unset($rss); 1209 return; 1210 } 1211 1212 echo '<ul>'; 1213 foreach ( $rss->get_items( 0, $items ) as $item ) { 1214 $link = $item->get_link(); 1215 while ( stristr( $link, 'http' ) != $link ) { 1216 $link = substr( $link, 1 ); 1217 } 1218 $link = esc_url( strip_tags( $link ) ); 1219 1220 $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); 1221 if ( empty( $title ) ) { 1222 $title = __( 'Untitled' ); 1223 } 1224 1225 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); 1226 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); 1227 1228 $summary = ''; 1229 if ( $show_summary ) { 1230 $summary = $desc; 1231 1232 // Change existing [...] to […]. 1233 if ( '[...]' == substr( $summary, -5 ) ) { 1234 $summary = substr( $summary, 0, -5 ) . '[…]'; 1235 } 1236 1237 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; 1238 } 1239 1240 $date = ''; 1241 if ( $show_date ) { 1242 $date = $item->get_date( 'U' ); 1243 1244 if ( $date ) { 1245 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; 1246 } 1247 } 1248 1249 $author = ''; 1250 if ( $show_author ) { 1251 $author = $item->get_author(); 1252 if ( is_object($author) ) { 1253 $author = $author->get_name(); 1254 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; 1255 } 1256 } 1257 1258 if ( $link == '' ) { 1259 echo "<li>$title{$date}{$summary}{$author}</li>"; 1260 } elseif ( $show_summary ) { 1261 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; 1262 } else { 1263 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; 1264 } 1265 } 1266 echo '</ul>'; 1267 $rss->__destruct(); 1268 unset($rss); 1269 } 1270 1271 /** 1272 * Display RSS widget options form. 1273 * 1274 * The options for what fields are displayed for the RSS form are all booleans 1275 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', 1276 * 'show_date'. 1277 * 1278 * @since 2.5.0 1279 * 1280 * @param array|string $args Values for input fields. 1281 * @param array $inputs Override default display options. 1282 */ 1283 function wp_widget_rss_form( $args, $inputs = null ) { 1284 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); 1285 $inputs = wp_parse_args( $inputs, $default_inputs ); 1286 1287 $args['title'] = isset( $args['title'] ) ? $args['title'] : ''; 1288 $args['url'] = isset( $args['url'] ) ? $args['url'] : ''; 1289 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0; 1290 1291 if ( $args['items'] < 1 || 20 < $args['items'] ) { 1292 $args['items'] = 10; 1293 } 1294 1295 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; 1296 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; 1297 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; 1298 1299 if ( ! empty( $args['error'] ) ) { 1300 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>'; 1301 } 1302 1303 $esc_number = esc_attr( $args['number'] ); 1304 if ( $inputs['url'] ) : 1305 ?> 1306 <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label> 1307 <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p> 1308 <?php endif; if ( $inputs['title'] ) : ?> 1309 <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label> 1310 <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr( $args['title'] ); ?>" /></p> 1311 <?php endif; if ( $inputs['items'] ) : ?> 1312 <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e( 'How many items would you like to display?' ); ?></label> 1313 <select id="rss-items-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][items]"> 1314 <?php 1315 for ( $i = 1; $i <= 20; ++$i ) { 1316 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; 1317 } 1318 ?> 1319 </select></p> 1320 <?php endif; if ( $inputs['show_summary'] ) : ?> 1321 <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> 1322 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p> 1323 <?php endif; if ( $inputs['show_author'] ) : ?> 1324 <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> 1325 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p> 1326 <?php endif; if ( $inputs['show_date'] ) : ?> 1327 <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> 1328 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p> 1329 <?php 1330 endif; 1331 foreach ( array_keys($default_inputs) as $input ) : 1332 if ( 'hidden' === $inputs[$input] ) : 1333 $id = str_replace( '_', '-', $input ); 1334 ?> 1335 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" /> 1336 <?php 1337 endif; 1338 endforeach; 1339 } 1340 1341 /** 1342 * Process RSS feed widget data and optionally retrieve feed items. 1343 * 1344 * The feed widget can not have more than 20 items or it will reset back to the 1345 * default, which is 10. 1346 * 1347 * The resulting array has the feed title, feed url, feed link (from channel), 1348 * feed items, error (if any), and whether to show summary, author, and date. 1349 * All respectively in the order of the array elements. 1350 * 1351 * @since 2.5.0 1352 * 1353 * @param array $widget_rss RSS widget feed data. Expects unescaped data. 1354 * @param bool $check_feed Optional, default is true. Whether to check feed for errors. 1355 * @return array 1356 */ 1357 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 1358 $items = (int) $widget_rss['items']; 1359 if ( $items < 1 || 20 < $items ) 1360 $items = 10; 1361 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); 1362 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; 1363 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; 1364 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0; 1365 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; 1366 1367 if ( $check_feed ) { 1368 $rss = fetch_feed($url); 1369 $error = false; 1370 $link = ''; 1371 if ( is_wp_error($rss) ) { 1372 $error = $rss->get_error_message(); 1373 } else { 1374 $link = esc_url(strip_tags($rss->get_permalink())); 1375 while ( stristr($link, 'http') != $link ) 1376 $link = substr($link, 1); 1377 1378 $rss->__destruct(); 1379 unset($rss); 1380 } 1381 } 1382 1383 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); 1384 } 1385 1386 /** 1387 * Tag cloud widget class 1388 * 1389 * @since 2.8.0 1390 */ 1391 class WP_Widget_Tag_Cloud extends WP_Widget { 1392 1393 public function __construct() { 1394 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") ); 1395 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops); 1396 } 1397 1398 /** 1399 * @param array $args 1400 * @param array $instance 1401 */ 1402 public function widget( $args, $instance ) { 1403 $current_taxonomy = $this->_get_current_taxonomy($instance); 1404 if ( !empty($instance['title']) ) { 1405 $title = $instance['title']; 1406 } else { 1407 if ( 'post_tag' == $current_taxonomy ) { 1408 $title = __('Tags'); 1409 } else { 1410 $tax = get_taxonomy($current_taxonomy); 1411 $title = $tax->labels->name; 1412 } 1413 } 1414 1415 /** This filter is documented in wp-includes/default-widgets.php */ 1416 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 1417 1418 echo $args['before_widget']; 1419 if ( $title ) { 1420 echo $args['before_title'] . $title . $args['after_title']; 1421 } 1422 echo '<div class="tagcloud">'; 1423 1424 /** 1425 * Filter the taxonomy used in the Tag Cloud widget. 1426 * 1427 * @since 2.8.0 1428 * @since 3.0.0 Added taxonomy drop-down. 1429 * 1430 * @see wp_tag_cloud() 1431 * 1432 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'. 1433 */ 1434 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 1435 'taxonomy' => $current_taxonomy 1436 ) ) ); 1437 1438 echo "</div>\n"; 1439 echo $args['after_widget']; 1440 } 1441 1442 /** 1443 * @param array $new_instance 1444 * @param array $old_instance 1445 * @return array 1446 */ 1447 public function update( $new_instance, $old_instance ) { 1448 $instance = array(); 1449 $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) ); 1450 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']); 1451 return $instance; 1452 } 1453 1454 /** 1455 * @param array $instance 1456 */ 1457 public function form( $instance ) { 1458 $current_taxonomy = $this->_get_current_taxonomy($instance); 1459 $title = isset( $instance['title'] ) ? $instance['title'] : ''; 1460 ?> 1461 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label> 1462 <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 ); ?>" /></p> 1463 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label> 1464 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>"> 1465 <?php foreach ( get_taxonomies() as $taxonomy ) : 1466 $tax = get_taxonomy($taxonomy); 1467 if ( !$tax->show_tagcloud || empty($tax->labels->name) ) 1468 continue; 1469 ?> 1470 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo esc_attr( $tax->labels->name ); ?></option> 1471 <?php endforeach; ?> 1472 </select></p><?php 1473 } 1474 1475 /** 1476 * @param array $instance 1477 * @return string 1478 */ 1479 public function _get_current_taxonomy($instance) { 1480 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) 1481 return $instance['taxonomy']; 1482 1483 return 'post_tag'; 1484 } 1485 } 1486 1487 /** 1488 * Navigation Menu widget class 1489 * 1490 * @since 3.0.0 1491 */ 1492 class WP_Nav_Menu_Widget extends WP_Widget { 1493 1494 public function __construct() { 1495 $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') ); 1496 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops ); 1497 } 1498 1499 /** 1500 * @param array $args 1501 * @param array $instance 1502 */ 1503 public function widget( $args, $instance ) { 1504 // Get menu 1505 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; 1506 1507 if ( !$nav_menu ) 1508 return; 1509 1510 /** This filter is documented in wp-includes/default-widgets.php */ 1511 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 1512 1513 echo $args['before_widget']; 1514 1515 if ( !empty($instance['title']) ) 1516 echo $args['before_title'] . $instance['title'] . $args['after_title']; 1517 1518 $nav_menu_args = array( 1519 'fallback_cb' => '', 1520 'menu' => $nav_menu 1521 ); 1522 1523 /** 1524 * Filter the arguments for the Custom Menu widget. 1525 * 1526 * @since 4.2.0 1527 * 1528 * @param array $nav_menu_args { 1529 * An array of arguments passed to wp_nav_menu() to retrieve a custom menu. 1530 * 1531 * @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty. 1532 * @type mixed $menu Menu ID, slug, or name. 1533 * } 1534 * @param stdClass $nav_menu Nav menu object for the current menu. 1535 * @param array $args Display arguments for the current widget. 1536 */ 1537 wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) ); 1538 1539 echo $args['after_widget']; 1540 } 1541 1542 /** 1543 * @param array $new_instance 1544 * @param array $old_instance 1545 * @return array 1546 */ 1547 public function update( $new_instance, $old_instance ) { 1548 $instance = array(); 1549 if ( ! empty( $new_instance['title'] ) ) { 1550 $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) ); 1551 } 1552 if ( ! empty( $new_instance['nav_menu'] ) ) { 1553 $instance['nav_menu'] = (int) $new_instance['nav_menu']; 1554 } 1555 return $instance; 1556 } 1557 1558 /** 1559 * @param array $instance 1560 */ 1561 public function form( $instance ) { 1562 $title = isset( $instance['title'] ) ? $instance['title'] : ''; 1563 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; 1564 1565 // Get menus 1566 $menus = wp_get_nav_menus(); 1567 1568 // If no menus exists, direct the user to go and create some. 1569 ?> 1570 <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>> 1571 <?php 1572 if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) { 1573 $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();'; 1574 } else { 1575 $url = admin_url( 'nav-menus.php' ); 1576 } 1577 ?> 1578 <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?> 1579 </p> 1580 <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>> 1581 <p> 1582 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label> 1583 <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 ); ?>"/> 1584 </p> 1585 <p> 1586 <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label> 1587 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>"> 1588 <option value="0"><?php _e( '— Select —' ); ?></option> 1589 <?php foreach ( $menus as $menu ) : ?> 1590 <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>> 1591 <?php echo esc_html( $menu->name ); ?> 1592 </option> 1593 <?php endforeach; ?> 1594 </select> 1595 </p> 1596 </div> 1597 <?php 1598 } 1599 } 1600 1601 /** 1602 * Register all of the default WordPress widgets on startup. 1603 * 1604 * Calls 'widgets_init' action after all of the WordPress widgets have been 1605 * registered. 1606 * 1607 * @since 2.2.0 1608 */ 1609 function wp_widgets_init() { 1610 if ( !is_blog_installed() ) 1611 return; 1612 1613 register_widget('WP_Widget_Pages'); 1614 1615 register_widget('WP_Widget_Calendar'); 1616 1617 register_widget('WP_Widget_Archives'); 1618 1619 if ( get_option( 'link_manager_enabled' ) ) 1620 register_widget('WP_Widget_Links'); 1621 1622 register_widget('WP_Widget_Meta'); 1623 1624 register_widget('WP_Widget_Search'); 1625 1626 register_widget('WP_Widget_Text'); 1627 1628 register_widget('WP_Widget_Categories'); 1629 1630 register_widget('WP_Widget_Recent_Posts'); 1631 1632 register_widget('WP_Widget_Recent_Comments'); 1633 1634 register_widget('WP_Widget_RSS'); 1635 1636 register_widget('WP_Widget_Tag_Cloud'); 1637 1638 register_widget('WP_Nav_Menu_Widget'); 1639 1640 /** 1641 * Fires after all default WordPress widgets have been registered. 1642 * 1643 * @since 2.2.0 1644 */ 1645 do_action( 'widgets_init' ); 1646 } 9 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-pages.php' ); 10 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-links.php' ); 11 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-search.php' ); 12 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-archives.php' ); 13 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-meta.php' ); 14 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-calendar.php' ); 15 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-text.php' ); 16 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-categories.php' ); 17 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-posts.php' ); 18 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-comments.php' ); 19 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-rss.php' ); 20 require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-tag-cloud.php' ); 21 require_once( ABSPATH . WPINC . '/widgets/class-wp-nav-menu-widget.php' ); -
src/wp-includes/widget-functions.php
1095 1095 1096 1096 return $sidebars_widgets; 1097 1097 } 1098 1099 /** 1100 * Display the RSS entries in a list. 1101 * 1102 * @since 2.5.0 1103 * 1104 * @param string|array|object $rss RSS url. 1105 * @param array $args Widget arguments. 1106 */ 1107 function wp_widget_rss_output( $rss, $args = array() ) { 1108 if ( is_string( $rss ) ) { 1109 $rss = fetch_feed($rss); 1110 } elseif ( is_array($rss) && isset($rss['url']) ) { 1111 $args = $rss; 1112 $rss = fetch_feed($rss['url']); 1113 } elseif ( !is_object($rss) ) { 1114 return; 1115 } 1116 1117 if ( is_wp_error($rss) ) { 1118 if ( is_admin() || current_user_can('manage_options') ) 1119 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; 1120 return; 1121 } 1122 1123 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); 1124 $args = wp_parse_args( $args, $default_args ); 1125 1126 $items = (int) $args['items']; 1127 if ( $items < 1 || 20 < $items ) 1128 $items = 10; 1129 $show_summary = (int) $args['show_summary']; 1130 $show_author = (int) $args['show_author']; 1131 $show_date = (int) $args['show_date']; 1132 1133 if ( !$rss->get_item_quantity() ) { 1134 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; 1135 $rss->__destruct(); 1136 unset($rss); 1137 return; 1138 } 1139 1140 echo '<ul>'; 1141 foreach ( $rss->get_items( 0, $items ) as $item ) { 1142 $link = $item->get_link(); 1143 while ( stristr( $link, 'http' ) != $link ) { 1144 $link = substr( $link, 1 ); 1145 } 1146 $link = esc_url( strip_tags( $link ) ); 1147 1148 $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); 1149 if ( empty( $title ) ) { 1150 $title = __( 'Untitled' ); 1151 } 1152 1153 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); 1154 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); 1155 1156 $summary = ''; 1157 if ( $show_summary ) { 1158 $summary = $desc; 1159 1160 // Change existing [...] to […]. 1161 if ( '[...]' == substr( $summary, -5 ) ) { 1162 $summary = substr( $summary, 0, -5 ) . '[…]'; 1163 } 1164 1165 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; 1166 } 1167 1168 $date = ''; 1169 if ( $show_date ) { 1170 $date = $item->get_date( 'U' ); 1171 1172 if ( $date ) { 1173 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; 1174 } 1175 } 1176 1177 $author = ''; 1178 if ( $show_author ) { 1179 $author = $item->get_author(); 1180 if ( is_object($author) ) { 1181 $author = $author->get_name(); 1182 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; 1183 } 1184 } 1185 1186 if ( $link == '' ) { 1187 echo "<li>$title{$date}{$summary}{$author}</li>"; 1188 } elseif ( $show_summary ) { 1189 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; 1190 } else { 1191 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; 1192 } 1193 } 1194 echo '</ul>'; 1195 $rss->__destruct(); 1196 unset($rss); 1197 } 1198 1199 /** 1200 * Display RSS widget options form. 1201 * 1202 * The options for what fields are displayed for the RSS form are all booleans 1203 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', 1204 * 'show_date'. 1205 * 1206 * @since 2.5.0 1207 * 1208 * @param array|string $args Values for input fields. 1209 * @param array $inputs Override default display options. 1210 */ 1211 function wp_widget_rss_form( $args, $inputs = null ) { 1212 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); 1213 $inputs = wp_parse_args( $inputs, $default_inputs ); 1214 1215 $args['title'] = isset( $args['title'] ) ? $args['title'] : ''; 1216 $args['url'] = isset( $args['url'] ) ? $args['url'] : ''; 1217 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0; 1218 1219 if ( $args['items'] < 1 || 20 < $args['items'] ) { 1220 $args['items'] = 10; 1221 } 1222 1223 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; 1224 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; 1225 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; 1226 1227 if ( ! empty( $args['error'] ) ) { 1228 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>'; 1229 } 1230 1231 $esc_number = esc_attr( $args['number'] ); 1232 if ( $inputs['url'] ) : 1233 ?> 1234 <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label> 1235 <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p> 1236 <?php endif; if ( $inputs['title'] ) : ?> 1237 <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label> 1238 <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr( $args['title'] ); ?>" /></p> 1239 <?php endif; if ( $inputs['items'] ) : ?> 1240 <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e( 'How many items would you like to display?' ); ?></label> 1241 <select id="rss-items-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][items]"> 1242 <?php 1243 for ( $i = 1; $i <= 20; ++$i ) { 1244 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; 1245 } 1246 ?> 1247 </select></p> 1248 <?php endif; if ( $inputs['show_summary'] ) : ?> 1249 <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> 1250 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p> 1251 <?php endif; if ( $inputs['show_author'] ) : ?> 1252 <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> 1253 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p> 1254 <?php endif; if ( $inputs['show_date'] ) : ?> 1255 <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> 1256 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p> 1257 <?php 1258 endif; 1259 foreach ( array_keys($default_inputs) as $input ) : 1260 if ( 'hidden' === $inputs[$input] ) : 1261 $id = str_replace( '_', '-', $input ); 1262 ?> 1263 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" /> 1264 <?php 1265 endif; 1266 endforeach; 1267 } 1268 1269 /** 1270 * Process RSS feed widget data and optionally retrieve feed items. 1271 * 1272 * The feed widget can not have more than 20 items or it will reset back to the 1273 * default, which is 10. 1274 * 1275 * The resulting array has the feed title, feed url, feed link (from channel), 1276 * feed items, error (if any), and whether to show summary, author, and date. 1277 * All respectively in the order of the array elements. 1278 * 1279 * @since 2.5.0 1280 * 1281 * @param array $widget_rss RSS widget feed data. Expects unescaped data. 1282 * @param bool $check_feed Optional, default is true. Whether to check feed for errors. 1283 * @return array 1284 */ 1285 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 1286 $items = (int) $widget_rss['items']; 1287 if ( $items < 1 || 20 < $items ) 1288 $items = 10; 1289 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); 1290 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; 1291 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; 1292 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0; 1293 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; 1294 1295 if ( $check_feed ) { 1296 $rss = fetch_feed($url); 1297 $error = false; 1298 $link = ''; 1299 if ( is_wp_error($rss) ) { 1300 $error = $rss->get_error_message(); 1301 } else { 1302 $link = esc_url(strip_tags($rss->get_permalink())); 1303 while ( stristr($link, 'http') != $link ) 1304 $link = substr($link, 1); 1305 1306 $rss->__destruct(); 1307 unset($rss); 1308 } 1309 } 1310 1311 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); 1312 } 1313 1314 /** 1315 * Register all of the default WordPress widgets on startup. 1316 * 1317 * Calls 'widgets_init' action after all of the WordPress widgets have been 1318 * registered. 1319 * 1320 * @since 2.2.0 1321 */ 1322 function wp_widgets_init() { 1323 if ( !is_blog_installed() ) 1324 return; 1325 1326 register_widget('WP_Widget_Pages'); 1327 1328 register_widget('WP_Widget_Calendar'); 1329 1330 register_widget('WP_Widget_Archives'); 1331 1332 if ( get_option( 'link_manager_enabled' ) ) 1333 register_widget('WP_Widget_Links'); 1334 1335 register_widget('WP_Widget_Meta'); 1336 1337 register_widget('WP_Widget_Search'); 1338 1339 register_widget('WP_Widget_Text'); 1340 1341 register_widget('WP_Widget_Categories'); 1342 1343 register_widget('WP_Widget_Recent_Posts'); 1344 1345 register_widget('WP_Widget_Recent_Comments'); 1346 1347 register_widget('WP_Widget_RSS'); 1348 1349 register_widget('WP_Widget_Tag_Cloud'); 1350 1351 register_widget('WP_Nav_Menu_Widget'); 1352 1353 /** 1354 * Fires after all default WordPress widgets have been registered. 1355 * 1356 * @since 2.2.0 1357 */ 1358 do_action( 'widgets_init' ); 1359 } -
src/wp-includes/widgets/class-wp-nav-menu-widget.php
1 1 <?php 2 2 /** 3 * Default Widgets3 * Navigation Menu widget class 4 4 * 5 * @since 3.0.0 5 6 * @package WordPress 6 7 * @subpackage Widgets 7 8 */ 8 9 /**10 * Pages widget class11 *12 * @since 2.8.013 */14 class WP_Widget_Pages extends WP_Widget {15 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);19 }20 21 /**22 * @param array $args23 * @param array $instance24 */25 public function widget( $args, $instance ) {26 27 /**28 * Filter the widget title.29 *30 * @since 2.6.031 *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.35 */36 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );37 38 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];39 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];40 41 if ( $sortby == 'menu_order' )42 $sortby = 'menu_order, post_title';43 44 /**45 * Filter the arguments for the Pages widget.46 *47 * @since 2.8.048 *49 * @see wp_list_pages()50 *51 * @param array $args An array of arguments to retrieve the pages list.52 */53 $out = wp_list_pages( apply_filters( 'widget_pages_args', array(54 'title_li' => '',55 'echo' => 0,56 'sort_column' => $sortby,57 'exclude' => $exclude58 ) ) );59 60 if ( ! empty( $out ) ) {61 echo $args['before_widget'];62 if ( $title ) {63 echo $args['before_title'] . $title . $args['after_title'];64 }65 ?>66 <ul>67 <?php echo $out; ?>68 </ul>69 <?php70 echo $args['after_widget'];71 }72 }73 74 /**75 * @param array $new_instance76 * @param array $old_instance77 * @return array78 */79 public function update( $new_instance, $old_instance ) {80 $instance = $old_instance;81 $instance['title'] = sanitize_text_field( $new_instance['title'] );82 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {83 $instance['sortby'] = $new_instance['sortby'];84 } else {85 $instance['sortby'] = 'menu_order';86 }87 88 $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );89 90 return $instance;91 }92 93 /**94 * @param array $instance95 */96 public function form( $instance ) {97 //Defaults98 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );99 ?>100 <p>101 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>102 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />103 </p>104 <p>105 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>106 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">107 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>108 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>109 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>110 </select>111 </p>112 <p>113 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>114 <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" />115 <br />116 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>117 </p>118 <?php119 }120 121 }122 123 /**124 * Links widget class125 *126 * @since 2.8.0127 */128 class WP_Widget_Links extends WP_Widget {129 130 public function __construct() {131 $widget_ops = array('description' => __( "Your blogroll" ) );132 parent::__construct('links', __('Links'), $widget_ops);133 }134 135 /**136 * @param array $args137 * @param array $instance138 */139 public function widget( $args, $instance ) {140 $show_description = isset($instance['description']) ? $instance['description'] : false;141 $show_name = isset($instance['name']) ? $instance['name'] : false;142 $show_rating = isset($instance['rating']) ? $instance['rating'] : false;143 $show_images = isset($instance['images']) ? $instance['images'] : true;144 $category = isset($instance['category']) ? $instance['category'] : false;145 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';146 $order = $orderby == 'rating' ? 'DESC' : 'ASC';147 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;148 149 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );150 151 /**152 * Filter the arguments for the Links widget.153 *154 * @since 2.6.0155 *156 * @see wp_list_bookmarks()157 *158 * @param array $args An array of arguments to retrieve the links list.159 */160 wp_list_bookmarks( apply_filters( 'widget_links_args', array(161 'title_before' => $args['before_title'], 'title_after' => $args['after_title'],162 'category_before' => $before_widget, 'category_after' => $args['after_widget'],163 'show_images' => $show_images, 'show_description' => $show_description,164 'show_name' => $show_name, 'show_rating' => $show_rating,165 'category' => $category, 'class' => 'linkcat widget',166 'orderby' => $orderby, 'order' => $order,167 'limit' => $limit,168 ) ) );169 }170 171 /**172 * @param array $new_instance173 * @param array $old_instance174 * @return array175 */176 public function update( $new_instance, $old_instance ) {177 $new_instance = (array) $new_instance;178 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );179 foreach ( $instance as $field => $val ) {180 if ( isset($new_instance[$field]) )181 $instance[$field] = 1;182 }183 184 $instance['orderby'] = 'name';185 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )186 $instance['orderby'] = $new_instance['orderby'];187 188 $instance['category'] = intval( $new_instance['category'] );189 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;190 191 return $instance;192 }193 194 /**195 * @param array $instance196 */197 public function form( $instance ) {198 199 //Defaults200 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );201 $link_cats = get_terms( 'link_category' );202 if ( ! $limit = intval( $instance['limit'] ) )203 $limit = -1;204 ?>205 <p>206 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>207 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">208 <option value=""><?php _ex('All Links', 'links widget'); ?></option>209 <?php210 foreach ( $link_cats as $link_cat ) {211 echo '<option value="' . intval( $link_cat->term_id ) . '"'212 . selected( $instance['category'], $link_cat->term_id, false )213 . '>' . $link_cat->name . "</option>\n";214 }215 ?>216 </select>217 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>218 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">219 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>220 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>221 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>222 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>223 </select>224 </p>225 <p>226 <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'); ?>" />227 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />228 <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'); ?>" />229 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />230 <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'); ?>" />231 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />232 <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'); ?>" />233 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>234 </p>235 <p>236 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>237 <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" />238 </p>239 <?php240 }241 }242 243 /**244 * Search widget class245 *246 * @since 2.8.0247 */248 class WP_Widget_Search extends WP_Widget {249 250 public function __construct() {251 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );252 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );253 }254 255 /**256 * @param array $args257 * @param array $instance258 */259 public function widget( $args, $instance ) {260 /** This filter is documented in wp-includes/default-widgets.php */261 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );262 263 echo $args['before_widget'];264 if ( $title ) {265 echo $args['before_title'] . $title . $args['after_title'];266 }267 268 // Use current theme search form if it exists269 get_search_form();270 271 echo $args['after_widget'];272 }273 274 /**275 * @param array $instance276 */277 public function form( $instance ) {278 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );279 $title = $instance['title'];280 ?>281 <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>282 <?php283 }284 285 /**286 * @param array $new_instance287 * @param array $old_instance288 * @return array289 */290 public function update( $new_instance, $old_instance ) {291 $instance = $old_instance;292 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));293 $instance['title'] = sanitize_text_field( $new_instance['title'] );294 return $instance;295 }296 297 }298 299 /**300 * Archives widget class301 *302 * @since 2.8.0303 */304 class WP_Widget_Archives extends WP_Widget {305 306 public function __construct() {307 $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') );308 parent::__construct('archives', __('Archives'), $widget_ops);309 }310 311 /**312 * @param array $args313 * @param array $instance314 */315 public function widget( $args, $instance ) {316 $c = ! empty( $instance['count'] ) ? '1' : '0';317 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';318 319 /** This filter is documented in wp-includes/default-widgets.php */320 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );321 322 echo $args['before_widget'];323 if ( $title ) {324 echo $args['before_title'] . $title . $args['after_title'];325 }326 327 if ( $d ) {328 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";329 ?>330 <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>331 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>332 <?php333 /**334 * Filter the arguments for the Archives widget drop-down.335 *336 * @since 2.8.0337 *338 * @see wp_get_archives()339 *340 * @param array $args An array of Archives widget drop-down arguments.341 */342 $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(343 'type' => 'monthly',344 'format' => 'option',345 'show_post_count' => $c346 ) );347 348 switch ( $dropdown_args['type'] ) {349 case 'yearly':350 $label = __( 'Select Year' );351 break;352 case 'monthly':353 $label = __( 'Select Month' );354 break;355 case 'daily':356 $label = __( 'Select Day' );357 break;358 case 'weekly':359 $label = __( 'Select Week' );360 break;361 default:362 $label = __( 'Select Post' );363 break;364 }365 ?>366 367 <option value=""><?php echo esc_attr( $label ); ?></option>368 <?php wp_get_archives( $dropdown_args ); ?>369 370 </select>371 <?php372 } else {373 ?>374 <ul>375 <?php376 /**377 * Filter the arguments for the Archives widget.378 *379 * @since 2.8.0380 *381 * @see wp_get_archives()382 *383 * @param array $args An array of Archives option arguments.384 */385 wp_get_archives( apply_filters( 'widget_archives_args', array(386 'type' => 'monthly',387 'show_post_count' => $c388 ) ) );389 ?>390 </ul>391 <?php392 }393 394 echo $args['after_widget'];395 }396 397 /**398 * @param array $new_instance399 * @param array $old_instance400 * @return array401 */402 public function update( $new_instance, $old_instance ) {403 $instance = $old_instance;404 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );405 $instance['title'] = sanitize_text_field( $new_instance['title'] );406 $instance['count'] = $new_instance['count'] ? 1 : 0;407 $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;408 409 return $instance;410 }411 412 /**413 * @param array $instance414 */415 public function form( $instance ) {416 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );417 $title = sanitize_text_field( $instance['title'] );418 ?>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>420 <p>421 <input class="checkbox" type="checkbox" <?php checked( $instance['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>422 <br/>423 <input class="checkbox" type="checkbox" <?php checked( $instance['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>424 </p>425 <?php426 }427 }428 429 /**430 * Meta widget class431 *432 * Displays log in/out, RSS feed links, etc.433 *434 * @since 2.8.0435 */436 class WP_Widget_Meta extends WP_Widget {437 438 public function __construct() {439 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") );440 parent::__construct('meta', __('Meta'), $widget_ops);441 }442 443 /**444 * @param array $args445 * @param array $instance446 */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 );450 451 echo $args['before_widget'];452 if ( $title ) {453 echo $args['before_title'] . $title . $args['after_title'];454 }455 ?>456 <ul>457 <?php wp_register(); ?>458 <li><?php wp_loginout(); ?></li>459 <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>460 <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>461 <?php462 /**463 * Filter the "Powered by WordPress" text in the Meta widget.464 *465 * @since 3.6.0466 *467 * @param string $title_text Default title text for the WordPress.org link.468 */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' )473 ) );474 475 wp_meta();476 ?>477 </ul>478 <?php479 echo $args['after_widget'];480 }481 482 /**483 * @param array $new_instance484 * @param array $old_instance485 * @return array486 */487 public function update( $new_instance, $old_instance ) {488 $instance = $old_instance;489 $instance['title'] = sanitize_text_field( $new_instance['title'] );490 491 return $instance;492 }493 494 /**495 * @param array $instance496 */497 public function form( $instance ) {498 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );499 $title = sanitize_text_field( $instance['title'] );500 ?>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>502 <?php503 }504 }505 506 /**507 * Calendar widget class508 *509 * @since 2.8.0510 */511 class WP_Widget_Calendar extends WP_Widget {512 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);516 }517 518 /**519 * @param array $args520 * @param array $instance521 */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 );525 526 echo $args['before_widget'];527 if ( $title ) {528 echo $args['before_title'] . $title . $args['after_title'];529 }530 echo '<div id="calendar_wrap">';531 get_calendar();532 echo '</div>';533 echo $args['after_widget'];534 }535 536 /**537 * @param array $new_instance538 * @param array $old_instance539 * @return array540 */541 public function update( $new_instance, $old_instance ) {542 $instance = $old_instance;543 $instance['title'] = sanitize_text_field( $new_instance['title'] );544 545 return $instance;546 }547 548 /**549 * @param array $instance550 */551 public function form( $instance ) {552 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );553 $title = sanitize_text_field( $instance['title'] );554 ?>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>557 <?php558 }559 }560 561 /**562 * Text widget class563 *564 * @since 2.8.0565 */566 class WP_Widget_Text extends WP_Widget {567 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);572 }573 574 /**575 * @param array $args576 * @param array $instance577 */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 );581 582 /**583 * Filter the content of the Text widget.584 *585 * @since 2.3.0586 *587 * @param string $widget_text The widget content.588 * @param WP_Widget $instance WP_Widget instance.589 */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'];594 } ?>595 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>596 <?php597 echo $args['after_widget'];598 }599 600 /**601 * @param array $new_instance602 * @param array $old_instance603 * @return array604 */605 public function update( $new_instance, $old_instance ) {606 $instance = $old_instance;607 $instance['title'] = sanitize_text_field( $new_instance['title'] );608 if ( current_user_can('unfiltered_html') )609 $instance['text'] = $new_instance['text'];610 else611 $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) );612 $instance['filter'] = ! empty( $new_instance['filter'] );613 return $instance;614 }615 616 /**617 * @param array $instance618 */619 public function form( $instance ) {620 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );621 $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;622 $title = sanitize_text_field( $instance['title'] );623 ?>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>626 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 esc_textarea( $instance['text'] ); ?></textarea></p>629 630 <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked( $filter ); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>631 <?php632 }633 }634 635 /**636 * Categories widget class637 *638 * @since 2.8.0639 */640 class WP_Widget_Categories extends WP_Widget {641 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);645 }646 647 /**648 * @staticvar bool $first_dropdown649 *650 * @param array $args651 * @param array $instance652 */653 public function widget( $args, $instance ) {654 static $first_dropdown = true;655 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 );658 659 $c = ! empty( $instance['count'] ) ? '1' : '0';660 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';661 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';662 663 echo $args['before_widget'];664 if ( $title ) {665 echo $args['before_title'] . $title . $args['after_title'];666 }667 668 $cat_args = array(669 'orderby' => 'name',670 'show_count' => $c,671 'hierarchical' => $h672 );673 674 if ( $d ) {675 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";676 $first_dropdown = false;677 678 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';679 680 $cat_args['show_option_none'] = __( 'Select Category' );681 $cat_args['id'] = $dropdown_id;682 683 /**684 * Filter the arguments for the Categories widget drop-down.685 *686 * @since 2.8.0687 *688 * @see wp_dropdown_categories()689 *690 * @param array $cat_args An array of Categories widget drop-down arguments.691 */692 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );693 ?>694 695 <script type='text/javascript'>696 /* <![CDATA[ */697 (function() {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;702 }703 }704 dropdown.onchange = onCatChange;705 })();706 /* ]]> */707 </script>708 709 <?php710 } else {711 ?>712 <ul>713 <?php714 $cat_args['title_li'] = '';715 716 /**717 * Filter the arguments for the Categories widget.718 *719 * @since 2.8.0720 *721 * @param array $cat_args An array of Categories widget options.722 */723 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );724 ?>725 </ul>726 <?php727 }728 729 echo $args['after_widget'];730 }731 732 /**733 * @param array $new_instance734 * @param array $old_instance735 * @return array736 */737 public function update( $new_instance, $old_instance ) {738 $instance = $old_instance;739 $instance['title'] = sanitize_text_field( $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;743 744 return $instance;745 }746 747 /**748 * @param array $instance749 */750 public function form( $instance ) {751 //Defaults752 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );753 $title = sanitize_text_field( $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;757 ?>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 esc_attr( $title ); ?>" /></p>760 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 />763 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 />766 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>769 <?php770 }771 772 }773 774 /**775 * Recent_Posts widget class776 *777 * @since 2.8.0778 */779 class WP_Widget_Recent_Posts extends WP_Widget {780 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';785 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') );789 }790 791 /**792 * @param array $args793 * @param array $instance794 */795 public function widget( $args, $instance ) {796 $cache = array();797 if ( ! $this->is_preview() ) {798 $cache = wp_cache_get( 'widget_recent_posts', 'widget' );799 }800 801 if ( ! is_array( $cache ) ) {802 $cache = array();803 }804 805 if ( ! isset( $args['widget_id'] ) ) {806 $args['widget_id'] = $this->id;807 }808 809 if ( isset( $cache[ $args['widget_id'] ] ) ) {810 echo $cache[ $args['widget_id'] ];811 return;812 }813 814 ob_start();815 816 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );817 818 /** This filter is documented in wp-includes/default-widgets.php */819 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );820 821 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;822 if ( ! $number )823 $number = 5;824 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;825 826 /**827 * Filter the arguments for the Recent Posts widget.828 *829 * @since 3.4.0830 *831 * @see WP_Query::get_posts()832 *833 * @param array $args An array of arguments used to retrieve the recent posts.834 */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' => true840 ) ) );841 842 if ($r->have_posts()) :843 ?>844 <?php echo $args['before_widget']; ?>845 <?php if ( $title ) {846 echo $args['before_title'] . $title . $args['after_title'];847 } ?>848 <ul>849 <?php while ( $r->have_posts() ) : $r->the_post(); ?>850 <li>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>854 <?php endif; ?>855 </li>856 <?php endwhile; ?>857 </ul>858 <?php echo $args['after_widget']; ?>859 <?php860 // Reset the global $the_post as this query will have stomped on it861 wp_reset_postdata();862 863 endif;864 865 if ( ! $this->is_preview() ) {866 $cache[ $args['widget_id'] ] = ob_get_flush();867 wp_cache_set( 'widget_recent_posts', $cache, 'widget' );868 } else {869 ob_end_flush();870 }871 }872 873 /**874 * @param array $new_instance875 * @param array $old_instance876 * @return array877 */878 public function update( $new_instance, $old_instance ) {879 $instance = $old_instance;880 $instance['title'] = santize_text_field( $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();884 885 $alloptions = wp_cache_get( 'alloptions', 'options' );886 if ( isset($alloptions['widget_recent_entries']) )887 delete_option('widget_recent_entries');888 889 return $instance;890 }891 892 /**893 * @access public894 */895 public function flush_widget_cache() {896 wp_cache_delete('widget_recent_posts', 'widget');897 }898 899 /**900 * @param array $instance901 */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;906 ?>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>909 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>912 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>915 <?php916 }917 }918 919 /**920 * Recent_Comments widget class921 *922 * @since 2.8.0923 */924 class WP_Widget_Recent_Comments extends WP_Widget {925 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';930 931 if ( is_active_widget(false, false, $this->id_base) )932 add_action( 'wp_head', array($this, 'recent_comments_style') );933 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') );937 }938 939 /**940 * @access public941 */942 public function recent_comments_style() {943 /**944 * Filter the Recent Comments default widget styles.945 *946 * @since 3.1.0947 *948 * @param bool $active Whether the widget is active. Default true.949 * @param string $id_base The widget ID.950 */951 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876952 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )953 return;954 ?>955 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>956 <?php957 }958 959 /**960 * @access public961 */962 public function flush_widget_cache() {963 wp_cache_delete('widget_recent_comments', 'widget');964 }965 966 /**967 * @param array $args968 * @param array $instance969 */970 public function widget( $args, $instance ) {971 $cache = array();972 if ( ! $this->is_preview() ) {973 $cache = wp_cache_get('widget_recent_comments', 'widget');974 }975 if ( ! is_array( $cache ) ) {976 $cache = array();977 }978 979 if ( ! isset( $args['widget_id'] ) )980 $args['widget_id'] = $this->id;981 982 if ( isset( $cache[ $args['widget_id'] ] ) ) {983 echo $cache[ $args['widget_id'] ];984 return;985 }986 987 $output = '';988 989 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );990 991 /** This filter is documented in wp-includes/default-widgets.php */992 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );993 994 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;995 if ( ! $number )996 $number = 5;997 998 /**999 * Filter the arguments for the Recent Comments widget.1000 *1001 * @since 3.4.01002 *1003 * @see WP_Comment_Query::query() for information on accepted arguments.1004 *1005 * @param array $comment_args An array of arguments used to retrieve the recent comments.1006 */1007 $comments = get_comments( apply_filters( 'widget_comments_args', array(1008 'number' => $number,1009 'status' => 'approve',1010 'post_status' => 'publish'1011 ) ) );1012 1013 $output .= $args['before_widget'];1014 if ( $title ) {1015 $output .= $args['before_title'] . $title . $args['after_title'];1016 }1017 1018 $output .= '<ul id="recentcomments">';1019 if ( is_array( $comments ) && $comments ) {1020 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)1021 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );1022 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );1023 1024 foreach ( (array) $comments as $comment ) {1025 $output .= '<li class="recentcomments">';1026 /* translators: comments widget: 1: comment author, 2: post link */1027 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),1028 '<span class="comment-author-link">' . get_comment_author_link( $comment->comment_ID ) . '</span>',1029 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'1030 );1031 $output .= '</li>';1032 }1033 }1034 $output .= '</ul>';1035 $output .= $args['after_widget'];1036 1037 echo $output;1038 1039 if ( ! $this->is_preview() ) {1040 $cache[ $args['widget_id'] ] = $output;1041 wp_cache_set( 'widget_recent_comments', $cache, 'widget' );1042 }1043 }1044 1045 /**1046 * @param array $new_instance1047 * @param array $old_instance1048 * @return array1049 */1050 public function update( $new_instance, $old_instance ) {1051 $instance = $old_instance;1052 $instance['title'] = sanitize_text_field( $new_instance['title'] );1053 $instance['number'] = absint( $new_instance['number'] );1054 $this->flush_widget_cache();1055 1056 $alloptions = wp_cache_get( 'alloptions', 'options' );1057 if ( isset($alloptions['widget_recent_comments']) )1058 delete_option('widget_recent_comments');1059 1060 return $instance;1061 }1062 1063 /**1064 * @param array $instance1065 */1066 public function form( $instance ) {1067 $title = isset( $instance['title'] ) ? $instance['title'] : '';1068 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;1069 ?>1070 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>1071 <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>1072 1073 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>1074 <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>1075 <?php1076 }1077 }1078 1079 /**1080 * RSS widget class1081 *1082 * @since 2.8.01083 */1084 class WP_Widget_RSS extends WP_Widget {1085 1086 public function __construct() {1087 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );1088 $control_ops = array( 'width' => 400, 'height' => 200 );1089 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );1090 }1091 1092 /**1093 * @param array $args1094 * @param array $instance1095 */1096 public function widget( $args, $instance ) {1097 if ( isset($instance['error']) && $instance['error'] )1098 return;1099 1100 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';1101 while ( stristr($url, 'http') != $url )1102 $url = substr($url, 1);1103 1104 if ( empty($url) )1105 return;1106 1107 // self-url destruction sequence1108 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )1109 return;1110 1111 $rss = fetch_feed($url);1112 $title = $instance['title'];1113 $desc = '';1114 $link = '';1115 1116 if ( ! is_wp_error($rss) ) {1117 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));1118 if ( empty($title) )1119 $title = strip_tags( $rss->get_title() );1120 $link = strip_tags( $rss->get_permalink() );1121 while ( stristr($link, 'http') != $link )1122 $link = substr($link, 1);1123 }1124 1125 if ( empty($title) )1126 $title = empty($desc) ? __('Unknown Feed') : $desc;1127 1128 /** This filter is documented in wp-includes/default-widgets.php */1129 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );1130 1131 $url = strip_tags( $url );1132 $icon = includes_url( 'images/rss.png' );1133 if ( $title )1134 $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">"'. esc_html( $title ) .'"</a>';1135 1136 echo $args['before_widget'];1137 if ( $title ) {1138 echo $args['before_title'] . $title . $args['after_title'];1139 }1140 wp_widget_rss_output( $rss, $instance );1141 echo $args['after_widget'];1142 1143 if ( ! is_wp_error($rss) )1144 $rss->__destruct();1145 unset($rss);1146 }1147 1148 /**1149 * @param array $new_instance1150 * @param array $old_instance1151 * @return array1152 */1153 public function update( $new_instance, $old_instance ) {1154 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );1155 return wp_widget_rss_process( $new_instance, $testurl );1156 }1157 1158 /**1159 * @param array $instance1160 */1161 public function form( $instance ) {1162 if ( empty( $instance ) ) {1163 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );1164 }1165 $instance['number'] = $this->number;1166 1167 wp_widget_rss_form( $instance );1168 }1169 }1170 1171 /**1172 * Display the RSS entries in a list.1173 *1174 * @since 2.5.01175 *1176 * @param string|array|object $rss RSS url.1177 * @param array $args Widget arguments.1178 */1179 function wp_widget_rss_output( $rss, $args = array() ) {1180 if ( is_string( $rss ) ) {1181 $rss = fetch_feed($rss);1182 } elseif ( is_array($rss) && isset($rss['url']) ) {1183 $args = $rss;1184 $rss = fetch_feed($rss['url']);1185 } elseif ( !is_object($rss) ) {1186 return;1187 }1188 1189 if ( is_wp_error($rss) ) {1190 if ( is_admin() || current_user_can('manage_options') )1191 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';1192 return;1193 }1194 1195 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );1196 $args = wp_parse_args( $args, $default_args );1197 1198 $items = (int) $args['items'];1199 if ( $items < 1 || 20 < $items )1200 $items = 10;1201 $show_summary = (int) $args['show_summary'];1202 $show_author = (int) $args['show_author'];1203 $show_date = (int) $args['show_date'];1204 1205 if ( !$rss->get_item_quantity() ) {1206 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';1207 $rss->__destruct();1208 unset($rss);1209 return;1210 }1211 1212 echo '<ul>';1213 foreach ( $rss->get_items( 0, $items ) as $item ) {1214 $link = $item->get_link();1215 while ( stristr( $link, 'http' ) != $link ) {1216 $link = substr( $link, 1 );1217 }1218 $link = esc_url( strip_tags( $link ) );1219 1220 $title = esc_html( trim( strip_tags( $item->get_title() ) ) );1221 if ( empty( $title ) ) {1222 $title = __( 'Untitled' );1223 }1224 1225 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );1226 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) );1227 1228 $summary = '';1229 if ( $show_summary ) {1230 $summary = $desc;1231 1232 // Change existing [...] to […].1233 if ( '[...]' == substr( $summary, -5 ) ) {1234 $summary = substr( $summary, 0, -5 ) . '[…]';1235 }1236 1237 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';1238 }1239 1240 $date = '';1241 if ( $show_date ) {1242 $date = $item->get_date( 'U' );1243 1244 if ( $date ) {1245 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';1246 }1247 }1248 1249 $author = '';1250 if ( $show_author ) {1251 $author = $item->get_author();1252 if ( is_object($author) ) {1253 $author = $author->get_name();1254 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';1255 }1256 }1257 1258 if ( $link == '' ) {1259 echo "<li>$title{$date}{$summary}{$author}</li>";1260 } elseif ( $show_summary ) {1261 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";1262 } else {1263 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";1264 }1265 }1266 echo '</ul>';1267 $rss->__destruct();1268 unset($rss);1269 }1270 1271 /**1272 * Display RSS widget options form.1273 *1274 * The options for what fields are displayed for the RSS form are all booleans1275 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',1276 * 'show_date'.1277 *1278 * @since 2.5.01279 *1280 * @param array|string $args Values for input fields.1281 * @param array $inputs Override default display options.1282 */1283 function wp_widget_rss_form( $args, $inputs = null ) {1284 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );1285 $inputs = wp_parse_args( $inputs, $default_inputs );1286 1287 $args['title'] = isset( $args['title'] ) ? $args['title'] : '';1288 $args['url'] = isset( $args['url'] ) ? $args['url'] : '';1289 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;1290 1291 if ( $args['items'] < 1 || 20 < $args['items'] ) {1292 $args['items'] = 10;1293 }1294 1295 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];1296 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];1297 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];1298 1299 if ( ! empty( $args['error'] ) ) {1300 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';1301 }1302 1303 $esc_number = esc_attr( $args['number'] );1304 if ( $inputs['url'] ) :1305 ?>1306 <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>1307 <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p>1308 <?php endif; if ( $inputs['title'] ) : ?>1309 <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>1310 <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr( $args['title'] ); ?>" /></p>1311 <?php endif; if ( $inputs['items'] ) : ?>1312 <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>1313 <select id="rss-items-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][items]">1314 <?php1315 for ( $i = 1; $i <= 20; ++$i ) {1316 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";1317 }1318 ?>1319 </select></p>1320 <?php endif; if ( $inputs['show_summary'] ) : ?>1321 <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> />1322 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p>1323 <?php endif; if ( $inputs['show_author'] ) : ?>1324 <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> />1325 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>1326 <?php endif; if ( $inputs['show_date'] ) : ?>1327 <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>1328 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p>1329 <?php1330 endif;1331 foreach ( array_keys($default_inputs) as $input ) :1332 if ( 'hidden' === $inputs[$input] ) :1333 $id = str_replace( '_', '-', $input );1334 ?>1335 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" />1336 <?php1337 endif;1338 endforeach;1339 }1340 1341 /**1342 * Process RSS feed widget data and optionally retrieve feed items.1343 *1344 * The feed widget can not have more than 20 items or it will reset back to the1345 * default, which is 10.1346 *1347 * The resulting array has the feed title, feed url, feed link (from channel),1348 * feed items, error (if any), and whether to show summary, author, and date.1349 * All respectively in the order of the array elements.1350 *1351 * @since 2.5.01352 *1353 * @param array $widget_rss RSS widget feed data. Expects unescaped data.1354 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.1355 * @return array1356 */1357 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {1358 $items = (int) $widget_rss['items'];1359 if ( $items < 1 || 20 < $items )1360 $items = 10;1361 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );1362 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';1363 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;1364 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;1365 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;1366 1367 if ( $check_feed ) {1368 $rss = fetch_feed($url);1369 $error = false;1370 $link = '';1371 if ( is_wp_error($rss) ) {1372 $error = $rss->get_error_message();1373 } else {1374 $link = esc_url(strip_tags($rss->get_permalink()));1375 while ( stristr($link, 'http') != $link )1376 $link = substr($link, 1);1377 1378 $rss->__destruct();1379 unset($rss);1380 }1381 }1382 1383 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );1384 }1385 1386 /**1387 * Tag cloud widget class1388 *1389 * @since 2.8.01390 */1391 class WP_Widget_Tag_Cloud extends WP_Widget {1392 1393 public function __construct() {1394 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );1395 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);1396 }1397 1398 /**1399 * @param array $args1400 * @param array $instance1401 */1402 public function widget( $args, $instance ) {1403 $current_taxonomy = $this->_get_current_taxonomy($instance);1404 if ( !empty($instance['title']) ) {1405 $title = $instance['title'];1406 } else {1407 if ( 'post_tag' == $current_taxonomy ) {1408 $title = __('Tags');1409 } else {1410 $tax = get_taxonomy($current_taxonomy);1411 $title = $tax->labels->name;1412 }1413 }1414 1415 /** This filter is documented in wp-includes/default-widgets.php */1416 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );1417 1418 echo $args['before_widget'];1419 if ( $title ) {1420 echo $args['before_title'] . $title . $args['after_title'];1421 }1422 echo '<div class="tagcloud">';1423 1424 /**1425 * Filter the taxonomy used in the Tag Cloud widget.1426 *1427 * @since 2.8.01428 * @since 3.0.0 Added taxonomy drop-down.1429 *1430 * @see wp_tag_cloud()1431 *1432 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.1433 */1434 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(1435 'taxonomy' => $current_taxonomy1436 ) ) );1437 1438 echo "</div>\n";1439 echo $args['after_widget'];1440 }1441 1442 /**1443 * @param array $new_instance1444 * @param array $old_instance1445 * @return array1446 */1447 public function update( $new_instance, $old_instance ) {1448 $instance = array();1449 $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) );1450 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);1451 return $instance;1452 }1453 1454 /**1455 * @param array $instance1456 */1457 public function form( $instance ) {1458 $current_taxonomy = $this->_get_current_taxonomy($instance);1459 $title = isset( $instance['title'] ) ? $instance['title'] : '';1460 ?>1461 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>1462 <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 ); ?>" /></p>1463 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>1464 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">1465 <?php foreach ( get_taxonomies() as $taxonomy ) :1466 $tax = get_taxonomy($taxonomy);1467 if ( !$tax->show_tagcloud || empty($tax->labels->name) )1468 continue;1469 ?>1470 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo esc_attr( $tax->labels->name ); ?></option>1471 <?php endforeach; ?>1472 </select></p><?php1473 }1474 1475 /**1476 * @param array $instance1477 * @return string1478 */1479 public function _get_current_taxonomy($instance) {1480 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )1481 return $instance['taxonomy'];1482 1483 return 'post_tag';1484 }1485 }1486 1487 /**1488 * Navigation Menu widget class1489 *1490 * @since 3.0.01491 */1492 9 class WP_Nav_Menu_Widget extends WP_Widget { 1493 10 1494 11 public function __construct() { … … 1597 114 <?php 1598 115 } 1599 116 } 1600 1601 /**1602 * Register all of the default WordPress widgets on startup.1603 *1604 * Calls 'widgets_init' action after all of the WordPress widgets have been1605 * registered.1606 *1607 * @since 2.2.01608 */1609 function wp_widgets_init() {1610 if ( !is_blog_installed() )1611 return;1612 1613 register_widget('WP_Widget_Pages');1614 1615 register_widget('WP_Widget_Calendar');1616 1617 register_widget('WP_Widget_Archives');1618 1619 if ( get_option( 'link_manager_enabled' ) )1620 register_widget('WP_Widget_Links');1621 1622 register_widget('WP_Widget_Meta');1623 1624 register_widget('WP_Widget_Search');1625 1626 register_widget('WP_Widget_Text');1627 1628 register_widget('WP_Widget_Categories');1629 1630 register_widget('WP_Widget_Recent_Posts');1631 1632 register_widget('WP_Widget_Recent_Comments');1633 1634 register_widget('WP_Widget_RSS');1635 1636 register_widget('WP_Widget_Tag_Cloud');1637 1638 register_widget('WP_Nav_Menu_Widget');1639 1640 /**1641 * Fires after all default WordPress widgets have been registered.1642 *1643 * @since 2.2.01644 */1645 do_action( 'widgets_init' );1646 } -
src/wp-includes/widgets/class-wp-widget-archives.php
1 1 <?php 2 2 /** 3 * Default Widgets3 * Archives widget class 4 4 * 5 * @since 2.8.0 5 6 * @package WordPress 6 7 * @subpackage Widgets 7 8 */ 8 9 /**10 * Pages widget class11 *12 * @since 2.8.013 */14 class WP_Widget_Pages extends WP_Widget {15 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);19 }20 21 /**22 * @param array $args23 * @param array $instance24 */25 public function widget( $args, $instance ) {26 27 /**28 * Filter the widget title.29 *30 * @since 2.6.031 *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.35 */36 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );37 38 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];39 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];40 41 if ( $sortby == 'menu_order' )42 $sortby = 'menu_order, post_title';43 44 /**45 * Filter the arguments for the Pages widget.46 *47 * @since 2.8.048 *49 * @see wp_list_pages()50 *51 * @param array $args An array of arguments to retrieve the pages list.52 */53 $out = wp_list_pages( apply_filters( 'widget_pages_args', array(54 'title_li' => '',55 'echo' => 0,56 'sort_column' => $sortby,57 'exclude' => $exclude58 ) ) );59 60 if ( ! empty( $out ) ) {61 echo $args['before_widget'];62 if ( $title ) {63 echo $args['before_title'] . $title . $args['after_title'];64 }65 ?>66 <ul>67 <?php echo $out; ?>68 </ul>69 <?php70 echo $args['after_widget'];71 }72 }73 74 /**75 * @param array $new_instance76 * @param array $old_instance77 * @return array78 */79 public function update( $new_instance, $old_instance ) {80 $instance = $old_instance;81 $instance['title'] = sanitize_text_field( $new_instance['title'] );82 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {83 $instance['sortby'] = $new_instance['sortby'];84 } else {85 $instance['sortby'] = 'menu_order';86 }87 88 $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );89 90 return $instance;91 }92 93 /**94 * @param array $instance95 */96 public function form( $instance ) {97 //Defaults98 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );99 ?>100 <p>101 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>102 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />103 </p>104 <p>105 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>106 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">107 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>108 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>109 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>110 </select>111 </p>112 <p>113 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>114 <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" />115 <br />116 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>117 </p>118 <?php119 }120 121 }122 123 /**124 * Links widget class125 *126 * @since 2.8.0127 */128 class WP_Widget_Links extends WP_Widget {129 130 public function __construct() {131 $widget_ops = array('description' => __( "Your blogroll" ) );132 parent::__construct('links', __('Links'), $widget_ops);133 }134 135 /**136 * @param array $args137 * @param array $instance138 */139 public function widget( $args, $instance ) {140 $show_description = isset($instance['description']) ? $instance['description'] : false;141 $show_name = isset($instance['name']) ? $instance['name'] : false;142 $show_rating = isset($instance['rating']) ? $instance['rating'] : false;143 $show_images = isset($instance['images']) ? $instance['images'] : true;144 $category = isset($instance['category']) ? $instance['category'] : false;145 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';146 $order = $orderby == 'rating' ? 'DESC' : 'ASC';147 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;148 149 $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );150 151 /**152 * Filter the arguments for the Links widget.153 *154 * @since 2.6.0155 *156 * @see wp_list_bookmarks()157 *158 * @param array $args An array of arguments to retrieve the links list.159 */160 wp_list_bookmarks( apply_filters( 'widget_links_args', array(161 'title_before' => $args['before_title'], 'title_after' => $args['after_title'],162 'category_before' => $before_widget, 'category_after' => $args['after_widget'],163 'show_images' => $show_images, 'show_description' => $show_description,164 'show_name' => $show_name, 'show_rating' => $show_rating,165 'category' => $category, 'class' => 'linkcat widget',166 'orderby' => $orderby, 'order' => $order,167 'limit' => $limit,168 ) ) );169 }170 171 /**172 * @param array $new_instance173 * @param array $old_instance174 * @return array175 */176 public function update( $new_instance, $old_instance ) {177 $new_instance = (array) $new_instance;178 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );179 foreach ( $instance as $field => $val ) {180 if ( isset($new_instance[$field]) )181 $instance[$field] = 1;182 }183 184 $instance['orderby'] = 'name';185 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )186 $instance['orderby'] = $new_instance['orderby'];187 188 $instance['category'] = intval( $new_instance['category'] );189 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;190 191 return $instance;192 }193 194 /**195 * @param array $instance196 */197 public function form( $instance ) {198 199 //Defaults200 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );201 $link_cats = get_terms( 'link_category' );202 if ( ! $limit = intval( $instance['limit'] ) )203 $limit = -1;204 ?>205 <p>206 <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>207 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">208 <option value=""><?php _ex('All Links', 'links widget'); ?></option>209 <?php210 foreach ( $link_cats as $link_cat ) {211 echo '<option value="' . intval( $link_cat->term_id ) . '"'212 . selected( $instance['category'], $link_cat->term_id, false )213 . '>' . $link_cat->name . "</option>\n";214 }215 ?>216 </select>217 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>218 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">219 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>220 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>221 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>222 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>223 </select>224 </p>225 <p>226 <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'); ?>" />227 <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />228 <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'); ?>" />229 <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />230 <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'); ?>" />231 <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />232 <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'); ?>" />233 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>234 </p>235 <p>236 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>237 <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" />238 </p>239 <?php240 }241 }242 243 /**244 * Search widget class245 *246 * @since 2.8.0247 */248 class WP_Widget_Search extends WP_Widget {249 250 public function __construct() {251 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );252 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );253 }254 255 /**256 * @param array $args257 * @param array $instance258 */259 public function widget( $args, $instance ) {260 /** This filter is documented in wp-includes/default-widgets.php */261 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );262 263 echo $args['before_widget'];264 if ( $title ) {265 echo $args['before_title'] . $title . $args['after_title'];266 }267 268 // Use current theme search form if it exists269 get_search_form();270 271 echo $args['after_widget'];272 }273 274 /**275 * @param array $instance276 */277 public function form( $instance ) {278 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );279 $title = $instance['title'];280 ?>281 <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>282 <?php283 }284 285 /**286 * @param array $new_instance287 * @param array $old_instance288 * @return array289 */290 public function update( $new_instance, $old_instance ) {291 $instance = $old_instance;292 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));293 $instance['title'] = sanitize_text_field( $new_instance['title'] );294 return $instance;295 }296 297 }298 299 /**300 * Archives widget class301 *302 * @since 2.8.0303 */304 9 class WP_Widget_Archives extends WP_Widget { 305 10 306 11 public function __construct() { … … 425 130 <?php 426 131 } 427 132 } 428 429 /**430 * Meta widget class431 *432 * Displays log in/out, RSS feed links, etc.433 *434 * @since 2.8.0435 */436 class WP_Widget_Meta extends WP_Widget {437 438 public function __construct() {439 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") );440 parent::__construct('meta', __('Meta'), $widget_ops);441 }442 443 /**444 * @param array $args445 * @param array $instance446 */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 );450 451 echo $args['before_widget'];452 if ( $title ) {453 echo $args['before_title'] . $title . $args['after_title'];454 }455 ?>456 <ul>457 <?php wp_register(); ?>458 <li><?php wp_loginout(); ?></li>459 <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>460 <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>461 <?php462 /**463 * Filter the "Powered by WordPress" text in the Meta widget.464 *465 * @since 3.6.0466 *467 * @param string $title_text Default title text for the WordPress.org link.468 */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' )473 ) );474 475 wp_meta();476 ?>477 </ul>478 <?php479 echo $args['after_widget'];480 }481 482 /**483 * @param array $new_instance484 * @param array $old_instance485 * @return array486 */487 public function update( $new_instance, $old_instance ) {488 $instance = $old_instance;489 $instance['title'] = sanitize_text_field( $new_instance['title'] );490 491 return $instance;492 }493 494 /**495 * @param array $instance496 */497 public function form( $instance ) {498 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );499 $title = sanitize_text_field( $instance['title'] );500 ?>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>502 <?php503 }504 }505 506 /**507 * Calendar widget class508 *509 * @since 2.8.0510 */511 class WP_Widget_Calendar extends WP_Widget {512 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);516 }517 518 /**519 * @param array $args520 * @param array $instance521 */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 );525 526 echo $args['before_widget'];527 if ( $title ) {528 echo $args['before_title'] . $title . $args['after_title'];529 }530 echo '<div id="calendar_wrap">';531 get_calendar();532 echo '</div>';533 echo $args['after_widget'];534 }535 536 /**537 * @param array $new_instance538 * @param array $old_instance539 * @return array540 */541 public function update( $new_instance, $old_instance ) {542 $instance = $old_instance;543 $instance['title'] = sanitize_text_field( $new_instance['title'] );544 545 return $instance;546 }547 548 /**549 * @param array $instance550 */551 public function form( $instance ) {552 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );553 $title = sanitize_text_field( $instance['title'] );554 ?>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>557 <?php558 }559 }560 561 /**562 * Text widget class563 *564 * @since 2.8.0565 */566 class WP_Widget_Text extends WP_Widget {567 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);572 }573 574 /**575 * @param array $args576 * @param array $instance577 */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 );581 582 /**583 * Filter the content of the Text widget.584 *585 * @since 2.3.0586 *587 * @param string $widget_text The widget content.588 * @param WP_Widget $instance WP_Widget instance.589 */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'];594 } ?>595 <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>596 <?php597 echo $args['after_widget'];598 }599 600 /**601 * @param array $new_instance602 * @param array $old_instance603 * @return array604 */605 public function update( $new_instance, $old_instance ) {606 $instance = $old_instance;607 $instance['title'] = sanitize_text_field( $new_instance['title'] );608 if ( current_user_can('unfiltered_html') )609 $instance['text'] = $new_instance['text'];610 else611 $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) );612 $instance['filter'] = ! empty( $new_instance['filter'] );613 return $instance;614 }615 616 /**617 * @param array $instance618 */619 public function form( $instance ) {620 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );621 $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;622 $title = sanitize_text_field( $instance['title'] );623 ?>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>626 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 esc_textarea( $instance['text'] ); ?></textarea></p>629 630 <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked( $filter ); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>631 <?php632 }633 }634 635 /**636 * Categories widget class637 *638 * @since 2.8.0639 */640 class WP_Widget_Categories extends WP_Widget {641 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);645 }646 647 /**648 * @staticvar bool $first_dropdown649 *650 * @param array $args651 * @param array $instance652 */653 public function widget( $args, $instance ) {654 static $first_dropdown = true;655 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 );658 659 $c = ! empty( $instance['count'] ) ? '1' : '0';660 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';661 $d = ! empty( $instance['dropdown'] ) ? '1' : '0';662 663 echo $args['before_widget'];664 if ( $title ) {665 echo $args['before_title'] . $title . $args['after_title'];666 }667 668 $cat_args = array(669 'orderby' => 'name',670 'show_count' => $c,671 'hierarchical' => $h672 );673 674 if ( $d ) {675 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";676 $first_dropdown = false;677 678 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';679 680 $cat_args['show_option_none'] = __( 'Select Category' );681 $cat_args['id'] = $dropdown_id;682 683 /**684 * Filter the arguments for the Categories widget drop-down.685 *686 * @since 2.8.0687 *688 * @see wp_dropdown_categories()689 *690 * @param array $cat_args An array of Categories widget drop-down arguments.691 */692 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );693 ?>694 695 <script type='text/javascript'>696 /* <![CDATA[ */697 (function() {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;702 }703 }704 dropdown.onchange = onCatChange;705 })();706 /* ]]> */707 </script>708 709 <?php710 } else {711 ?>712 <ul>713 <?php714 $cat_args['title_li'] = '';715 716 /**717 * Filter the arguments for the Categories widget.718 *719 * @since 2.8.0720 *721 * @param array $cat_args An array of Categories widget options.722 */723 wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );724 ?>725 </ul>726 <?php727 }728 729 echo $args['after_widget'];730 }731 732 /**733 * @param array $new_instance734 * @param array $old_instance735 * @return array736 */737 public function update( $new_instance, $old_instance ) {738 $instance = $old_instance;739 $instance['title'] = sanitize_text_field( $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;743 744 return $instance;745 }746 747 /**748 * @param array $instance749 */750 public function form( $instance ) {751 //Defaults752 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );753 $title = sanitize_text_field( $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;757 ?>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 esc_attr( $title ); ?>" /></p>760 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 />763 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 />766 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>769 <?php770 }771 772 }773 774 /**775 * Recent_Posts widget class776 *777 * @since 2.8.0778 */779 class WP_Widget_Recent_Posts extends WP_Widget {780 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';785 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') );789 }790 791 /**792 * @param array $args793 * @param array $instance794 */795 public function widget( $args, $instance ) {796 $cache = array();797 if ( ! $this->is_preview() ) {798 $cache = wp_cache_get( 'widget_recent_posts', 'widget' );799 }800 801 if ( ! is_array( $cache ) ) {802 $cache = array();803 }804 805 if ( ! isset( $args['widget_id'] ) ) {806 $args['widget_id'] = $this->id;807 }808 809 if ( isset( $cache[ $args['widget_id'] ] ) ) {810 echo $cache[ $args['widget_id'] ];811 return;812 }813 814 ob_start();815 816 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );817 818 /** This filter is documented in wp-includes/default-widgets.php */819 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );820 821 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;822 if ( ! $number )823 $number = 5;824 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;825 826 /**827 * Filter the arguments for the Recent Posts widget.828 *829 * @since 3.4.0830 *831 * @see WP_Query::get_posts()832 *833 * @param array $args An array of arguments used to retrieve the recent posts.834 */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' => true840 ) ) );841 842 if ($r->have_posts()) :843 ?>844 <?php echo $args['before_widget']; ?>845 <?php if ( $title ) {846 echo $args['before_title'] . $title . $args['after_title'];847 } ?>848 <ul>849 <?php while ( $r->have_posts() ) : $r->the_post(); ?>850 <li>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>854 <?php endif; ?>855 </li>856 <?php endwhile; ?>857 </ul>858 <?php echo $args['after_widget']; ?>859 <?php860 // Reset the global $the_post as this query will have stomped on it861 wp_reset_postdata();862 863 endif;864 865 if ( ! $this->is_preview() ) {866 $cache[ $args['widget_id'] ] = ob_get_flush();867 wp_cache_set( 'widget_recent_posts', $cache, 'widget' );868 } else {869 ob_end_flush();870 }871 }872 873 /**874 * @param array $new_instance875 * @param array $old_instance876 * @return array877 */878 public function update( $new_instance, $old_instance ) {879 $instance = $old_instance;880 $instance['title'] = santize_text_field( $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();884 885 $alloptions = wp_cache_get( 'alloptions', 'options' );886 if ( isset($alloptions['widget_recent_entries']) )887 delete_option('widget_recent_entries');888 889 return $instance;890 }891 892 /**893 * @access public894 */895 public function flush_widget_cache() {896 wp_cache_delete('widget_recent_posts', 'widget');897 }898 899 /**900 * @param array $instance901 */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;906 ?>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>909 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>912 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>915 <?php916 }917 }918 919 /**920 * Recent_Comments widget class921 *922 * @since 2.8.0923 */924 class WP_Widget_Recent_Comments extends WP_Widget {925 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';930 931 if ( is_active_widget(false, false, $this->id_base) )932 add_action( 'wp_head', array($this, 'recent_comments_style') );933 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') );937 }938 939 /**940 * @access public941 */942 public function recent_comments_style() {943 /**944 * Filter the Recent Comments default widget styles.945 *946 * @since 3.1.0947 *948 * @param bool $active Whether the widget is active. Default true.949 * @param string $id_base The widget ID.950 */951 if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876952 || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )953 return;954 ?>955 <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>956 <?php957 }958 959 /**960 * @access public961 */962 public function flush_widget_cache() {963 wp_cache_delete('widget_recent_comments', 'widget');964 }965 966 /**967 * @param array $args968 * @param array $instance969 */970 public function widget( $args, $instance ) {971 $cache = array();972 if ( ! $this->is_preview() ) {973 $cache = wp_cache_get('widget_recent_comments', 'widget');974 }975 if ( ! is_array( $cache ) ) {976 $cache = array();977 }978 979 if ( ! isset( $args['widget_id'] ) )980 $args['widget_id'] = $this->id;981 982 if ( isset( $cache[ $args['widget_id'] ] ) ) {983 echo $cache[ $args['widget_id'] ];984 return;985 }986 987 $output = '';988 989 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' );990 991 /** This filter is documented in wp-includes/default-widgets.php */992 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );993 994 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;995 if ( ! $number )996 $number = 5;997 998 /**999 * Filter the arguments for the Recent Comments widget.1000 *1001 * @since 3.4.01002 *1003 * @see WP_Comment_Query::query() for information on accepted arguments.1004 *1005 * @param array $comment_args An array of arguments used to retrieve the recent comments.1006 */1007 $comments = get_comments( apply_filters( 'widget_comments_args', array(1008 'number' => $number,1009 'status' => 'approve',1010 'post_status' => 'publish'1011 ) ) );1012 1013 $output .= $args['before_widget'];1014 if ( $title ) {1015 $output .= $args['before_title'] . $title . $args['after_title'];1016 }1017 1018 $output .= '<ul id="recentcomments">';1019 if ( is_array( $comments ) && $comments ) {1020 // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)1021 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );1022 _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );1023 1024 foreach ( (array) $comments as $comment ) {1025 $output .= '<li class="recentcomments">';1026 /* translators: comments widget: 1: comment author, 2: post link */1027 $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),1028 '<span class="comment-author-link">' . get_comment_author_link( $comment->comment_ID ) . '</span>',1029 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'1030 );1031 $output .= '</li>';1032 }1033 }1034 $output .= '</ul>';1035 $output .= $args['after_widget'];1036 1037 echo $output;1038 1039 if ( ! $this->is_preview() ) {1040 $cache[ $args['widget_id'] ] = $output;1041 wp_cache_set( 'widget_recent_comments', $cache, 'widget' );1042 }1043 }1044 1045 /**1046 * @param array $new_instance1047 * @param array $old_instance1048 * @return array1049 */1050 public function update( $new_instance, $old_instance ) {1051 $instance = $old_instance;1052 $instance['title'] = sanitize_text_field( $new_instance['title'] );1053 $instance['number'] = absint( $new_instance['number'] );1054 $this->flush_widget_cache();1055 1056 $alloptions = wp_cache_get( 'alloptions', 'options' );1057 if ( isset($alloptions['widget_recent_comments']) )1058 delete_option('widget_recent_comments');1059 1060 return $instance;1061 }1062 1063 /**1064 * @param array $instance1065 */1066 public function form( $instance ) {1067 $title = isset( $instance['title'] ) ? $instance['title'] : '';1068 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;1069 ?>1070 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>1071 <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>1072 1073 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>1074 <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>1075 <?php1076 }1077 }1078 1079 /**1080 * RSS widget class1081 *1082 * @since 2.8.01083 */1084 class WP_Widget_RSS extends WP_Widget {1085 1086 public function __construct() {1087 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );1088 $control_ops = array( 'width' => 400, 'height' => 200 );1089 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );1090 }1091 1092 /**1093 * @param array $args1094 * @param array $instance1095 */1096 public function widget( $args, $instance ) {1097 if ( isset($instance['error']) && $instance['error'] )1098 return;1099 1100 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';1101 while ( stristr($url, 'http') != $url )1102 $url = substr($url, 1);1103 1104 if ( empty($url) )1105 return;1106 1107 // self-url destruction sequence1108 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )1109 return;1110 1111 $rss = fetch_feed($url);1112 $title = $instance['title'];1113 $desc = '';1114 $link = '';1115 1116 if ( ! is_wp_error($rss) ) {1117 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));1118 if ( empty($title) )1119 $title = strip_tags( $rss->get_title() );1120 $link = strip_tags( $rss->get_permalink() );1121 while ( stristr($link, 'http') != $link )1122 $link = substr($link, 1);1123 }1124 1125 if ( empty($title) )1126 $title = empty($desc) ? __('Unknown Feed') : $desc;1127 1128 /** This filter is documented in wp-includes/default-widgets.php */1129 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );1130 1131 $url = strip_tags( $url );1132 $icon = includes_url( 'images/rss.png' );1133 if ( $title )1134 $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">"'. esc_html( $title ) .'"</a>';1135 1136 echo $args['before_widget'];1137 if ( $title ) {1138 echo $args['before_title'] . $title . $args['after_title'];1139 }1140 wp_widget_rss_output( $rss, $instance );1141 echo $args['after_widget'];1142 1143 if ( ! is_wp_error($rss) )1144 $rss->__destruct();1145 unset($rss);1146 }1147 1148 /**1149 * @param array $new_instance1150 * @param array $old_instance1151 * @return array1152 */1153 public function update( $new_instance, $old_instance ) {1154 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );1155 return wp_widget_rss_process( $new_instance, $testurl );1156 }1157 1158 /**1159 * @param array $instance1160 */1161 public function form( $instance ) {1162 if ( empty( $instance ) ) {1163 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );1164 }1165 $instance['number'] = $this->number;1166 1167 wp_widget_rss_form( $instance );1168 }1169 }1170 1171 /**1172 * Display the RSS entries in a list.1173 *1174 * @since 2.5.01175 *1176 * @param string|array|object $rss RSS url.1177 * @param array $args Widget arguments.1178 */1179 function wp_widget_rss_output( $rss, $args = array() ) {1180 if ( is_string( $rss ) ) {1181 $rss = fetch_feed($rss);1182 } elseif ( is_array($rss) && isset($rss['url']) ) {1183 $args = $rss;1184 $rss = fetch_feed($rss['url']);1185 } elseif ( !is_object($rss) ) {1186 return;1187 }1188 1189 if ( is_wp_error($rss) ) {1190 if ( is_admin() || current_user_can('manage_options') )1191 echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';1192 return;1193 }1194 1195 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );1196 $args = wp_parse_args( $args, $default_args );1197 1198 $items = (int) $args['items'];1199 if ( $items < 1 || 20 < $items )1200 $items = 10;1201 $show_summary = (int) $args['show_summary'];1202 $show_author = (int) $args['show_author'];1203 $show_date = (int) $args['show_date'];1204 1205 if ( !$rss->get_item_quantity() ) {1206 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';1207 $rss->__destruct();1208 unset($rss);1209 return;1210 }1211 1212 echo '<ul>';1213 foreach ( $rss->get_items( 0, $items ) as $item ) {1214 $link = $item->get_link();1215 while ( stristr( $link, 'http' ) != $link ) {1216 $link = substr( $link, 1 );1217 }1218 $link = esc_url( strip_tags( $link ) );1219 1220 $title = esc_html( trim( strip_tags( $item->get_title() ) ) );1221 if ( empty( $title ) ) {1222 $title = __( 'Untitled' );1223 }1224 1225 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );1226 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) );1227 1228 $summary = '';1229 if ( $show_summary ) {1230 $summary = $desc;1231 1232 // Change existing [...] to […].1233 if ( '[...]' == substr( $summary, -5 ) ) {1234 $summary = substr( $summary, 0, -5 ) . '[…]';1235 }1236 1237 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';1238 }1239 1240 $date = '';1241 if ( $show_date ) {1242 $date = $item->get_date( 'U' );1243 1244 if ( $date ) {1245 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';1246 }1247 }1248 1249 $author = '';1250 if ( $show_author ) {1251 $author = $item->get_author();1252 if ( is_object($author) ) {1253 $author = $author->get_name();1254 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';1255 }1256 }1257 1258 if ( $link == '' ) {1259 echo "<li>$title{$date}{$summary}{$author}</li>";1260 } elseif ( $show_summary ) {1261 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";1262 } else {1263 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";1264 }1265 }1266 echo '</ul>';1267 $rss->__destruct();1268 unset($rss);1269 }1270 1271 /**1272 * Display RSS widget options form.1273 *1274 * The options for what fields are displayed for the RSS form are all booleans1275 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',1276 * 'show_date'.1277 *1278 * @since 2.5.01279 *1280 * @param array|string $args Values for input fields.1281 * @param array $inputs Override default display options.1282 */1283 function wp_widget_rss_form( $args, $inputs = null ) {1284 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );1285 $inputs = wp_parse_args( $inputs, $default_inputs );1286 1287 $args['title'] = isset( $args['title'] ) ? $args['title'] : '';1288 $args['url'] = isset( $args['url'] ) ? $args['url'] : '';1289 $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;1290 1291 if ( $args['items'] < 1 || 20 < $args['items'] ) {1292 $args['items'] = 10;1293 }1294 1295 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];1296 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];1297 $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];1298 1299 if ( ! empty( $args['error'] ) ) {1300 echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';1301 }1302 1303 $esc_number = esc_attr( $args['number'] );1304 if ( $inputs['url'] ) :1305 ?>1306 <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>1307 <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p>1308 <?php endif; if ( $inputs['title'] ) : ?>1309 <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>1310 <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr( $args['title'] ); ?>" /></p>1311 <?php endif; if ( $inputs['items'] ) : ?>1312 <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>1313 <select id="rss-items-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][items]">1314 <?php1315 for ( $i = 1; $i <= 20; ++$i ) {1316 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";1317 }1318 ?>1319 </select></p>1320 <?php endif; if ( $inputs['show_summary'] ) : ?>1321 <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> />1322 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p>1323 <?php endif; if ( $inputs['show_author'] ) : ?>1324 <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> />1325 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>1326 <?php endif; if ( $inputs['show_date'] ) : ?>1327 <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>1328 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p>1329 <?php1330 endif;1331 foreach ( array_keys($default_inputs) as $input ) :1332 if ( 'hidden' === $inputs[$input] ) :1333 $id = str_replace( '_', '-', $input );1334 ?>1335 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" />1336 <?php1337 endif;1338 endforeach;1339 }1340 1341 /**1342 * Process RSS feed widget data and optionally retrieve feed items.1343 *1344 * The feed widget can not have more than 20 items or it will reset back to the1345 * default, which is 10.1346 *1347 * The resulting array has the feed title, feed url, feed link (from channel),1348 * feed items, error (if any), and whether to show summary, author, and date.1349 * All respectively in the order of the array elements.1350 *1351 * @since 2.5.01352 *1353 * @param array $widget_rss RSS widget feed data. Expects unescaped data.1354 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.1355 * @return array1356 */1357 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {1358 $items = (int) $widget_rss['items'];1359 if ( $items < 1 || 20 < $items )1360 $items = 10;1361 $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );1362 $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';1363 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;1364 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;1365 $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;1366 1367 if ( $check_feed ) {1368 $rss = fetch_feed($url);1369 $error = false;1370 $link = '';1371 if ( is_wp_error($rss) ) {1372 $error = $rss->get_error_message();1373 } else {1374 $link = esc_url(strip_tags($rss->get_permalink()));1375 while ( stristr($link, 'http') != $link )1376 $link = substr($link, 1);1377 1378 $rss->__destruct();1379 unset($rss);1380 }1381 }1382 1383 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );1384 }1385 1386 /**1387 * Tag cloud widget class1388 *1389 * @since 2.8.01390 */1391 class WP_Widget_Tag_Cloud extends WP_Widget {1392 1393 public function __construct() {1394 $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );1395 parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);1396 }1397 1398 /**1399 * @param array $args1400 * @param array $instance1401 */1402 public function widget( $args, $instance ) {1403 $current_taxonomy = $this->_get_current_taxonomy($instance);1404 if ( !empty($instance['title']) ) {1405 $title = $instance['title'];1406 } else {1407 if ( 'post_tag' == $current_taxonomy ) {1408 $title = __('Tags');1409 } else {1410 $tax = get_taxonomy($current_taxonomy);1411 $title = $tax->labels->name;1412 }1413 }1414 1415 /** This filter is documented in wp-includes/default-widgets.php */1416 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );1417 1418 echo $args['before_widget'];1419 if ( $title ) {1420 echo $args['before_title'] . $title . $args['after_title'];1421 }1422 echo '<div class="tagcloud">';1423 1424 /**1425 * Filter the taxonomy used in the Tag Cloud widget.1426 *1427 * @since 2.8.01428 * @since 3.0.0 Added taxonomy drop-down.1429 *1430 * @see wp_tag_cloud()1431 *1432 * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.1433 */1434 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(1435 'taxonomy' => $current_taxonomy1436 ) ) );1437 1438 echo "</div>\n";1439 echo $args['after_widget'];1440 }1441 1442 /**1443 * @param array $new_instance1444 * @param array $old_instance1445 * @return array1446 */1447 public function update( $new_instance, $old_instance ) {1448 $instance = array();1449 $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) );1450 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);1451 return $instance;1452 }1453 1454 /**1455 * @param array $instance1456 */1457 public function form( $instance ) {1458 $current_taxonomy = $this->_get_current_taxonomy($instance);1459 $title = isset( $instance['title'] ) ? $instance['title'] : '';1460 ?>1461 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>1462 <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 ); ?>" /></p>1463 <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>1464 <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">1465 <?php foreach ( get_taxonomies() as $taxonomy ) :1466 $tax = get_taxonomy($taxonomy);1467 if ( !$tax->show_tagcloud || empty($tax->labels->name) )1468 continue;1469 ?>1470 <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo esc_attr( $tax->labels->name ); ?></option>1471 <?php endforeach; ?>1472 </select></p><?php1473 }1474 1475 /**1476 * @param array $instance1477 * @return string1478 */1479 public function _get_current_taxonomy($instance) {1480 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )1481 return $instance['taxonomy'];1482 1483 return 'post_tag';1484 }1485 }1486 1487 /**1488 * Navigation Menu widget class1489 *1490 * @since 3.0.01491 */1492 class WP_Nav_Menu_Widget extends WP_Widget {1493 1494 public function __construct() {1495 $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );1496 parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );1497 }1498 1499 /**1500 * @param array $args1501 * @param array $instance1502 */1503 public function widget( $args, $instance ) {1504 // Get menu1505 $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;1506 1507 if ( !$nav_menu )1508 return;1509 1510 /** This filter is documented in wp-includes/default-widgets.php */1511 $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );1512 1513 echo $args['before_widget'];1514 1515 if ( !empty($instance['title']) )1516 echo $args['before_title'] . $instance['title'] . $args['after_title'];1517 1518 $nav_menu_args = array(1519 'fallback_cb' => '',1520 'menu' => $nav_menu1521 );1522 1523 /**1524 * Filter the arguments for the Custom Menu widget.1525 *1526 * @since 4.2.01527 *1528 * @param array $nav_menu_args {1529 * An array of arguments passed to wp_nav_menu() to retrieve a custom menu.1530 *1531 * @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.1532 * @type mixed $menu Menu ID, slug, or name.1533 * }1534 * @param stdClass $nav_menu Nav menu object for the current menu.1535 * @param array $args Display arguments for the current widget.1536 */1537 wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) );1538 1539 echo $args['after_widget'];1540 }1541 1542 /**1543 * @param array $new_instance1544 * @param array $old_instance1545 * @return array1546 */1547 public function update( $new_instance, $old_instance ) {1548 $instance = array();1549 if ( ! empty( $new_instance['title'] ) ) {1550 $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) );1551 }1552 if ( ! empty( $new_instance['nav_menu'] ) ) {1553 $instance['nav_menu'] = (int) $new_instance['nav_menu'];1554 }1555 return $instance;1556 }1557 1558 /**1559 * @param array $instance1560 */1561 public function form( $instance ) {1562 $title = isset( $instance['title'] ) ? $instance['title'] : '';1563 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';1564 1565 // Get menus1566 $menus = wp_get_nav_menus();1567 1568 // If no menus exists, direct the user to go and create some.1569 ?>1570 <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>1571 <?php1572 if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {1573 $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();';1574 } else {1575 $url = admin_url( 'nav-menus.php' );1576 }1577 ?>1578 <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>1579 </p>1580 <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>1581 <p>1582 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>1583 <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 ); ?>"/>1584 </p>1585 <p>1586 <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>1587 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">1588 <option value="0"><?php _e( '— Select —' ); ?></option>1589 <?php foreach ( $menus as $menu ) : ?>1590 <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>1591 <?php echo esc_html( $menu->name ); ?>1592 </option>1593 <?php endforeach; ?>1594 </select>1595 </p>1596 </div>1597 <?php1598 }1599 }1600 1601 /**1602 * Register all of the default WordPress widgets on startup.1603 *1604 * Calls 'widgets_init' action after all of the WordPress widgets have been1605 * registered.1606 *1607 * @since 2.2.01608 */1609 function wp_widgets_init() {1610 if ( !is_blog_installed() )1611 return;1612 1613 register_widget('WP_Widget_Pages');1614 1615 register_widget('WP_Widget_Calendar');1616 1617 register_widget('WP_Widget_Archives');1618 1619 if ( get_option( 'link_manager_enabled' ) )1620 register_widget('WP_Widget_Links');1621 1622 register_widget('WP_Widget_Meta');1623 1624 register_widget('WP_Widget_Search');1625 1626 register_widget('WP_Widget_Text');1627 1628 register_widget('WP_Widget_Categories');1629 1630 register_widget('WP_Widget_Recent_Posts');1631 1632 register_widget('WP_Widget_Recent_Comments');1633 1634 register_widget('WP_Widget_RSS');1635 1636 register_widget('WP_Widget_Tag_Cloud');1637 1638 register_widget('WP_Nav_Menu_Widget');1639 1640 /**1641 * Fires after all default WordPress widgets have been registered.1642 *1643 * @since 2.2.01644 */1645 do_action( 'widgets_init' );1646 } -
src/wp-includes/widgets/class-wp-widget-calendar.php
1 1 <?php 2 2 /** 3 * Default Widgets3 * Calendar widget class 4 4 * 5 * @since 2.8.0 5 6 * @package WordPress 6 7 * @subpackage Widgets 7 8 */ 8 9 /**10 * Pages widget class11 *12 * @since 2.8.013 */14 class WP_Widget_Pages extends WP_Widget {15 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);19 }20 21 /**22 * @param array $args23 * @param array $instance24 */25 public function widget( $args, $instance ) {26 27 /**28 * Filter the widget title.29 *30 * @since 2.6.031 *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.35 */36 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );37 38 $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];39 $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];40 41 if ( $sortby == 'menu_order' )42 $sortby = 'menu_order, post_title';43 44 /**45 * Filter the arguments for the Pages widget.46 *47 * @since 2.8.048 *49 * @see wp_list_pages()50 *51 * @param array $args An array of arguments to retrieve the pages list.52 */53 $out = wp_list_pages( apply_filters( 'widget_pages_args', array(54 'title_li' => '',55 'echo' => 0,56 'sort_column' => $sortby,57 'exclude' => $exclude58 ) ) );59 60 if ( ! empty( $out ) ) {61 echo $args['before_widget'];62 if ( $title ) {63 echo $args['before_title'] . $title . $args['after_title'];64 }65 ?>66 <ul>67 <?php echo $out; ?>68 </ul>69 <?php70 echo $args['after_widget'];71 }72 }73 74 /**75 * @param array $new_instance76 * @param array $old_instance77 * @return array78 */79 public function update( $new_instance, $old_instance ) {80 $instance = $old_instance;81 $instance['title'] = sanitize_text_field( $new_instance['title'] );82 if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {83 $instance['sortby'] = $new_instance['sortby'];84 } else {85 $instance['sortby'] = 'menu_order';86 }87 88 $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );89 90 return $instance;91 }92 93 /**94 * @param array $instance95 */96 public function form( $instance ) {97 //Defaults98 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );99 ?>100 <p>101 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>102 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />103 </p>104 <p>105 <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>106 <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">107 <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>108 <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>109 <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>110 </select>111 </p>112 <p>113 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label>114 <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" />115 &nb