WP_REST_Request::get_content_type
Retrieves the Content-Type of the request.
Метод класса: WP_REST_Request{}
Хуков нет.
Возвращает
Массив|null. Map containing 'value' and 'parameters' keys or null when no valid Content-Type header was available.
Использование
$WP_REST_Request = new WP_REST_Request(); $WP_REST_Request->get_content_type();
Список изменений
| С версии 4.4.0 | Введена. |
Код WP_REST_Request::get_content_type() WP REST Request::get content type WP 7.0.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;
}