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