Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit 35cd786

Browse files
committed
Introduce rest_parse_request_arg() wrapper to perform a validation and
sanitization in one step.
1 parent ce8bde7 commit 35cd786

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

plugin.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,33 @@ function rest_sanitize_request_arg( $value, $request, $param ) {
414414
}
415415
}
416416

417+
418+
if ( ! function_exists( 'rest_parse_request_arg' ) ) {
419+
/**
420+
* Parse a request argument based on details registered to the route.
421+
*
422+
* Runs a validation check and sanitizes the value, primarily to be used via
423+
* the `sanitize_callback` arguments in the endpoint args registration.
424+
*
425+
* @param mixed $value
426+
* @param WP_REST_Request $request
427+
* @param string $param
428+
* @return mixed
429+
*/
430+
function rest_parse_request_arg( $value, $request, $param ) {
431+
432+
$is_valid = rest_validate_request_arg( $value, $request, $param );
433+
434+
if ( is_wp_error( $is_valid ) ) {
435+
return $is_valid;
436+
}
437+
438+
$value = rest_sanitize_request_arg( $value, $request, $param );
439+
440+
return $value;
441+
}
442+
}
443+
417444
if ( ! function_exists( 'rest_is_ip_address' ) ) {
418445
/**
419446
* Determines if a IPv4 address is valid.

0 commit comments

Comments
 (0)