diff --git src/wp-includes/class-walker-category.php src/wp-includes/class-walker-category.php
index da518c9..8ef3c58 100644
|
|
class Walker_Category extends Walker { |
170 | 170 | } elseif ( $category->term_id == $_current_term->parent ) { |
171 | 171 | $css_classes[] = 'current-cat-parent'; |
172 | 172 | } |
| 173 | while ( $_current_term->parent ) { |
| 174 | if ( $category->term_id == $_current_term->parent ) { |
| 175 | $css_classes[] = 'current-cat-ancestor'; |
| 176 | break; |
| 177 | } |
| 178 | $_current_term = get_term( $_current_term->parent, $category->taxonomy ); |
| 179 | } |
173 | 180 | } |
174 | 181 | } |
175 | 182 | |
diff --git tests/phpunit/tests/category/wpListCategories.php tests/phpunit/tests/category/wpListCategories.php
index 048f72d..e1b6884 100644
|
|
class Tests_Category_WpListCategories extends WP_UnitTestCase { |
307 | 307 | |
308 | 308 | $this->assertNotContains( '<li class="cat-item cat-item-' . $child2 . '">', $actual ); |
309 | 309 | } |
| 310 | |
| 311 | /** |
| 312 | * @ticket 10676 |
| 313 | */ |
| 314 | public function test_class_containing_current_cat_ancestor() { |
| 315 | $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) ); |
| 316 | $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) ); |
| 317 | $child2 = self::factory()->category->create( array( 'name' => 'Child 2', 'slug' => 'child2', 'parent' => $parent ) ); |
| 318 | $grandchild = self::factory()->category->create( array( 'name' => 'Grand Child', 'slug' => 'child', 'parent' => $child ) ); |
| 319 | |
| 320 | $actual = wp_list_categories( array( |
| 321 | 'echo' => 0, |
| 322 | 'hide_empty' => false, |
| 323 | 'current_category' => $grandchild, |
| 324 | ) ); |
| 325 | |
| 326 | $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual ); |
| 327 | $this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual ); |
| 328 | $this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual ); |
| 329 | $this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual ); |
| 330 | } |
310 | 331 | } |