WP_REST_Request::get_method(): string
Retrieves the HTTP method for the request.
Contents
Return
string HTTP method.
Source
File: wp-includes/rest-api/class-wp-rest-request.php
.
View all references
public function get_method() {
return $this->method;
}
Changelog
Version | Description |
---|---|
4.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
The return value (HTTP Method) is returned in full uppercase such as “POST”, “GET”, “PATCH”, “DELETE”. As an example in your API route callback you can check for the method type when you’re expecting one of several potential methods:
Alternatively you might use a switch to check the method such as:
These examples are in the context of a callback from
register_rest_route()
which passes the$request
(instance ofWP_REST_Request
) to the callback.