WP_HTTP_Polling_Sync_Server::validate_requestpublicWP 7.0.0

Validates that the request body does not exceed the maximum allowed size.

Runs as the route-level validate_callback, after per-arg schema validation has already passed.

Method of the class: WP_HTTP_Polling_Sync_Server{}

No Hooks.

Returns

true|WP_Error. True if valid, WP_Error if the body is too large.

Usage

$WP_HTTP_Polling_Sync_Server = new WP_HTTP_Polling_Sync_Server();
$WP_HTTP_Polling_Sync_Server->validate_request( $request );
$request(WP_REST_Request) (required)
The REST request.

Changelog

Since 7.0.0 Introduced.

WP_HTTP_Polling_Sync_Server::validate_request() code WP 7.0

public function validate_request( WP_REST_Request $request ) {
	$body = $request->get_body();
	if ( is_string( $body ) && strlen( $body ) > self::MAX_BODY_SIZE ) {
		return new WP_Error(
			'rest_sync_body_too_large',
			__( 'Request body is too large.' ),
			array( 'status' => 413 )
		);
	}

	return true;
}