WP_REST_Request::parse_body_params()protectedWP 4.4.0

Parses the request body parameters.

Parses out URL-encoded bodies for request methods that aren't supported natively by PHP. In PHP 5.x, only POST has these parsed automatically.

Method of the class: WP_REST_Request{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->parse_body_params();

Changelog

Since 4.4.0 Introduced.

WP_REST_Request::parse_body_params() code WP 6.5.2

protected function parse_body_params() {
	if ( $this->parsed_body ) {
		return;
	}

	$this->parsed_body = true;

	/*
	 * Check that we got URL-encoded. Treat a missing Content-Type as
	 * URL-encoded for maximum compatibility.
	 */
	$content_type = $this->get_content_type();

	if ( ! empty( $content_type ) && 'application/x-www-form-urlencoded' !== $content_type['value'] ) {
		return;
	}

	parse_str( $this->get_body(), $params );

	/*
	 * Add to the POST parameters stored internally. If a user has already
	 * set these manually (via `set_body_params`), don't override them.
	 */
	$this->params['POST'] = array_merge( $params, $this->params['POST'] );
}