Make WordPress Core

Ticket #29839: taxonomy-20141113_01.diff

File taxonomy-20141113_01.diff, 2.6 KB (added by theMikeD, 11 years ago)

Code fix for #29839

  • taxonomy.php

     
    16401640
    16411641        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    16421642                'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(),
    1643                 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
     1643                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'children_only' => '',
    16441644                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '',
    16451645                'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' );
    16461646        $args = wp_parse_args( $args, $defaults );
     
    16531653                $args['pad_counts'] = false;
    16541654        }
    16551655
    1656         // 'parent' overrides 'child_of'.
     1656        // 'parent' overrides 'child_of'
    16571657        if ( 0 < intval( $args['parent'] ) ) {
    16581658                $args['child_of'] = false;
    16591659        }
    16601660
    16611661        if ( 'all' == $args['get'] ) {
     1662                $args['children_only'] = 0;
    16621663                $args['child_of'] = 0;
    16631664                $args['hide_empty'] = 0;
    16641665                $args['hierarchical'] = false;
     
    16911692                }
    16921693        }
    16931694
     1695    // Check for heirarchical taxonomy
     1696        $children_only = $args['children_only']; // boolean
     1697        if ( $children_only ) {
     1698                // Empty if taxonomy is not heirarchical; term ids if it is.
     1699                // Note that we are not checking for a specific child or parent, just the
     1700                //  existence of an heirarchical taxonomy
     1701                $hierarchy = _get_term_hierarchy( reset( $taxonomies ) );
     1702                if ( empty( $hierarchy )) {
     1703                        return $empty_array;
     1704                }
     1705        }
     1706
    16941707        // $args can be whatever, only use the args defined in defaults to compute the key
    16951708        $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    16961709        $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key );
     
    17981811                }
    17991812        }
    18001813
     1814        if ( $children_only ) {
     1815                $terms_to_exclude = "";
     1816                $term_heirarchy = _get_term_hierarchy( reset( $taxonomies ) );
     1817                if ( ! empty( $term_heirarchy ) ) {
     1818                        // Any term listed in $term_heirarchy has by definition a child term, so exclude it
     1819                        foreach ( array_keys($term_heirarchy) as $excluded_index=>$excluded_id ) {
     1820                                if ( empty($terms_to_exclude) ) {
     1821                                        $terms_to_exclude = $excluded_id;
     1822                                } else {
     1823                                        $terms_to_exclude .= ', ' . $excluded_id;
     1824                                }
     1825                        }
     1826                }
     1827                if ( empty( $exclusions ) ) {
     1828                        $exclusions = $terms_to_exclude;
     1829                } else {
     1830                        $exclusions .= ', ' . $terms_to_exclude;
     1831                }
     1832        }
     1833
    18011834        if ( ! empty( $exclusions ) ) {
    18021835                $exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')';
    18031836        }