WP_REST_Request::__construct( string $method = , string $route = , array $attributes = array() )

Constructor.

Parameters

$methodstringoptional
Request method.

Default:''

$routestringoptional
Request route.

Default:''

$attributesarrayoptional
Request attributes.

Default:array()

Source

public function __construct( $method = '', $route = '', $attributes = array() ) {
	$this->params = array(
		'URL'      => array(),
		'GET'      => array(),
		'POST'     => array(),
		'FILES'    => array(),

		// See parse_json_params.
		'JSON'     => null,

		'defaults' => array(),
	);

	$this->set_method( $method );
	$this->set_route( $route );
	$this->set_attributes( $attributes );
}

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Request objects can also be constructed from a URL by using WP_REST_Request::from_url:

    // If your site is at http://example.com/:
    $request = WP_REST_Request::from_url( 'http://example.com/wp-json/wp/v2/posts' );
    // GET by default; to change the method, you can then run:
    $request->set_method( 'POST' );

You must log in before being able to contribute a note or feedback.