Function
Get a value from the request.
tml_get_request_value( string $key, string $type = 'any' )
Parameters
-
$keystring - The key of the value to retrieve.
-
$typestring Default'any' - Optional. The request type. Can be either 'get', 'post' or 'any'. Default 'any'.
Return
mixed
The requested value.
Source
function tml_get_request_value( $key, $type = 'any' ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- generic request-value accessor used in both nonce-protected and read-only contexts; verification is the caller's responsibility.
$type = strtoupper( $type );
if ( 'POST' === $type && array_key_exists( $key, $_POST ) ) {
$value = $_POST[ $key ];
} elseif ( 'GET' === $type && array_key_exists( $key, $_GET ) ) {
$value = $_GET[ $key ];
} elseif ( array_key_exists( $key, $_REQUEST ) ) {
$value = $_REQUEST[ $key ];
} else {
$value = '';
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
if ( is_string( $value ) ) {
$value = wp_unslash( $value );
}
return $value;
}
Uses
Used by
Changelog
| Version | Description |
|---|---|
| 7.0 | Introduced. |