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
This commit is contained in:
Scott Taylor 2014-03-07 19:29:16 +00:00
parent 3556e565b3
commit c353fa41a2

View File

@ -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;
}