diff --git a/src/wp-includes/class-walker-category.php b/src/wp-includes/class-walker-category.php
index da518c9ee1..8ef3c58d52 100644
--- a/src/wp-includes/class-walker-category.php
+++ b/src/wp-includes/class-walker-category.php
@@ -170,6 +170,13 @@ class Walker_Category extends Walker {
} elseif ( $category->term_id == $_current_term->parent ) {
$css_classes[] = 'current-cat-parent';
}
+ while ( $_current_term->parent ) {
+ if ( $category->term_id == $_current_term->parent ) {
+ $css_classes[] = 'current-cat-ancestor';
+ break;
+ }
+ $_current_term = get_term( $_current_term->parent, $category->taxonomy );
+ }
}
}
diff --git a/tests/phpunit/tests/category/wpListCategories.php b/tests/phpunit/tests/category/wpListCategories.php
index dad221f7e7..061496a8a6 100644
--- a/tests/phpunit/tests/category/wpListCategories.php
+++ b/tests/phpunit/tests/category/wpListCategories.php
@@ -381,4 +381,25 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase {
$this->assertNotContains( '
', $actual );
$this->assertNotContains( '', $actual );
}
+
+ /**
+ * @ticket 10676
+ */
+ public function test_class_containing_current_cat_ancestor() {
+ $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
+ $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
+ $child2 = self::factory()->category->create( array( 'name' => 'Child 2', 'slug' => 'child2', 'parent' => $parent ) );
+ $grandchild = self::factory()->category->create( array( 'name' => 'Grand Child', 'slug' => 'child', 'parent' => $child ) );
+
+ $actual = wp_list_categories( array(
+ 'echo' => 0,
+ 'hide_empty' => false,
+ 'current_category' => $grandchild,
+ ) );
+
+ $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
+ $this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
+ $this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
+ $this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
+ }
}