diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php
index 2f6aa8a..f77c92f 100644
a
|
b
|
class WP_REST_Request implements ArrayAccess { |
844 | 844 | $param = $this->get_param( $key ); |
845 | 845 | |
846 | 846 | if ( null !== $param && ! empty( $arg['validate_callback'] ) ) { |
847 | | $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
| 847 | |
| 848 | /** |
| 849 | * Filter validation callbacks which should only be supplied the parameter to validate. |
| 850 | * |
| 851 | * Some functions used as validation callbacks (e.g. is_numeric()), throw |
| 852 | * errors when supplied more than one argument. |
| 853 | * |
| 854 | * @since 4.4.0 |
| 855 | * |
| 856 | * @param array $single_argument_callbacks |
| 857 | */ |
| 858 | $single_argument_callbacks = apply_filters( 'rest_request_validate_callbacks_single_argument', array( 'is_numeric', 'sanitize_title' ) ); |
| 859 | if ( in_array( $arg['validate_callback'], $single_argument_callbacks ) ) { |
| 860 | $valid_check = call_user_func( $arg['validate_callback'], $param ); |
| 861 | } else { |
| 862 | $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
| 863 | } |
848 | 864 | |
849 | 865 | if ( false === $valid_check ) { |
850 | 866 | $invalid_params[ $key ] = __( 'Invalid param.' ); |
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index ba40892..ea0704f 100644
a
|
b
|
class Tests_REST_Request extends WP_UnitTestCase { |
391 | 391 | $this->assertArrayHasKey( 'someinteger', $data['params'] ); |
392 | 392 | $this->assertArrayHasKey( 'someotherinteger', $data['params'] ); |
393 | 393 | } |
| 394 | |
| 395 | public function test_validate_callback_only_pass_value() { |
| 396 | $this->request->set_url_params( array( |
| 397 | 'numeric_value' => '123', |
| 398 | 'non_numeric_value' => 'foo-bar', |
| 399 | ) ); |
| 400 | $this->request->set_attributes( array( |
| 401 | 'args' => array( |
| 402 | 'numeric_value' => array( |
| 403 | 'validate_callback' => 'is_numeric', |
| 404 | ), |
| 405 | 'non_numeric_value' => array( |
| 406 | 'validate_callback' => 'is_numeric', |
| 407 | ), |
| 408 | ), |
| 409 | )); |
| 410 | |
| 411 | $valid = $this->request->has_valid_params(); |
| 412 | |
| 413 | $this->assertWPError( $valid ); |
| 414 | $this->assertEquals( 'rest_invalid_param', $valid->get_error_code() ); |
| 415 | $data = $valid->get_error_data( 'rest_invalid_param' ); |
| 416 | $this->assertArrayHasKey( 'non_numeric_value', $data['params'] ); |
| 417 | $this->assertFalse( array_key_exists( 'numeric_value', $data ) ); |
| 418 | |
| 419 | } |
| 420 | |
394 | 421 | } |