From a4fa8c528f313b81d20e60c0eccbb21c0be939ec Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Mon, 14 Nov 2016 16:42:31 +0000 Subject: [PATCH] REST API: Make all collection params filterable. For developers wanting to add their own registered collection parameters, they can now use the `rest_$type_collection_params` filter. This brings consistency with the already existing `rest_$post_type_collection_params`. Fixes #38710. Props jnylen0. Built from https://develop.svn.wordpress.org/trunk@39223 git-svn-id: http://core.svn.wordpress.org/trunk@39163 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-comments-controller.php | 13 ++++++++++++- .../class-wp-rest-terms-controller.php | 17 ++++++++++++++++- .../class-wp-rest-users-controller.php | 13 ++++++++++++- wp-includes/version.php | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 03d30b0e7a..afd64895e1 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -1389,7 +1389,18 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { 'validate_callback' => 'rest_validate_request_arg', ); - return $query_params; + /** + * Filter collection parameters for the comments controller. + * + * This filter registers the collection parameter, but does not map the + * collection parameter to an internal WP_Comment_Query parameter. Use the + * `rest_comment_query` filter to set WP_Comment_Query parameters. + * + * @since 4.7.0 + * + * @param $params JSON Schema-formatted collection parameters. + */ + return apply_filters( 'rest_comment_collection_params', $query_params ); } /** diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 043966658d..422448f228 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -959,7 +959,22 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { 'type' => 'string', ); - return $query_params; + /** + * Filter collection parameters for the terms controller. + * + * The dynamic part of the filter `$this->taxonomy` refers to the taxonomy + * slug for the controller. + * + * This filter registers the collection parameter, but does not map the + * collection parameter to an internal WP_Term_Query parameter. Use the + * `rest_{$this->taxonomy}_query` filter to set WP_Term_Query parameters. + * + * @since 4.7.0 + * + * @param $params JSON Schema-formatted collection parameters. + * @param WP_Taxonomy $taxonomy_obj Taxonomy object. + */ + return apply_filters( 'rest_{$this->taxonomy}_collection_params', $query_params, $taxonomy ); } /** diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 4a693ba571..0b49ec8a2c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -1298,6 +1298,17 @@ class WP_REST_Users_Controller extends WP_REST_Controller { ), ); - return $query_params; + /** + * Filter collection parameters for the users controller. + * + * This filter registers the collection parameter, but does not map the + * collection parameter to an internal WP_User_Query parameter. Use the + * `rest_user_query` filter to set WP_User_Query arguments. + * + * @since 4.7.0 + * + * @param $params JSON Schema-formatted collection parameters. + */ + return apply_filters( 'rest_user_collection_params', $query_params ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 8a8747bde7..854e2fbaa2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta3-39222'; +$wp_version = '4.7-beta3-39223'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.