From 2b12294a0a58ea6ef1d54263853e4140f1c2d75a Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Wed, 26 Oct 2016 02:28:13 +0000 Subject: [PATCH] REST API: Add missing sanitization callback for the `hide_empty` parameter of the Terms Controller. Fixes a bug where the boolean parameter `hide_empty` was not being properly sanitized in the Terms controller. Props websupporter. Fixes #38465. git-svn-id: https://develop.svn.wordpress.org/trunk@38942 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-terms-controller.php | 1 + tests/phpunit/tests/rest-api/rest-categories-controller.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index cf131adb67..6540c52fdf 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -867,6 +867,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { 'description' => __( 'Whether to hide resources not assigned to any posts.' ), 'type' => 'boolean', 'default' => false, + 'sanitize_callback' => 'rest_sanitize_request_arg', 'validate_callback' => 'rest_validate_request_arg', ); if ( $taxonomy->hierarchical ) { diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index c62bc695ac..ac2d0f1aa3 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -92,6 +92,12 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $this->assertEquals( 2, count( $data ) ); $this->assertEquals( 'Season 5', $data[0]['name'] ); $this->assertEquals( 'The Be Sharps', $data[1]['name'] ); + + // Confirm the empty category "Uncategorized" category appears. + $request->set_param( 'hide_empty', 'false' ); + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 3, count( $data ) ); } public function test_get_items_parent_zero_arg() {