Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r40028 r42343  
    2626function get_categories( $args = '' ) {
    2727    $defaults = array( 'taxonomy' => 'category' );
    28     $args = wp_parse_args( $args, $defaults );
     28    $args     = wp_parse_args( $args, $defaults );
    2929
    3030    $taxonomy = $args['taxonomy'];
     
    4141
    4242    // Back compat
    43     if ( isset($args['type']) && 'link' == $args['type'] ) {
    44         _deprecated_argument( __FUNCTION__, '3.0.0',
     43    if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
     44        _deprecated_argument(
     45            __FUNCTION__, '3.0.0',
    4546            /* translators: 1: "type => link", 2: "taxonomy => link_category" */
    46             sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),
     47            sprintf(
     48                __( '%1$s is deprecated. Use %2$s instead.' ),
    4749                '<code>type => link</code>',
    4850                '<code>taxonomy => link_category</code>'
     
    9294    $category = get_term( $category, 'category', $output, $filter );
    9395
    94     if ( is_wp_error( $category ) )
     96    if ( is_wp_error( $category ) ) {
    9597        return $category;
     98    }
    9699
    97100    _make_cat_compat( $category );
     
    121124 */
    122125function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {
    123     $category_path = rawurlencode( urldecode( $category_path ) );
    124     $category_path = str_replace( '%2F', '/', $category_path );
    125     $category_path = str_replace( '%20', ' ', $category_path );
     126    $category_path  = rawurlencode( urldecode( $category_path ) );
     127    $category_path  = str_replace( '%2F', '/', $category_path );
     128    $category_path  = str_replace( '%20', ' ', $category_path );
    126129    $category_paths = '/' . trim( $category_path, '/' );
    127     $leaf_path  = sanitize_title( basename( $category_paths ) );
     130    $leaf_path      = sanitize_title( basename( $category_paths ) );
    128131    $category_paths = explode( '/', $category_paths );
    129     $full_path = '';
     132    $full_path      = '';
    130133    foreach ( (array) $category_paths as $pathdir ) {
    131134        $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
    132135    }
    133     $categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );
     136    $categories = get_terms(
     137        'category', array(
     138            'get'  => 'all',
     139            'slug' => $leaf_path,
     140        )
     141    );
    134142
    135143    if ( empty( $categories ) ) {
     
    138146
    139147    foreach ( $categories as $category ) {
    140         $path = '/' . $leaf_path;
     148        $path        = '/' . $leaf_path;
    141149        $curcategory = $category;
    142150        while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {
     
    171179 * @return object Category data object
    172180 */
    173 function get_category_by_slug( $slug  ) {
     181function get_category_by_slug( $slug ) {
    174182    $category = get_term_by( 'slug', $slug, 'category' );
    175     if ( $category )
     183    if ( $category ) {
    176184        _make_cat_compat( $category );
     185    }
    177186
    178187    return $category;
     
    189198function get_cat_ID( $cat_name ) {
    190199    $cat = get_term_by( 'name', $cat_name, 'category' );
    191     if ( $cat )
     200    if ( $cat ) {
    192201        return $cat->term_id;
     202    }
    193203    return 0;
    194204}
     
    203213 */
    204214function get_cat_name( $cat_id ) {
    205     $cat_id = (int) $cat_id;
     215    $cat_id   = (int) $cat_id;
    206216    $category = get_term( $cat_id, 'category' );
    207     if ( ! $category || is_wp_error( $category ) )
     217    if ( ! $category || is_wp_error( $category ) ) {
    208218        return '';
     219    }
    209220    return $category->name;
    210221}
     
    344355function _make_cat_compat( &$category ) {
    345356    if ( is_object( $category ) && ! is_wp_error( $category ) ) {
    346         $category->cat_ID = $category->term_id;
    347         $category->category_count = $category->count;
     357        $category->cat_ID               = $category->term_id;
     358        $category->category_count       = $category->count;
    348359        $category->category_description = $category->description;
    349         $category->cat_name = $category->name;
    350         $category->category_nicename = $category->slug;
    351         $category->category_parent = $category->parent;
     360        $category->cat_name             = $category->name;
     361        $category->category_nicename    = $category->slug;
     362        $category->category_parent      = $category->parent;
    352363    } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
    353         $category['cat_ID'] = &$category['term_id'];
    354         $category['category_count'] = &$category['count'];
     364        $category['cat_ID']               = &$category['term_id'];
     365        $category['category_count']       = &$category['count'];
    355366        $category['category_description'] = &$category['description'];
    356         $category['cat_name'] = &$category['name'];
    357         $category['category_nicename'] = &$category['slug'];
    358         $category['category_parent'] = &$category['parent'];
    359     }
    360 }
     367        $category['cat_name']             = &$category['name'];
     368        $category['category_nicename']    = &$category['slug'];
     369        $category['category_parent']      = &$category['parent'];
     370    }
     371}
Note: See TracChangeset for help on using the changeset viewer.