rest api – Inspecting WP_Rest_Request

Question

I’m implementing a callback for a GET Wp Rest request, which receives a WP_Rest_Request object.

function create_on_demand_post( WP_REST_Request $request ) {
    $params = $request->get_json_params();
    // etc...
}

There are class methods which retrieve the request data, but I’m wondering if there’s a way to access the data in this ArrayAccess implementation as I would with an array or object:

WP_REST_Request
    method:"POST"
    params:array(6)
    headers:array(8)
    body:"{"title": "From Python", "status": "publish", "content": "This is a post created using rest API", etc...}"
    route:"/my-plugin/v1/posts"
    attributes:array(7)
    parsed_json:true
    parsed_body:false

I have tried $request->body, which doesn’t evaluate and $request['body'], as well as $request['body'][0], both of which return null.

Are you only able to access the attributes using the provided methods?

0
MikeiLL 7 months 2022-01-26T22:24:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse