Make WordPress Core

Ticket #29839: 20141116_01-taxonomy.2.diff

File 20141116_01-taxonomy.2.diff, 2.6 KB (added by theMikeD, 10 years ago)

Patch for #29839: removed check for hierarchical taxonomy

  • src/wp-includes/taxonomy.php

     
    16161616 *     @type int          $child_of          Term ID to retrieve child terms of. If multiple taxonomies
    16171617 *                                           are passed, $child_of is ignored. Default 0.
    16181618 *     @type int|string   $parent            Parent term ID to retrieve direct-child terms of. Default empty.
     1619 *     @type bool         $childless         Returns terms that have no children. Null if taxonomy is not
     1620 *                                           hierarchical. Default false
    16191621 *     @type string       $cache_domain      Unique cache key to be produced when this query is stored in an
    16201622 *                                           object cache. Default is 'core'.
    16211623 * }
     
    16401642
    16411643        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    16421644                'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(),
    1643                 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
     1645                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'childless' => false,
    16441646                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '',
    16451647                'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' );
    16461648        $args = wp_parse_args( $args, $defaults );
     
    16591661        }
    16601662
    16611663        if ( 'all' == $args['get'] ) {
     1664                $args['childless'] = false;
    16621665                $args['child_of'] = 0;
    16631666                $args['hide_empty'] = 0;
    16641667                $args['hierarchical'] = false;
     
    17981801                }
    17991802        }
    18001803
     1804        $childless = (bool) $args['childless']; // boolean
     1805        if ( $childless ) {
     1806                $terms_to_exclude = "";
     1807                $term_hierarchy = _get_term_hierarchy( reset( $taxonomies ) );
     1808
     1809                // If $term_hierarchy is empty, then there are no exclusions because either the
     1810                //  $taxonomy is flat, or it's hierarchical but has no child terms. In both cases,
     1811                //  return everything
     1812                if ( ! empty( $term_hierarchy ) ) {
     1813                        // Any term listed in $term_hierarchy has by definition a child term, so exclude it
     1814                        foreach ( array_keys($term_hierarchy) as $excluded_index=>$excluded_id ) {
     1815                                if ( empty($terms_to_exclude) ) {
     1816                                        $terms_to_exclude = intval( $excluded_id );
     1817                                } else {
     1818                                        $terms_to_exclude .= ', ' . intval( $excluded_id );
     1819                                }
     1820                        }
     1821                        if ( empty( $exclusions ) ) {
     1822                                $exclusions = $terms_to_exclude;
     1823                        } else {
     1824                                $exclusions .= ', ' . $terms_to_exclude;
     1825                        }
     1826                }
     1827        }
     1828
    18011829        if ( ! empty( $exclusions ) ) {
    18021830                $exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')';
    18031831        }