diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 7f2c539676..ad66987f7b 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -996,6 +996,11 @@ class Walker_Category extends Walker { $category ); + // Don't generate an element if the category name is empty. + if ( ! $cat_name ) { + return; + } + $link = 'description ) ) { /** diff --git a/tests/phpunit/tests/category/wpListCategories.php b/tests/phpunit/tests/category/wpListCategories.php new file mode 100644 index 0000000000..dbd4cbb98d --- /dev/null +++ b/tests/phpunit/tests/category/wpListCategories.php @@ -0,0 +1,39 @@ +factory->category->create( array( + 'name' => 'Test Cat 1', + ) ); + $c2 = $this->factory->category->create( array( + 'name' => 'Test Cat 2', + ) ); + + add_filter( 'list_cats', array( $this, 'list_cats_callback' ) ); + $found = wp_list_categories( array( + 'hide_empty' => false, + 'echo' => false, + ) ); + remove_filter( 'list_cats', array( $this, 'list_cats_callback' ) ); + + $this->assertContains( "cat-item-$c2", $found ); + $this->assertContains( 'Test Cat 2', $found ); + + $this->assertNotContains( "cat-item-$c1", $found ); + $this->assertNotContains( 'Test Cat 1', $found ); + } + + public function list_cats_callback( $cat ) { + if ( 'Test Cat 1' === $cat ) { + return ''; + } + + return $cat; + } +}