From 3e38c1a6c05994bfa130994d92e2f8d2a0be8c9b Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 30 Jan 2016 09:51:49 -0800 Subject: [PATCH 1/2] Add validation callbacks to `GET` terms and taxonomies --- lib/endpoints/class-wp-rest-taxonomies-controller.php | 1 + lib/endpoints/class-wp-rest-terms-controller.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/endpoints/class-wp-rest-taxonomies-controller.php b/lib/endpoints/class-wp-rest-taxonomies-controller.php index 9f38c94992..df69140239 100755 --- a/lib/endpoints/class-wp-rest-taxonomies-controller.php +++ b/lib/endpoints/class-wp-rest-taxonomies-controller.php @@ -205,6 +205,7 @@ public function get_collection_params() { $new_params['type'] = array( 'description' => __( 'Limit results to resources associated with a specific post type.' ), 'type' => 'string', + 'validate_callback' => 'rest_validate_request_arg', ); return $new_params; } diff --git a/lib/endpoints/class-wp-rest-terms-controller.php b/lib/endpoints/class-wp-rest-terms-controller.php index 075b17a50e..d849cd2059 100755 --- a/lib/endpoints/class-wp-rest-terms-controller.php +++ b/lib/endpoints/class-wp-rest-terms-controller.php @@ -635,6 +635,7 @@ public function get_collection_params() { 'description' => __( 'Offset the result set by a specific number of items.' ), 'type' => 'integer', 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', ); } $query_params['order'] = array( @@ -646,6 +647,7 @@ public function get_collection_params() { 'asc', 'desc', ), + 'validate_callback' => 'rest_validate_request_arg', ); $query_params['orderby'] = array( 'description' => __( 'Sort collection by resource attribute.' ), @@ -661,27 +663,32 @@ public function get_collection_params() { 'description', 'count', ), + 'validate_callback' => 'rest_validate_request_arg', ); $query_params['hide_empty'] = array( 'description' => __( 'Whether to hide resources not assigned to any posts.' ), 'type' => 'boolean', 'default' => false, + 'validate_callback' => 'rest_validate_request_arg', ); if ( $taxonomy->hierarchical ) { $query_params['parent'] = array( 'description' => __( 'Limit result set to resources assigned to a specific parent.' ), 'type' => 'integer', 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', ); } $query_params['post'] = array( 'description' => __( 'Limit result set to resources assigned to a specific post.' ), - 'type' => 'number', + 'type' => 'integer', 'default' => false, + 'validate_callback' => 'rest_validate_request_arg', ); $query_params['slug'] = array( 'description' => __( 'Limit result set to resources with a specific slug.' ), 'type' => 'string', + 'validate_callback' => 'rest_validate_request_arg', ); return $query_params; } From e647e770cc6a9eff14f208afd6acc938a7fd6d14 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 30 Jan 2016 10:45:59 -0800 Subject: [PATCH 2/2] Better default type for an optional parameter --- lib/endpoints/class-wp-rest-terms-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/endpoints/class-wp-rest-terms-controller.php b/lib/endpoints/class-wp-rest-terms-controller.php index d849cd2059..8586cf90c4 100755 --- a/lib/endpoints/class-wp-rest-terms-controller.php +++ b/lib/endpoints/class-wp-rest-terms-controller.php @@ -682,7 +682,7 @@ public function get_collection_params() { $query_params['post'] = array( 'description' => __( 'Limit result set to resources assigned to a specific post.' ), 'type' => 'integer', - 'default' => false, + 'default' => null, 'validate_callback' => 'rest_validate_request_arg', ); $query_params['slug'] = array(