Make WordPress Core


Ignore:
Timestamp:
07/25/2019 12:47:53 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rename $r variable used with wp_parse_args() to $parsed_args for clarity.

Props freewebmentor.
Fixes #45059.

File:
1 edited

Legend:

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

    r45652 r45667  
    614614    );
    615615
    616     $r = wp_parse_args( $args, $defaults );
    617 
    618     $children = get_posts( $r );
     616    $parsed_args = wp_parse_args( $args, $defaults );
     617
     618    $children = get_posts( $parsed_args );
    619619
    620620    if ( ! $children ) {
     
    622622    }
    623623
    624     if ( ! empty( $r['fields'] ) ) {
     624    if ( ! empty( $parsed_args['fields'] ) ) {
    625625        return $children;
    626626    }
     
    19551955    );
    19561956
    1957     $r = wp_parse_args( $args, $defaults );
    1958     if ( empty( $r['post_status'] ) ) {
    1959         $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';
    1960     }
    1961     if ( ! empty( $r['numberposts'] ) && empty( $r['posts_per_page'] ) ) {
    1962         $r['posts_per_page'] = $r['numberposts'];
    1963     }
    1964     if ( ! empty( $r['category'] ) ) {
    1965         $r['cat'] = $r['category'];
    1966     }
    1967     if ( ! empty( $r['include'] ) ) {
    1968         $incposts            = wp_parse_id_list( $r['include'] );
    1969         $r['posts_per_page'] = count( $incposts );  // only the number of posts included
    1970         $r['post__in']       = $incposts;
    1971     } elseif ( ! empty( $r['exclude'] ) ) {
    1972         $r['post__not_in'] = wp_parse_id_list( $r['exclude'] );
    1973     }
    1974 
    1975     $r['ignore_sticky_posts'] = true;
    1976     $r['no_found_rows']       = true;
     1957    $parsed_args = wp_parse_args( $args, $defaults );
     1958    if ( empty( $parsed_args['post_status'] ) ) {
     1959        $parsed_args['post_status'] = ( 'attachment' == $parsed_args['post_type'] ) ? 'inherit' : 'publish';
     1960    }
     1961    if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
     1962        $parsed_args['posts_per_page'] = $parsed_args['numberposts'];
     1963    }
     1964    if ( ! empty( $parsed_args['category'] ) ) {
     1965        $parsed_args['cat'] = $parsed_args['category'];
     1966    }
     1967    if ( ! empty( $parsed_args['include'] ) ) {
     1968        $incposts                      = wp_parse_id_list( $parsed_args['include'] );
     1969        $parsed_args['posts_per_page'] = count( $incposts );  // only the number of posts included
     1970        $parsed_args['post__in']       = $incposts;
     1971    } elseif ( ! empty( $parsed_args['exclude'] ) ) {
     1972        $parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] );
     1973    }
     1974
     1975    $parsed_args['ignore_sticky_posts'] = true;
     1976    $parsed_args['no_found_rows']       = true;
    19771977
    19781978    $get_posts = new WP_Query;
    1979     return $get_posts->query( $r );
     1979    return $get_posts->query( $parsed_args );
    19801980
    19811981}
     
    33823382    );
    33833383
    3384     $r = wp_parse_args( $args, $defaults );
    3385 
    3386     $results = get_posts( $r );
     3384    $parsed_args = wp_parse_args( $args, $defaults );
     3385
     3386    $results = get_posts( $parsed_args );
    33873387
    33883388    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
     
    51125112    );
    51135113
    5114     $r = wp_parse_args( $args, $defaults );
    5115 
    5116     $number       = (int) $r['number'];
    5117     $offset       = (int) $r['offset'];
    5118     $child_of     = (int) $r['child_of'];
    5119     $hierarchical = $r['hierarchical'];
    5120     $exclude      = $r['exclude'];
    5121     $meta_key     = $r['meta_key'];
    5122     $meta_value   = $r['meta_value'];
    5123     $parent       = $r['parent'];
    5124     $post_status  = $r['post_status'];
     5114    $parsed_args = wp_parse_args( $args, $defaults );
     5115
     5116    $number       = (int) $parsed_args['number'];
     5117    $offset       = (int) $parsed_args['offset'];
     5118    $child_of     = (int) $parsed_args['child_of'];
     5119    $hierarchical = $parsed_args['hierarchical'];
     5120    $exclude      = $parsed_args['exclude'];
     5121    $meta_key     = $parsed_args['meta_key'];
     5122    $meta_value   = $parsed_args['meta_value'];
     5123    $parent       = $parsed_args['parent'];
     5124    $post_status  = $parsed_args['post_status'];
    51255125
    51265126    // Make sure the post type is hierarchical.
    51275127    $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
    5128     if ( ! in_array( $r['post_type'], $hierarchical_post_types ) ) {
     5128    if ( ! in_array( $parsed_args['post_type'], $hierarchical_post_types ) ) {
    51295129        return false;
    51305130    }
     
    51435143
    51445144    // $args can be whatever, only use the args defined in defaults to compute the key.
    5145     $key          = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
     5145    $key          = md5( serialize( wp_array_slice_assoc( $parsed_args, array_keys( $defaults ) ) ) );
    51465146    $last_changed = wp_cache_get_last_changed( 'posts' );
    51475147
     
    51525152        $pages = array_map( 'get_post', $cache );
    51535153        /** This filter is documented in wp-includes/post.php */
    5154         $pages = apply_filters( 'get_pages', $pages, $r );
     5154        $pages = apply_filters( 'get_pages', $pages, $parsed_args );
    51555155        return $pages;
    51565156    }
    51575157
    51585158    $inclusions = '';
    5159     if ( ! empty( $r['include'] ) ) {
     5159    if ( ! empty( $parsed_args['include'] ) ) {
    51605160        $child_of     = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
    51615161        $parent       = -1;
     
    51645164        $meta_value   = '';
    51655165        $hierarchical = false;
    5166         $incpages     = wp_parse_id_list( $r['include'] );
     5166        $incpages     = wp_parse_id_list( $parsed_args['include'] );
    51675167        if ( ! empty( $incpages ) ) {
    51685168            $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')';
     
    51795179
    51805180    $author_query = '';
    5181     if ( ! empty( $r['authors'] ) ) {
    5182         $post_authors = wp_parse_list( $r['authors'] );
     5181    if ( ! empty( $parsed_args['authors'] ) ) {
     5182        $post_authors = wp_parse_list( $parsed_args['authors'] );
    51835183
    51845184        if ( ! empty( $post_authors ) ) {
     
    52345234
    52355235    if ( 1 == count( $post_status ) ) {
    5236         $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $r['post_type'], reset( $post_status ) );
     5236        $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $parsed_args['post_type'], reset( $post_status ) );
    52375237    } else {
    52385238        $post_status     = implode( "', '", $post_status );
    5239         $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );
     5239        $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $parsed_args['post_type'] );
    52405240    }
    52415241
     
    52625262    );
    52635263
    5264     foreach ( explode( ',', $r['sort_column'] ) as $orderby ) {
     5264    foreach ( explode( ',', $parsed_args['sort_column'] ) as $orderby ) {
    52655265        $orderby = trim( $orderby );
    52665266        if ( ! in_array( $orderby, $allowed_keys ) ) {
     
    52935293    $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
    52945294
    5295     $sort_order = strtoupper( $r['sort_order'] );
     5295    $sort_order = strtoupper( $parsed_args['sort_order'] );
    52965296    if ( '' !== $sort_order && ! in_array( $sort_order, array( 'ASC', 'DESC' ) ) ) {
    52975297        $sort_order = 'ASC';
     
    53125312
    53135313        /** This filter is documented in wp-includes/post.php */
    5314         $pages = apply_filters( 'get_pages', array(), $r );
     5314        $pages = apply_filters( 'get_pages', array(), $parsed_args );
    53155315        return $pages;
    53165316    }
     
    53295329    }
    53305330
    5331     if ( ! empty( $r['exclude_tree'] ) ) {
    5332         $exclude = wp_parse_id_list( $r['exclude_tree'] );
     5331    if ( ! empty( $parsed_args['exclude_tree'] ) ) {
     5332        $exclude = wp_parse_id_list( $parsed_args['exclude_tree'] );
    53335333        foreach ( $exclude as $id ) {
    53345334            $children = get_page_children( $id, $pages );
     
    53625362     *
    53635363     * @param array $pages List of pages to retrieve.
    5364      * @param array $r     Array of get_pages() arguments.
     5364     * @param array $parsed_args     Array of get_pages() arguments.
    53655365     */
    5366     return apply_filters( 'get_pages', $pages, $r );
     5366    return apply_filters( 'get_pages', $pages, $parsed_args );
    53675367}
    53685368
Note: See TracChangeset for help on using the changeset viewer.