Make WordPress Core

Changeset 38911


Ignore:
Timestamp:
10/25/2016 05:12:18 PM (8 years ago)
Author:
joehoyle
Message:

REST API: Validate posts status enum

Currently we are using a different validate callback, so the enum is not interpretted. We just have to fallback to the result of rest_validate_request_arg in our custom wrapper function.

Fixes #38417.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r38832 r38911  
    19481948    public function validate_user_can_query_private_statuses( $value, $request, $parameter ) {
    19491949        if ( 'publish' === $value ) {
    1950             return true;
     1950            return rest_validate_request_arg( $value, $request, $parameter );
    19511951        }
    19521952        $post_type_obj = get_post_type_object( $this->post_type );
    19531953        if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
    1954             return true;
     1954            return rest_validate_request_arg( $value, $request, $parameter );
    19551955        }
    19561956        return new WP_Error( 'rest_forbidden_status', __( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) );
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r38832 r38911  
    239239        $this->assertEquals( 200, $response->get_status() );
    240240        $this->assertEquals( 1, count( $response->get_data() ) );
     241    }
     242
     243    public function test_get_items_invalid_status_query() {
     244        wp_set_current_user( 0 );
     245        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     246        $request->set_param( 'status', 'invalid' );
     247        $response = $this->server->dispatch( $request );
     248        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    241249    }
    242250
Note: See TracChangeset for help on using the changeset viewer.