Make WordPress Core

Ticket #9007: deprecate_get_category_children.9007.diff

File deprecate_get_category_children.9007.diff, 2.5 KB (added by filosofo, 16 years ago)

Deprecate get_category_children. Really, how often do you need a string of concatenated category children ids?

  • wp-includes/deprecated.php

     
    13031303        return get_comment($comment_ID, ARRAY_A);
    13041304}
    13051305
     1306/**
     1307 * Retrieve category children list separated before and after the term IDs.
     1308 *
     1309 * @since 1.2.0
     1310 * @deprecated Use get_term_children()
     1311 * @see get_term_children()
     1312 *
     1313 * @param int $id Category ID to retrieve children.
     1314 * @param string $before Optional. Prepend before category term ID.
     1315 * @param string $after Optional, default is empty string. Append after category term ID.
     1316 * @param array $visited Optional. Category Term IDs that have already been added.
     1317 * @return string
     1318 */
     1319function get_category_children( $id, $before = '/', $after = '' ) {
     1320        _deprecated_function(__FUNCTION__, '2.8', 'get_term_children()');
     1321        if ( 0 == $id )
     1322                return '';
     1323
     1324        $children = get_term_children( $id, 'category' );
     1325
     1326        if ( !is_wp_error( $children ) && !empty( $children ) )
     1327                $chain = $before . join( $after . $before, $children ) . $after;
     1328        else
     1329                $chain = '';
     1330           
     1331        return $chain;
     1332}
     1333
  • wp-includes/category-template.php

     
    77 */
    88
    99/**
    10  * Retrieve category children list separated before and after the term IDs.
    11  *
    12  * @since 1.2.0
    13  *
    14  * @param int $id Category ID to retrieve children.
    15  * @param string $before Optional. Prepend before category term ID.
    16  * @param string $after Optional, default is empty string. Append after category term ID.
    17  * @param array $visited Optional. Category Term IDs that have already been added.
    18  * @return string
    19  */
    20 function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
    21         if ( 0 == $id )
    22                 return '';
    23 
    24         $chain = '';
    25         /** TODO: consult hierarchy */
    26         $cat_ids = get_all_category_ids();
    27         foreach ( (array) $cat_ids as $cat_id ) {
    28                 if ( $cat_id == $id )
    29                         continue;
    30 
    31                 $category = get_category( $cat_id );
    32                 if ( is_wp_error( $category ) )
    33                         return $category;
    34                 if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
    35                         $visited[] = $category->term_id;
    36                         $chain .= $before.$category->term_id.$after;
    37                         $chain .= get_category_children( $category->term_id, $before, $after );
    38                 }
    39         }
    40         return $chain;
    41 }
    42 
    43 /**
    4410 * Retrieve category link URL.
    4511 *
    4612 * @since 1.0.0