Changeset 45667 for trunk/src/wp-includes/category-template.php
- Timestamp:
- 07/25/2019 12:47:53 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r45599 r45667 366 366 } 367 367 368 $r = wp_parse_args( $args, $defaults ); 369 $option_none_value = $r['option_none_value']; 370 371 if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { 372 $r['pad_counts'] = true; 373 } 374 375 $tab_index = $r['tab_index']; 368 // Parse incoming $args into an array and merge it with $defaults 369 $parsed_args = wp_parse_args( $args, $defaults ); 370 $option_none_value = $args['option_none_value']; 371 372 if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) { 373 $parsed_args['pad_counts'] = true; 374 } 375 376 $tab_index = $parsed_args['tab_index']; 376 377 377 378 $tab_index_attribute = ''; … … 381 382 382 383 // Avoid clashes with the 'name' param of get_terms(). 383 $get_terms_args = $ r;384 $get_terms_args = $parsed_args; 384 385 unset( $get_terms_args['name'] ); 385 $categories = get_terms( $ r['taxonomy'], $get_terms_args );386 387 $name = esc_attr( $ r['name'] );388 $class = esc_attr( $ r['class'] );389 $id = $ r['id'] ? esc_attr( $r['id'] ) : $name;390 $required = $ r['required'] ? 'required' : '';391 392 if ( ! $ r['hide_if_empty'] || ! empty( $categories ) ) {386 $categories = get_terms( $parsed_args['taxonomy'], $get_terms_args ); 387 388 $name = esc_attr( $parsed_args['name'] ); 389 $class = esc_attr( $parsed_args['class'] ); 390 $id = $parsed_args['id'] ? esc_attr( $parsed_args['id'] ) : $name; 391 $required = $parsed_args['required'] ? 'required' : ''; 392 393 if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) { 393 394 $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n"; 394 395 } else { 395 396 $output = ''; 396 397 } 397 if ( empty( $categories ) && ! $ r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) {398 if ( empty( $categories ) && ! $parsed_args['hide_if_empty'] && ! empty( $parsed_args['show_option_none'] ) ) { 398 399 399 400 /** … … 412 413 * @param WP_Term|null $category The category object, or null if there's no corresponding category. 413 414 */ 414 $show_option_none = apply_filters( 'list_cats', $ r['show_option_none'], null );415 $show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null ); 415 416 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; 416 417 } … … 418 419 if ( ! empty( $categories ) ) { 419 420 420 if ( $ r['show_option_all'] ) {421 if ( $parsed_args['show_option_all'] ) { 421 422 422 423 /** This filter is documented in wp-includes/category-template.php */ 423 $show_option_all = apply_filters( 'list_cats', $ r['show_option_all'], null );424 $selected = ( '0' === strval( $ r['selected'] ) ) ? " selected='selected'" : '';424 $show_option_all = apply_filters( 'list_cats', $parsed_args['show_option_all'], null ); 425 $selected = ( '0' === strval( $parsed_args['selected'] ) ) ? " selected='selected'" : ''; 425 426 $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; 426 427 } 427 428 428 if ( $ r['show_option_none'] ) {429 if ( $parsed_args['show_option_none'] ) { 429 430 430 431 /** This filter is documented in wp-includes/category-template.php */ 431 $show_option_none = apply_filters( 'list_cats', $ r['show_option_none'], null );432 $selected = selected( $option_none_value, $ r['selected'], false );432 $show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null ); 433 $selected = selected( $option_none_value, $parsed_args['selected'], false ); 433 434 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; 434 435 } 435 436 436 if ( $ r['hierarchical'] ) {437 $depth = $ r['depth']; // Walk the full depth.437 if ( $parsed_args['hierarchical'] ) { 438 $depth = $parsed_args['depth']; // Walk the full depth. 438 439 } else { 439 440 $depth = -1; // Flat. 440 441 } 441 $output .= walk_category_dropdown_tree( $categories, $depth, $ r);442 } 443 444 if ( ! $ r['hide_if_empty'] || ! empty( $categories ) ) {442 $output .= walk_category_dropdown_tree( $categories, $depth, $parsed_args ); 443 } 444 445 if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) { 445 446 $output .= "</select>\n"; 446 447 } … … 451 452 * 452 453 * @param string $output HTML output. 453 * @param array $ rArguments used to build the drop-down.454 * @param array $parsed_args Arguments used to build the drop-down. 454 455 */ 455 $output = apply_filters( 'wp_dropdown_cats', $output, $ r);456 457 if ( $ r['echo'] ) {456 $output = apply_filters( 'wp_dropdown_cats', $output, $parsed_args ); 457 458 if ( $parsed_args['echo'] ) { 458 459 echo $output; 459 460 } … … 538 539 ); 539 540 540 $ r= wp_parse_args( $args, $defaults );541 542 if ( ! isset( $ r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {543 $ r['pad_counts'] = true;541 $parsed_args = wp_parse_args( $args, $defaults ); 542 543 if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) { 544 $parsed_args['pad_counts'] = true; 544 545 } 545 546 546 547 // Descendants of exclusions should be excluded too. 547 if ( true == $ r['hierarchical'] ) {548 if ( true == $parsed_args['hierarchical'] ) { 548 549 $exclude_tree = array(); 549 550 550 if ( $ r['exclude_tree'] ) {551 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $ r['exclude_tree'] ) );552 } 553 554 if ( $ r['exclude'] ) {555 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $ r['exclude'] ) );556 } 557 558 $ r['exclude_tree'] = $exclude_tree;559 $ r['exclude'] = '';560 } 561 562 if ( ! isset( $ r['class'] ) ) {563 $ r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];564 } 565 566 if ( ! taxonomy_exists( $ r['taxonomy'] ) ) {551 if ( $parsed_args['exclude_tree'] ) { 552 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) ); 553 } 554 555 if ( $parsed_args['exclude'] ) { 556 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude'] ) ); 557 } 558 559 $parsed_args['exclude_tree'] = $exclude_tree; 560 $parsed_args['exclude'] = ''; 561 } 562 563 if ( ! isset( $parsed_args['class'] ) ) { 564 $parsed_args['class'] = ( 'category' == $parsed_args['taxonomy'] ) ? 'categories' : $parsed_args['taxonomy']; 565 } 566 567 if ( ! taxonomy_exists( $parsed_args['taxonomy'] ) ) { 567 568 return false; 568 569 } 569 570 570 $show_option_all = $ r['show_option_all'];571 $show_option_none = $ r['show_option_none'];572 573 $categories = get_categories( $ r);571 $show_option_all = $parsed_args['show_option_all']; 572 $show_option_none = $parsed_args['show_option_none']; 573 574 $categories = get_categories( $parsed_args ); 574 575 575 576 $output = ''; 576 if ( $ r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {577 $output = '<li class="' . esc_attr( $ r['class'] ) . '">' . $r['title_li'] . '<ul>';577 if ( $parsed_args['title_li'] && 'list' == $parsed_args['style'] && ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) ) { 578 $output = '<li class="' . esc_attr( $parsed_args['class'] ) . '">' . $parsed_args['title_li'] . '<ul>'; 578 579 } 579 580 if ( empty( $categories ) ) { 580 581 if ( ! empty( $show_option_none ) ) { 581 if ( 'list' == $ r['style'] ) {582 if ( 'list' == $parsed_args['style'] ) { 582 583 $output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; 583 584 } else { … … 591 592 592 593 // For taxonomies that belong only to custom post types, point to a valid archive. 593 $taxonomy_object = get_taxonomy( $ r['taxonomy'] );594 $taxonomy_object = get_taxonomy( $parsed_args['taxonomy'] ); 594 595 if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) { 595 596 foreach ( $taxonomy_object->object_type as $object_type ) { … … 614 615 615 616 $posts_page = esc_url( $posts_page ); 616 if ( 'list' == $ r['style'] ) {617 if ( 'list' == $parsed_args['style'] ) { 617 618 $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; 618 619 } else { … … 621 622 } 622 623 623 if ( empty( $ r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {624 if ( empty( $parsed_args['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { 624 625 $current_term_object = get_queried_object(); 625 if ( $current_term_object && $ r['taxonomy'] === $current_term_object->taxonomy ) {626 $ r['current_category'] = get_queried_object_id();626 if ( $current_term_object && $parsed_args['taxonomy'] === $current_term_object->taxonomy ) { 627 $parsed_args['current_category'] = get_queried_object_id(); 627 628 } 628 629 } 629 630 630 if ( $ r['hierarchical'] ) {631 $depth = $ r['depth'];631 if ( $parsed_args['hierarchical'] ) { 632 $depth = $parsed_args['depth']; 632 633 } else { 633 634 $depth = -1; // Flat. 634 635 } 635 $output .= walk_category_tree( $categories, $depth, $ r);636 } 637 638 if ( $ r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {636 $output .= walk_category_tree( $categories, $depth, $parsed_args ); 637 } 638 639 if ( $parsed_args['title_li'] && 'list' == $parsed_args['style'] && ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) ) { 639 640 $output .= '</ul></li>'; 640 641 } … … 650 651 $html = apply_filters( 'wp_list_categories', $output, $args ); 651 652 652 if ( $ r['echo'] ) {653 if ( $parsed_args['echo'] ) { 653 654 echo $html; 654 655 } else {
Note: See TracChangeset
for help on using the changeset viewer.