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
This commit is contained in:
Rachel Baker
2016-10-26 02:28:13 +00:00
parent 8a883144b6
commit 2b12294a0a
2 changed files with 7 additions and 0 deletions

View File

@@ -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 ) {

View File

@@ -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() {