diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php
index 971434baf2..e452ccda25 100644
--- a/src/wp-includes/category-template.php
+++ b/src/wp-includes/category-template.php
@@ -550,11 +550,11 @@ function wp_list_categories( $args = '' ) {
$exclude_tree = array();
if ( $r['exclude_tree'] ) {
- $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude_tree'] );
+ $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) );
}
if ( $r['exclude'] ) {
- $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude'] );
+ $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) );
}
$r['exclude_tree'] = $exclude_tree;
diff --git a/tests/phpunit/tests/category/wpListCategories.php b/tests/phpunit/tests/category/wpListCategories.php
index 048f72d367..dad221f7e7 100644
--- a/tests/phpunit/tests/category/wpListCategories.php
+++ b/tests/phpunit/tests/category/wpListCategories.php
@@ -307,4 +307,78 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase {
$this->assertNotContains( '
', $actual );
}
+
+ /**
+ * @ticket 35156
+ */
+ public function test_comma_separated_exclude_tree_should_be_merged_with_exclude() {
+ $c = self::factory()->category->create();
+ $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
+ $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
+ $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
+ $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
+ $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
+ $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
+ $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
+ $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
+
+
+ $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
+
+ $actual = wp_list_categories( array(
+ 'echo' => 0,
+ 'hide_empty' => 0,
+ 'exclude' => "$parent,$parent2",
+ 'exclude_tree' => "$parent3,$parent4",
+ ) );
+
+ $this->assertContains( '', $actual );
+
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ }
+
+ /**
+ * @ticket 35156
+ */
+ public function test_array_exclude_tree_should_be_merged_with_exclude() {
+ $c = self::factory()->category->create();
+ $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
+ $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
+ $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
+ $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
+ $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
+ $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
+ $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
+ $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
+
+
+ $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
+
+ $actual = wp_list_categories( array(
+ 'echo' => 0,
+ 'hide_empty' => 0,
+ 'exclude' => array( $parent, $parent2 ),
+ 'exclude_tree' => array( $parent3, $parent4 ),
+ ) );
+
+ $this->assertContains( '', $actual );
+
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertNotContains( '', $actual );
+ }
}