WP_REST_Server::get_raw_data() WordPress Method

The WP_REST_Server::get_raw_data() method is used to retrieve the raw request body data. This is useful for cases where the data needs to be accessed outside of the normal request/response cycle, such as for Webhooks.

WP_REST_Server::get_raw_data() #

Retrieves the raw request entity (body).


Return

(string) Raw request data.


Top ↑

Source

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

	public static function get_raw_data() {
		// phpcs:disable PHPCompatibility.Variables.RemovedPredefinedGlobalVariables.http_raw_post_dataDeprecatedRemoved
		global $HTTP_RAW_POST_DATA;

		// $HTTP_RAW_POST_DATA was deprecated in PHP 5.6 and removed in PHP 7.0.
		if ( ! isset( $HTTP_RAW_POST_DATA ) ) {
			$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
		}

		return $HTTP_RAW_POST_DATA;
		// phpcs:enable
	}


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.