Ticket #45059: 45059.patch
File 45059.patch, 8.9 KB (added by , 6 years ago) |
---|
-
category-template.php
364 364 ); 365 365 $args['taxonomy'] = 'link_category'; 366 366 } 367 // Parse incoming $args into an array and merge it with $defaults 368 $args = wp_parse_args( $args, $defaults ); 369 $option_none_value = $args['option_none_value']; 367 370 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; 371 if ( ! isset( $args['pad_counts'] ) && $args['show_count'] && $args['hierarchical'] ) { 372 $args['pad_counts'] = true; 373 373 } 374 374 375 $tab_index = $ r['tab_index'];375 $tab_index = $args['tab_index']; 376 376 377 377 $tab_index_attribute = ''; 378 378 if ( (int) $tab_index > 0 ) { … … 380 380 } 381 381 382 382 // Avoid clashes with the 'name' param of get_terms(). 383 $get_terms_args = $ r;383 $get_terms_args = $args; 384 384 unset( $get_terms_args['name'] ); 385 $categories = get_terms( $ r['taxonomy'], $get_terms_args );385 $categories = get_terms( $args['taxonomy'], $get_terms_args ); 386 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' : '';387 $name = esc_attr( $args['name'] ); 388 $class = esc_attr( $args['class'] ); 389 $id = $args['id'] ? esc_attr( $args['id'] ) : $name; 390 $required = $args['required'] ? 'required' : ''; 391 391 392 if ( ! $ r['hide_if_empty'] || ! empty( $categories ) ) {392 if ( ! $args['hide_if_empty'] || ! empty( $categories ) ) { 393 393 $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n"; 394 394 } else { 395 395 $output = ''; 396 396 } 397 if ( empty( $categories ) && ! $ r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) {397 if ( empty( $categories ) && ! $args['hide_if_empty'] && ! empty( $args['show_option_none'] ) ) { 398 398 399 399 /** 400 400 * Filters a taxonomy drop-down display element. … … 411 411 * @param string $element Category name. 412 412 * @param WP_Term|null $category The category object, or null if there's no corresponding category. 413 413 */ 414 $show_option_none = apply_filters( 'list_cats', $ r['show_option_none'], null );414 $show_option_none = apply_filters( 'list_cats', $args['show_option_none'], null ); 415 415 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; 416 416 } 417 417 418 418 if ( ! empty( $categories ) ) { 419 419 420 if ( $ r['show_option_all'] ) {420 if ( $args['show_option_all'] ) { 421 421 422 422 /** 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'" : '';423 $show_option_all = apply_filters( 'list_cats', $args['show_option_all'], null ); 424 $selected = ( '0' === strval( $args['selected'] ) ) ? " selected='selected'" : ''; 425 425 $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; 426 426 } 427 427 428 if ( $ r['show_option_none'] ) {428 if ( $args['show_option_none'] ) { 429 429 430 430 /** 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 );431 $show_option_none = apply_filters( 'list_cats', $args['show_option_none'], null ); 432 $selected = selected( $option_none_value, $args['selected'], false ); 433 433 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; 434 434 } 435 435 436 if ( $ r['hierarchical'] ) {437 $depth = $ r['depth']; // Walk the full depth.436 if ( $args['hierarchical'] ) { 437 $depth = $args['depth']; // Walk the full depth. 438 438 } else { 439 439 $depth = -1; // Flat. 440 440 } … … 441 441 $output .= walk_category_dropdown_tree( $categories, $depth, $r ); 442 442 } 443 443 444 if ( ! $ r['hide_if_empty'] || ! empty( $categories ) ) {444 if ( ! $args['hide_if_empty'] || ! empty( $categories ) ) { 445 445 $output .= "</select>\n"; 446 446 } 447 447 /** … … 454 454 */ 455 455 $output = apply_filters( 'wp_dropdown_cats', $output, $r ); 456 456 457 if ( $ r['echo'] ) {457 if ( $args['echo'] ) { 458 458 echo $output; 459 459 } 460 460 return $output; … … 537 537 'use_desc_for_title' => 1, 538 538 ); 539 539 540 $r = wp_parse_args( $args, $defaults ); 540 // Parse incoming $args into an array and merge it with $defaults 541 $args = wp_parse_args( $args, $defaults ); 541 542 542 if ( ! isset( $ r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {543 $ r['pad_counts'] = true;543 if ( ! isset( $args['pad_counts'] ) && $args['show_count'] && $args['hierarchical'] ) { 544 $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 == $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'] ) );551 if ( $args['exclude_tree'] ) { 552 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $args['exclude_tree'] ) ); 552 553 } 553 554 554 if ( $ r['exclude'] ) {555 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $ r['exclude'] ) );555 if ( $args['exclude'] ) { 556 $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $args['exclude'] ) ); 556 557 } 557 558 558 $ r['exclude_tree'] = $exclude_tree;559 $ r['exclude'] = '';559 $args['exclude_tree'] = $exclude_tree; 560 $args['exclude'] = ''; 560 561 } 561 562 562 if ( ! isset( $ r['class'] ) ) {563 $ r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];563 if ( ! isset( $args['class'] ) ) { 564 $args['class'] = ( 'category' == $args['taxonomy'] ) ? 'categories' : $args['taxonomy']; 564 565 } 565 566 566 if ( ! taxonomy_exists( $ r['taxonomy'] ) ) {567 if ( ! taxonomy_exists( $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'];571 $show_option_all = $args['show_option_all']; 572 $show_option_none = $args['show_option_none']; 572 573 573 574 $categories = get_categories( $r ); 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 ( $args['title_li'] && 'list' == $args['style'] && ( ! empty( $categories ) || ! $args['hide_title_if_empty'] ) ) { 578 $output = '<li class="' . esc_attr( $args['class'] ) . '">' . $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' == $args['style'] ) { 582 583 $output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; 583 584 } else { 584 585 $output .= $show_option_none; … … 590 591 $posts_page = ''; 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( $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 ) { 596 597 $_object_type = get_post_type_object( $object_type ); … … 613 614 } 614 615 615 616 $posts_page = esc_url( $posts_page ); 616 if ( 'list' == $ r['style'] ) {617 if ( 'list' == $args['style'] ) { 617 618 $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; 618 619 } else { 619 620 $output .= "<a href='$posts_page'>$show_option_all</a>"; … … 620 621 } 621 622 } 622 623 623 if ( empty( $ r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {624 if ( empty( $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 && $args['taxonomy'] === $current_term_object->taxonomy ) { 627 $args['current_category'] = get_queried_object_id(); 627 628 } 628 629 } 629 630 630 if ( $ r['hierarchical'] ) {631 $depth = $ r['depth'];631 if ( $args['hierarchical'] ) { 632 $depth = $args['depth']; 632 633 } else { 633 634 $depth = -1; // Flat. 634 635 } … … 635 636 $output .= walk_category_tree( $categories, $depth, $r ); 636 637 } 637 638 638 if ( $ r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {639 if ( $args['title_li'] && 'list' == $args['style'] && ( ! empty( $categories ) || ! $args['hide_title_if_empty'] ) ) { 639 640 $output .= '</ul></li>'; 640 641 } 641 642 … … 649 650 */ 650 651 $html = apply_filters( 'wp_list_categories', $output, $args ); 651 652 652 if ( $ r['echo'] ) {653 if ( $args['echo'] ) { 653 654 echo $html; 654 655 } else { 655 656 return $html;