WP_REST_Request::get_content_type() WordPress Method

The WP_REST_Request::get_content_type() method is used to retrieve the Content-Type request header. This is useful for determining the type of data that is being sent in a request body.

WP_REST_Request::get_content_type() #

Retrieves the content-type of the request.


Return

(array|null) Map containing 'value' and 'parameters' keys or null when no valid content-type header was available.


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-request.php

	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 ( false === strpos( $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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.