Automattic\WooCommerce\StoreApi
Authentication::is_only_post_request
Returns true only for POST requests that are NOT overridden to another method via the X-HTTP-Method-Override header (used by wp.apiFetch for PUT/DELETE).
Method of the class: Authentication{}
No Hooks.
Returns
bool.
Usage
// private - for code of main (parent) class only $result = $this->is_only_post_request();
Notes
| See: https://github.com/wordpress/gutenberg/blob/trunk/packages/api-fetch/src/middlewares/http-v1.ts#L21-L43 |
Authentication::is_only_post_request() Authentication::is only post request code WC 11.0.1
private function is_only_post_request() {
// Check that REQUEST_METHOD is POST.
if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return false;
}
// Check X-HTTP-Method-Override header if it exists and is not empty - it must also be POST.
if ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
$method_override = strtoupper( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) );
if ( '' !== $method_override && 'POST' !== $method_override ) {
return false;
}
}
return true;
}