Make WordPress Core

Changeset 32532


Ignore:
Timestamp:
05/21/2015 09:17:42 PM (10 years ago)
Author:
wonderboymusic
Message:

In category.php:

  • Clarify some return docs.
  • In _make_cat_compat(), ensure that WP_Error is not decorated

See #32444.

File:
1 edited

Legend:

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

    r32116 r32532  
    6969 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
    7070 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
    71  * @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.
     71 * @return object|array|WP_Error|null Category data in type defined by $output parameter.
     72 *                                    WP_Error if $category is empty, null if it does not exist.
    7273 */
    7374function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
     
    99100 * @param bool $full_match Optional. Whether full path should be matched.
    100101 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
    101  * @return null|object|array Null on failure. Type is based on $output value.
     102 * @return null|object|array|WP_Error Null on failure. Type is based on $output value.
    102103 */
    103104function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {
     
    109110    $category_paths = explode( '/', $category_paths );
    110111    $full_path = '';
    111     foreach ( (array) $category_paths as $pathdir )
     112    foreach ( (array) $category_paths as $pathdir ) {
    112113        $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
    113 
     114    }
    114115    $categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );
    115116
    116     if ( empty( $categories ) )
    117         return null;
     117    if ( empty( $categories ) ) {
     118        return;
     119    }
    118120
    119121    foreach ( $categories as $category ) {
     
    122124        while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {
    123125            $curcategory = get_term( $curcategory->parent, 'category' );
    124             if ( is_wp_error( $curcategory ) )
     126            if ( is_wp_error( $curcategory ) ) {
    125127                return $curcategory;
     128            }
    126129            $path = '/' . $curcategory->slug . $path;
    127130        }
     
    140143        return $category;
    141144    }
    142 
    143     return null;
    144145}
    145146
     
    322323 */
    323324function _make_cat_compat( &$category ) {
    324     if ( is_object( $category ) ) {
     325    if ( is_object( $category ) && ! is_wp_error( $category ) ) {
    325326        $category->cat_ID = &$category->term_id;
    326327        $category->category_count = &$category->count;
Note: See TracChangeset for help on using the changeset viewer.