Make WordPress Core

Changeset 27521


Ignore:
Timestamp:
03/13/2014 04:03:06 AM (11 years ago)
Author:
wonderboymusic
Message:

Avoid a notice in get_the_category_by_ID() when is_wp_error( $term ) is false but $term->name is not set. Clarify the @return value of get_category() and get_tag() which return the same possible types as get_term(), which they wrap.

Props ericmann, SergeyBiryukov.
Fixes #25429.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r27376 r27521  
    137137    $cat_ID = (int) $cat_ID;
    138138    $category = get_term( $cat_ID, 'category' );
     139
    139140    if ( is_wp_error( $category ) )
    140141        return $category;
    141     return $category->name;
     142
     143    return ( $category ) ? $category->name : '';
    142144}
    143145
  • trunk/src/wp-includes/category.php

    r25880 r27521  
    8686 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
    8787 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
    88  * @return mixed Category data in type defined by $output parameter.
     88 * @return object|array|WP_Error|null Category data in type defined by $output parameter. WP_Error if $category is empty, null if it does not exist.
    8989 */
    9090function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
    9191    $category = get_term( $category, 'category', $output, $filter );
     92
    9293    if ( is_wp_error( $category ) )
    9394        return $category;
     
    302303 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
    303304 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
    304  * @return object|array Return type based on $output value.
     305 * @return object|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist.
    305306 */
    306307function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) {
Note: See TracChangeset for help on using the changeset viewer.