WP_REST_Request::get_content_type()
Retrieves the Content-Type of the request.
Method of the class: WP_REST_Request{}
No Hooks.
Return
Array|null
. Map containing 'value' and 'parameters' keys or null when no valid Content-Type header was available.
Usage
$WP_REST_Request = new WP_REST_Request(); $WP_REST_Request->get_content_type();
Changelog
Since 4.4.0 | Introduced. |
WP_REST_Request::get_content_type() WP REST Request::get content type code WP 6.6.2
public function get_content_type() { $value = $this->get_header( 'Content-Type' ); if ( empty( $value ) ) { return null; } $parameters = ''; if ( strpos( $value, ';' ) ) { list( $value, $parameters ) = explode( ';', $value, 2 ); } $value = strtolower( $value ); if ( ! str_contains( $value, '/' ) ) { return null; } // Parse type and subtype out. list( $type, $subtype ) = explode( '/', $value, 2 ); $data = compact( 'value', 'type', 'subtype', 'parameters' ); $data = array_map( 'trim', $data ); return $data; }