Ticket #33565: 33565.diff
File 33565.diff, 4.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/category-template.php
462 462 * 463 463 * @since 2.1.0 464 464 * @since 4.4.0 Introduced the `hide_title_if_no_cats` argument. 465 * @since 4.4.0 Added option to pass an array of objects or IDs to $current_category 465 466 * 466 467 * @param string|array $args { 467 468 * Array of optional arguments. … … 488 489 * @type array|string $exclude_tree Array or comma/space-separated string of term IDs to exclude, along 489 490 * with their descendants. See {@link get_terms()}. Default empty string. 490 491 * @type bool|int $echo True to echo markup, false to return it. Default 1. 491 * @type int $current_category Category that should get the 'current-cat' class. Default 0. 492 * @type array|int $current_category Category , array of category objects or an array of category IDs 493 * that should get the 'current-cat' class. Default 0. 492 494 * @type bool $hierarchical Whether to include terms that have non-empty descendants. 493 495 * See {@link get_terms()}. Default true. 494 496 * @type string $title_li Text to use for the list title `<li>` element. Pass an empty string … … 1121 1123 ); 1122 1124 1123 1125 if ( ! empty( $args['current_category'] ) ) { 1124 $_current_category = get_term( $args['current_category'], $category->taxonomy ); 1125 if ( $category->term_id == $args['current_category'] ) { 1126 $css_classes[] = 'current-cat'; 1127 } elseif ( $category->term_id == $_current_category->parent ) { 1128 $css_classes[] = 'current-cat-parent'; 1126 if (is_array($args['current_category'])) { 1127 $current_terms = $args['current_category']; 1128 foreach ($current_terms as $current_term) { 1129 if (is_object($current_term)) $current_term = $current_term->term_id; 1130 if (is_numeric($current_term)) { 1131 $_current_category = get_term( $current_term, $category->taxonomy ); 1132 if ( $category->term_id == $current_term ) { 1133 $css_classes[] = 'current-cat'; 1134 } elseif ( $category->term_id == $_current_category->parent ) { 1135 $css_classes[] = 'current-cat-parent'; 1136 } 1137 } 1138 } 1139 } else { 1140 $_current_category = get_term( $args['current_category'], $category->taxonomy ); 1141 if ( $category->term_id == $args['current_category'] ) { 1142 $css_classes[] = 'current-cat'; 1143 } elseif ( $category->term_id == $_current_category->parent ) { 1144 $css_classes[] = 'current-cat-parent'; 1145 } 1129 1146 } 1130 1147 } 1131 1148 -
tests/phpunit/tests/category/wpListCategories.php
247 247 248 248 $this->assertContains( '<li class="categories">Categories', $found ); 249 249 } 250 251 /** 252 * @ticket 33565 253 */ 254 public function test_pass_array_of_objects_to_current_category() { 255 $c1 = $this->factory->category->create(); 256 $c2 = $this->factory->category->create(); 257 $c3 = $this->factory->category->create(); 258 $object1 = $this->category_factory->get_object_by_id( $c1 ); 259 $object2 = $this->category_factory->get_object_by_id( $c2 ); 260 $object3 = $this->category_factory->get_object_by_id( $c3 ); 261 262 $found = wp_list_categories( array( 263 'echo' => false, 264 'hide_empty' => false, 265 'current_category' => array($object2,$object3), 266 ) ); 267 268 $this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found ); 269 $this->assertRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found ); 270 $this->assertRegExp( '/class="[^"]*cat-item-' . $c3 . '[^"]*current-cat[^"]*"/', $found ); 271 } 272 273 /** 274 * @ticket 33565 275 */ 276 public function test_pass_array_of_ids_to_current_category() { 277 $c1 = $this->factory->category->create(); 278 $c2 = $this->factory->category->create(); 279 $c3 = $this->factory->category->create(); 280 281 $found = wp_list_categories( array( 282 'echo' => false, 283 'hide_empty' => false, 284 'current_category' => array($c2,$c3), 285 ) ); 286 287 $this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found ); 288 $this->assertRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found ); 289 $this->assertRegExp( '/class="[^"]*cat-item-' . $c3 . '[^"]*current-cat[^"]*"/', $found ); 290 } 250 291 }