WP_REST_Request::has_param() WordPress Method
The WP_REST_Request::has_param() method is used to determine whether a parameter has been set for a given request. This can be useful when validating user input or when trying to determine whether a certain piece of data is available.
WP_REST_Request::has_param( string $key ) #
Checks if a parameter exists in the request.
Description
This allows distinguishing between an omitted parameter, and a parameter specifically set to null.
Parameters
- $key
(string)(Required)Parameter name.
Return
(bool) True if a param exists for the given key.
Source
File: wp-includes/rest-api/class-wp-rest-request.php
public function has_param( $key ) {
$order = $this->get_parameter_order();
foreach ( $order as $type ) {
if ( is_array( $this->params[ $type ] ) && array_key_exists( $key, $this->params[ $type ] ) ) {
return true;
}
}
return false;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |