WP_REST_Request::parse_body_params() WordPress Method

The parse_body_params() method is used to parse the body of a request for parameters. This is useful for JSON or XML requests where the body may contain parameters that need to be parsed before they can be used.

WP_REST_Request::parse_body_params() #

Parses the request body parameters.


Description

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.


Top ↑

Source

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

	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'] );
	}


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.