WordPress.org

Make WordPress Core

Ticket #9667: Docs clarification + arg var name change + cast to absint.diff

File Docs clarification + arg var name change + cast to absint.diff, 2.3 KB (added by simonwheatley, 5 years ago)

Docs clarification, arg var name change, term ID arg cast to intval

  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/taxonomy.php

     
    406406} 
    407407 
    408408/** 
    409  * Merge all term children into a single array. 
     409 * Merge all term children into a single array of their IDs. 
    410410 * 
    411411 * This recursive function will merge all of the children of $term into the same 
    412  * array. Only useful for taxonomies which are hierarchical. 
     412 * array of term IDs. Only useful for taxonomies which are hierarchical. 
    413413 * 
    414414 * Will return an empty array if $term does not exist in $taxonomy. 
    415415 * 
     
    421421 * @uses _get_term_hierarchy() 
    422422 * @uses get_term_children() Used to get the children of both $taxonomy and the parent $term 
    423423 * 
    424  * @param string $term Name of Term to get children 
     424 * @param string $term ID of Term to get children 
    425425 * @param string $taxonomy Taxonomy Name 
    426426 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist 
    427427 */ 
    428 function get_term_children( $term, $taxonomy ) { 
     428function get_term_children( $term_id, $taxonomy ) { 
    429429        if ( ! is_taxonomy($taxonomy) ) 
    430430                return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 
    431431 
     432        $term_id = intval( $term_id ); 
     433 
    432434        $terms = _get_term_hierarchy($taxonomy); 
    433435 
    434         if ( ! isset($terms[$term]) ) 
     436        if ( ! isset($terms[$term_id]) ) 
    435437                return array(); 
    436438 
    437         $children = $terms[$term]; 
     439        $children = $terms[$term_id]; 
    438440 
    439         foreach ( (array) $terms[$term] as $child ) { 
     441        foreach ( (array) $terms[$term_id] as $child ) { 
    440442                if ( isset($terms[$child]) ) 
    441443                        $children = array_merge($children, get_term_children($child, $taxonomy)); 
    442444        } 
     
    19281930 
    19291931 
    19301932/** 
    1931  * Retrieves children of taxonomy. 
     1933 * Retrieves children of taxonomy as Term IDs. 
    19321934 * 
    19331935 * @package WordPress 
    19341936 * @subpackage Taxonomy 
     
    19391941 *       option. That is the name of the taxonomy, immediately followed by '_children'. 
    19401942 * 
    19411943 * @param string $taxonomy Taxonomy Name 
    1942  * @return array Empty if $taxonomy isn't hierarachical or returns children. 
     1944 * @return array Empty if $taxonomy isn't hierarachical or returns children as Term IDs. 
    19431945 */ 
    19441946function _get_term_hierarchy($taxonomy) { 
    19451947        if ( !is_taxonomy_hierarchical($taxonomy) )