Changeset 32292
- Timestamp:
- 04/24/2015 02:56:37 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r32026 r32292 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 // Fallback for the 'All' link is the front page. 553 if ( ! $posts_page ) { 554 $posts_page = 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); 555 } 556 536 557 $posts_page = esc_url( $posts_page ); 537 558 if ( 'list' == $r['style'] ) { -
trunk/tests/phpunit/tests/category/wpListCategories.php
r31301 r32292 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 127 /** 128 * @ticket 21881 129 */ 130 public function test_show_option_all_link_should_not_link_to_post_type_archive_if_has_archive_is_false() { 131 register_post_type( 'wptests_pt', array( 'has_archive' => false ) ); 132 register_post_type( 'wptests_pt2', array( 'has_archive' => true ) ); 133 register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) ); 134 135 $terms = $this->factory->term->create_many( 2, array( 136 'taxonomy' => 'wptests_tax', 137 ) ); 138 139 $found = wp_list_categories( array( 140 'echo' => false, 141 'show_option_all' => 'All', 142 'hide_empty' => false, 143 'taxonomy' => 'wptests_tax', 144 ) ); 145 146 $pt_archive = get_post_type_archive_link( 'wptests_pt2' ); 147 148 $this->assertContains( "<li class='cat-item-all'><a href='" . $pt_archive . "'>All</a></li>", $found ); 149 } 150 151 public function test_show_option_all_link_should_link_to_post_archive_if_available() { 152 register_post_type( 'wptests_pt', array( 'has_archive' => true ) ); 153 register_post_type( 'wptests_pt2', array( 'has_archive' => true ) ); 154 register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'post', 'wptests_pt2' ) ); 155 156 $terms = $this->factory->term->create_many( 2, array( 157 'taxonomy' => 'wptests_tax', 158 ) ); 159 160 $found = wp_list_categories( array( 161 'echo' => false, 162 'show_option_all' => 'All', 163 'hide_empty' => false, 164 'taxonomy' => 'wptests_tax', 165 ) ); 166 167 $url = home_url( '/' ); 168 169 $this->assertContains( "<li class='cat-item-all'><a href='" . $url . "'>All</a></li>", $found ); 170 } 171 172 public function test_show_option_all_link_should_link_to_post_archive_if_no_associated_post_types_have_archives() { 173 register_post_type( 'wptests_pt', array( 'has_archive' => false ) ); 174 register_post_type( 'wptests_pt2', array( 'has_archive' => false ) ); 175 register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) ); 176 177 $terms = $this->factory->term->create_many( 2, array( 178 'taxonomy' => 'wptests_tax', 179 ) ); 180 181 $found = wp_list_categories( array( 182 'echo' => false, 183 'show_option_all' => 'All', 184 'hide_empty' => false, 185 'taxonomy' => 'wptests_tax', 186 ) ); 187 188 $url = home_url( '/' ); 189 190 $this->assertContains( "<li class='cat-item-all'><a href='" . $url . "'>All</a></li>", $found ); 191 } 192 103 193 public function list_cats_callback( $cat ) { 104 194 if ( 'Test Cat 1' === $cat ) {
Note: See TracChangeset
for help on using the changeset viewer.