From c353fa41a21bda386676bf1513a6146193b2f117 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 7 Mar 2014 19:29:16 +0000 Subject: [PATCH] In `get_terms()`, leverage `get_term_children()` over `_get_term_children()` when making sure to show empty terms that have children in a hierarchical taxonomy while avoiding duplicates. Adds unit test for `child_of` param. Adjusts unit tests for `get_terms()`. See [27108] and [27125]. Props SergeyBiryukov. Fixes #27123. Built from https://develop.svn.wordpress.org/trunk@27458 git-svn-id: http://core.svn.wordpress.org/trunk@27304 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index de6adbb0b9..a7baa167ef 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1477,11 +1477,15 @@ function get_terms($taxonomies, $args = '') { if ( $hierarchical && $hide_empty && is_array( $terms ) ) { foreach ( $terms as $k => $term ) { if ( ! $term->count ) { - $children = _get_term_children( $term->term_id, $terms, reset( $taxonomies ) ); - if ( is_array( $children ) ) - foreach ( $children as $child ) - if ( $child->count ) + $children = get_term_children( $term->term_id, reset( $taxonomies ) ); + if ( is_array( $children ) ) { + foreach ( $children as $child_id ) { + $child = get_term( $child_id, reset( $taxonomies ) ); + if ( $child->count ) { continue 2; + } + } + } // It really is empty unset($terms[$k]); @@ -2923,20 +2927,6 @@ function _get_term_children($term_id, $terms, $taxonomy) { } if ( $term->term_id == $term_id ) { - if ( isset( $has_children[$term_id] ) ) { - $current_id = $term_id; - while ( $current_id > 0 ) { - foreach ( $has_children[$current_id] as $t_id ) { - if ( $use_id ) { - $term_list[] = $t_id; - } else { - $term_list[] = get_term( $t_id, $taxonomy ); - } - } - - $current_id = isset( $has_children[$t_id] ) ? $t_id : 0; - } - } continue; }