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.


Built from https://develop.svn.wordpress.org/branches/4.7@39631


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39571 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-12-21 05:34:34 +00:00
parent cf9b1dbc1f
commit 6e8114742f
5 changed files with 31 additions and 31 deletions

View File

@ -1437,7 +1437,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
*
* @since 4.7.0
*
* @param $params JSON Schema-formatted collection parameters.
* @param array $query_params JSON Schema-formatted collection parameters.
*/
return apply_filters( 'rest_comment_collection_params', $query_params );
}

View File

@ -1985,18 +1985,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
* @return array Collection parameters.
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$query_params = parent::get_collection_params();
$params['context']['default'] = 'view';
$query_params['context']['default'] = 'view';
$params['after'] = array(
$query_params['after'] = array(
'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
'type' => 'string',
'format' => 'date-time',
);
if ( post_type_supports( $this->post_type, 'author' ) ) {
$params['author'] = array(
$query_params['author'] = array(
'description' => __( 'Limit result set to posts assigned to specific authors.' ),
'type' => 'array',
'items' => array(
@ -2004,7 +2004,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
),
'default' => array(),
);
$params['author_exclude'] = array(
$query_params['author_exclude'] = array(
'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ),
'type' => 'array',
'items' => array(
@ -2014,13 +2014,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
);
}
$params['before'] = array(
$query_params['before'] = array(
'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
'type' => 'string',
'format' => 'date-time',
);
$params['exclude'] = array(
$query_params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific IDs.' ),
'type' => 'array',
'items' => array(
@ -2029,7 +2029,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'default' => array(),
);
$params['include'] = array(
$query_params['include'] = array(
'description' => __( 'Limit result set to specific IDs.' ),
'type' => 'array',
'items' => array(
@ -2039,25 +2039,25 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
);
if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
$params['menu_order'] = array(
$query_params['menu_order'] = array(
'description' => __( 'Limit result set to posts with a specific menu_order value.' ),
'type' => 'integer',
);
}
$params['offset'] = array(
$query_params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of items.' ),
'type' => 'integer',
);
$params['order'] = array(
$query_params['order'] = array(
'description' => __( 'Order sort attribute ascending or descending.' ),
'type' => 'string',
'default' => 'desc',
'enum' => array( 'asc', 'desc' ),
);
$params['orderby'] = array(
$query_params['orderby'] = array(
'description' => __( 'Sort collection by object attribute.' ),
'type' => 'string',
'default' => 'date',
@ -2072,13 +2072,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
);
if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
$params['orderby']['enum'][] = 'menu_order';
$query_params['orderby']['enum'][] = 'menu_order';
}
$post_type_obj = get_post_type_object( $this->post_type );
$post_type = get_post_type_object( $this->post_type );
if ( $post_type_obj->hierarchical || 'attachment' === $this->post_type ) {
$params['parent'] = array(
if ( $post_type->hierarchical || 'attachment' === $this->post_type ) {
$query_params['parent'] = array(
'description' => __( 'Limit result set to those of particular parent IDs.' ),
'type' => 'array',
'items' => array(
@ -2086,7 +2086,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
),
'default' => array(),
);
$params['parent_exclude'] = array(
$query_params['parent_exclude'] = array(
'description' => __( 'Limit result set to all items except those of a particular parent ID.' ),
'type' => 'array',
'items' => array(
@ -2096,7 +2096,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
);
}
$params['slug'] = array(
$query_params['slug'] = array(
'description' => __( 'Limit result set to posts with one or more specific slugs.' ),
'type' => 'array',
'items' => array(
@ -2105,7 +2105,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'sanitize_callback' => 'wp_parse_slug_list',
);
$params['status'] = array(
$query_params['status'] = array(
'default' => 'publish',
'description' => __( 'Limit result set to posts assigned one or more statuses.' ),
'type' => 'array',
@ -2121,7 +2121,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
foreach ( $taxonomies as $taxonomy ) {
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
$params[ $base ] = array(
$query_params[ $base ] = array(
/* translators: %s: taxonomy name */
'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ),
'type' => 'array',
@ -2131,7 +2131,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'default' => array(),
);
$params[ $base . '_exclude' ] = array(
$query_params[ $base . '_exclude' ] = array(
/* translators: %s: taxonomy name */
'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ),
'type' => 'array',
@ -2143,7 +2143,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
}
if ( 'post' === $this->post_type ) {
$params['sticky'] = array(
$query_params['sticky'] = array(
'description' => __( 'Limit result set to items that are sticky.' ),
'type' => 'boolean',
);
@ -2161,10 +2161,10 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
*
* @since 4.7.0
*
* @param $params JSON Schema-formatted collection parameters.
* @param WP_Post_Type $post_type_obj Post type object.
* @param array $query_params JSON Schema-formatted collection parameters.
* @param WP_Post_Type $post_type Post type object.
*/
return apply_filters( "rest_{$this->post_type}_collection_params", $params, $post_type_obj );
return apply_filters( "rest_{$this->post_type}_collection_params", $query_params, $post_type );
}
/**

View File

@ -971,10 +971,10 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
*
* @since 4.7.0
*
* @param $params JSON Schema-formatted collection parameters.
* @param WP_Taxonomy $taxonomy_obj Taxonomy object.
* @param array $query_params JSON Schema-formatted collection parameters.
* @param WP_Taxonomy $taxonomy Taxonomy object.
*/
return apply_filters( 'rest_{$this->taxonomy}_collection_params', $query_params, $taxonomy );
return apply_filters( "rest_{$this->taxonomy}_collection_params", $query_params, $taxonomy );
}
/**

View File

@ -1351,7 +1351,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
*
* @since 4.7.0
*
* @param $params JSON Schema-formatted collection parameters.
* @param array $query_params JSON Schema-formatted collection parameters.
*/
return apply_filters( 'rest_user_collection_params', $query_params );
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7.1-alpha-39630';
$wp_version = '4.7.1-alpha-39631';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.