Make WordPress Core


Ignore:
Timestamp:
12/21/2016 05:33:15 AM (8 years ago)
Author:
pento
Message:

REST API: Improve the rest_*_collection_params filter docs and fix the terms filter.

The rest_{$taxonomy}_collection_params filter in 4.7 is incorrectly using single quotes instead of double quotes, which means it is not working correctly as a dynamic filter. This fixes the quotes around the filter name, and also updates the docblocks for the other 3 similar filters for better conformance to the documentation standards.

Merge of [39621] to the 4.7 branch.

Props shazahm1hotmailcom, JPry, jnylen0.
Fixes #39300.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r39630 r39631  
    19861986     */
    19871987    public function get_collection_params() {
    1988         $params = parent::get_collection_params();
    1989 
    1990         $params['context']['default'] = 'view';
    1991 
    1992         $params['after'] = array(
     1988        $query_params = parent::get_collection_params();
     1989
     1990        $query_params['context']['default'] = 'view';
     1991
     1992        $query_params['after'] = array(
    19931993            'description'        => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
    19941994            'type'               => 'string',
     
    19971997
    19981998        if ( post_type_supports( $this->post_type, 'author' ) ) {
    1999             $params['author'] = array(
     1999            $query_params['author'] = array(
    20002000                'description'         => __( 'Limit result set to posts assigned to specific authors.' ),
    20012001                'type'                => 'array',
     
    20052005                'default'             => array(),
    20062006            );
    2007             $params['author_exclude'] = array(
     2007            $query_params['author_exclude'] = array(
    20082008                'description'         => __( 'Ensure result set excludes posts assigned to specific authors.' ),
    20092009                'type'                => 'array',
     
    20152015        }
    20162016
    2017         $params['before'] = array(
     2017        $query_params['before'] = array(
    20182018            'description'        => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
    20192019            'type'               => 'string',
     
    20212021        );
    20222022
    2023         $params['exclude'] = array(
     2023        $query_params['exclude'] = array(
    20242024            'description'        => __( 'Ensure result set excludes specific IDs.' ),
    20252025            'type'               => 'array',
     
    20302030        );
    20312031
    2032         $params['include'] = array(
     2032        $query_params['include'] = array(
    20332033            'description'        => __( 'Limit result set to specific IDs.' ),
    20342034            'type'               => 'array',
     
    20402040
    20412041        if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
    2042             $params['menu_order'] = array(
     2042            $query_params['menu_order'] = array(
    20432043                'description'        => __( 'Limit result set to posts with a specific menu_order value.' ),
    20442044                'type'               => 'integer',
     
    20462046        }
    20472047
    2048         $params['offset'] = array(
     2048        $query_params['offset'] = array(
    20492049            'description'        => __( 'Offset the result set by a specific number of items.' ),
    20502050            'type'               => 'integer',
    20512051        );
    20522052
    2053         $params['order'] = array(
     2053        $query_params['order'] = array(
    20542054            'description'        => __( 'Order sort attribute ascending or descending.' ),
    20552055            'type'               => 'string',
     
    20582058        );
    20592059
    2060         $params['orderby'] = array(
     2060        $query_params['orderby'] = array(
    20612061            'description'        => __( 'Sort collection by object attribute.' ),
    20622062            'type'               => 'string',
     
    20732073
    20742074        if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
    2075             $params['orderby']['enum'][] = 'menu_order';
    2076         }
    2077 
    2078         $post_type_obj = get_post_type_object( $this->post_type );
    2079 
    2080         if ( $post_type_obj->hierarchical || 'attachment' === $this->post_type ) {
    2081             $params['parent'] = array(
     2075            $query_params['orderby']['enum'][] = 'menu_order';
     2076        }
     2077
     2078        $post_type = get_post_type_object( $this->post_type );
     2079
     2080        if ( $post_type->hierarchical || 'attachment' === $this->post_type ) {
     2081            $query_params['parent'] = array(
    20822082                'description'       => __( 'Limit result set to those of particular parent IDs.' ),
    20832083                'type'              => 'array',
     
    20872087                'default'           => array(),
    20882088            );
    2089             $params['parent_exclude'] = array(
     2089            $query_params['parent_exclude'] = array(
    20902090                'description'       => __( 'Limit result set to all items except those of a particular parent ID.' ),
    20912091                'type'              => 'array',
     
    20972097        }
    20982098
    2099         $params['slug'] = array(
     2099        $query_params['slug'] = array(
    21002100            'description'       => __( 'Limit result set to posts with one or more specific slugs.' ),
    21012101            'type'              => 'array',
     
    21062106        );
    21072107
    2108         $params['status'] = array(
     2108        $query_params['status'] = array(
    21092109            'default'           => 'publish',
    21102110            'description'       => __( 'Limit result set to posts assigned one or more statuses.' ),
     
    21222122            $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
    21232123
    2124             $params[ $base ] = array(
     2124            $query_params[ $base ] = array(
    21252125                /* translators: %s: taxonomy name */
    21262126                'description'       => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ),
     
    21322132            );
    21332133
    2134             $params[ $base . '_exclude' ] = array(
     2134            $query_params[ $base . '_exclude' ] = array(
    21352135                /* translators: %s: taxonomy name */
    21362136                'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ),
     
    21442144
    21452145        if ( 'post' === $this->post_type ) {
    2146             $params['sticky'] = array(
     2146            $query_params['sticky'] = array(
    21472147                'description'       => __( 'Limit result set to items that are sticky.' ),
    21482148                'type'              => 'boolean',
     
    21622162         * @since 4.7.0
    21632163         *
    2164          * @param $params JSON Schema-formatted collection parameters.
    2165          * @param WP_Post_Type $post_type_obj Post type object.
     2164         * @param array        $query_params JSON Schema-formatted collection parameters.
     2165         * @param WP_Post_Type $post_type    Post type object.
    21662166         */
    2167         return apply_filters( "rest_{$this->post_type}_collection_params", $params, $post_type_obj );
     2167        return apply_filters( "rest_{$this->post_type}_collection_params", $query_params, $post_type );
    21682168    }
    21692169
Note: See TracChangeset for help on using the changeset viewer.