From 03f3c454ca60501efbd53a873acf2783286bebf9 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 26 Oct 2013 19:00:57 +0000 Subject: [PATCH] Fix the exclude_tree argument in get_terms(), which fixes the exclude argument in wp_list_categories(). Merges [25933] to the 3.7 branch. This was a 3.7 regression caused by [25162]. props dd32. fixes #25710. git-svn-id: https://develop.svn.wordpress.org/branches/3.7@25936 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 2 +- tests/phpunit/tests/term/getTerms.php | 32 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index c8191fe0b0..4bf48a93d6 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1362,7 +1362,7 @@ function get_terms($taxonomies, $args = '') { $exclusions = ''; if ( ! empty( $exclude_tree ) ) { $exclude_tree = wp_parse_id_list( $exclude_tree ); - $excluded_children = array(); + $excluded_children = $exclude_tree; foreach ( $exclude_tree as $extrunk ) { $excluded_children = array_merge( $excluded_children, diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index eb576e659a..7709e8d17e 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -151,6 +151,38 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->assertEmpty( $wpdb->last_error ); } + /** + * @ticket 25710 + */ + function test_get_terms_exclude_tree() { + + $term_id_uncategorized = get_option( 'default_category' ); + + $term_id1 = $this->factory->category->create(); + $term_id11 = $this->factory->category->create( array( 'parent' => $term_id1 ) ); + $term_id2 = $this->factory->category->create(); + $term_id22 = $this->factory->category->create( array( 'parent' => $term_id2 ) ); + + // There's something else broken in the cache cleaning routines that leads to this having to be done manually + delete_option( 'category_children' ); + + $terms = get_terms( 'category', array( + 'exclude' => $term_id_uncategorized, + 'fields' => 'ids', + 'hide_empty' => false, + ) ); + $this->assertEquals( array( $term_id1, $term_id11, $term_id2, $term_id22 ), $terms ); + + $terms = get_terms( 'category', array( + 'fields' => 'ids', + 'exclude_tree' => "$term_id1,$term_id_uncategorized", + 'hide_empty' => false, + ) ); + + $this->assertEquals( array( $term_id2, $term_id22 ), $terms ); + + } + /** * @ticket 13992 */