rest_sanitize_request_arg() WordPress Function

The rest_sanitize_request_arg() function is used to sanitize the value of a request argument before it is used to make a REST request. This function ensures that the value is a string and that it does not contain any invalid characters.

rest_sanitize_request_arg( mixed $value, WP_REST_Request $request, string $param ) #

Sanitize a request argument based on details registered to the route.


Parameters

$value

(mixed)(Required)

$request

(WP_REST_Request)(Required)

$param

(string)(Required)


Top ↑

Return

(mixed)


Top ↑

Source

File: wp-includes/rest-api.php

function rest_sanitize_request_arg( $value, $request, $param ) {
	$attributes = $request->get_attributes();
	if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
		return $value;
	}
	$args = $attributes['args'][ $param ];

	return rest_sanitize_value_from_schema( $value, $args, $param );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.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.

Show More