diff --git src/wp-includes/category-template.php src/wp-includes/category-template.php
index 9a2120c..bedf4e0 100644
|
|
function wp_list_categories( $args = '' ) { |
532 | 532 | } |
533 | 533 | } else { |
534 | 534 | if ( ! empty( $show_option_all ) ) { |
535 | | $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); |
| 535 | |
| 536 | $posts_page = ''; |
| 537 | |
| 538 | // For taxonomies that belong only to custom post types, point to a valid archive. |
| 539 | $taxonomy_object = get_taxonomy( $r['taxonomy'] ); |
| 540 | if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) { |
| 541 | foreach ( $taxonomy_object->object_type as $object_type ) { |
| 542 | $_object_type = get_post_type_object( $object_type ); |
| 543 | |
| 544 | // Grab the first one. |
| 545 | if ( ! empty( $_object_type->has_archive ) ) { |
| 546 | $posts_page = get_post_type_archive_link( $object_type ); |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if ( ! $posts_page ) { |
| 553 | $posts_page = 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); |
| 554 | } |
| 555 | |
536 | 556 | $posts_page = esc_url( $posts_page ); |
537 | 557 | if ( 'list' == $r['style'] ) { |
538 | 558 | $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; |
diff --git tests/phpunit/tests/category/wpListCategories.php tests/phpunit/tests/category/wpListCategories.php
index 55af2f4..e16c902 100644
|
|
class Tests_Category_WpListCategories extends WP_UnitTestCase { |
100 | 100 | $this->assertContains( "<li class='cat-item-all'><a href='" . get_permalink( $p ) . "'>All</a></li>", $found ); |
101 | 101 | } |
102 | 102 | |
| 103 | /** |
| 104 | * @ticket 21881 |
| 105 | */ |
| 106 | public function test_show_option_all_link_should_link_to_post_type_archive_when_taxonomy_does_not_apply_to_posts() { |
| 107 | register_post_type( 'wptests_pt', array( 'has_archive' => true ) ); |
| 108 | register_post_type( 'wptests_pt2', array( 'has_archive' => true ) ); |
| 109 | register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) ); |
| 110 | |
| 111 | $terms = $this->factory->term->create_many( 2, array( |
| 112 | 'taxonomy' => 'wptests_tax', |
| 113 | ) ); |
| 114 | |
| 115 | $found = wp_list_categories( array( |
| 116 | 'echo' => false, |
| 117 | 'show_option_all' => 'All', |
| 118 | 'hide_empty' => false, |
| 119 | 'taxonomy' => 'wptests_tax', |
| 120 | ) ); |
| 121 | |
| 122 | $pt_archive = get_post_type_archive_link( 'wptests_pt' ); |
| 123 | |
| 124 | $this->assertContains( "<li class='cat-item-all'><a href='" . $pt_archive . "'>All</a></li>", $found ); |
| 125 | } |
| 126 | |
103 | 127 | public function list_cats_callback( $cat ) { |
104 | 128 | if ( 'Test Cat 1' === $cat ) { |
105 | 129 | return ''; |