On this page
rest_sanitize_array( mixed $maybe_array ): array
Converts an array-like value to an array.
Parameters
$maybe_arraymixed Required-
The value being evaluated.
Return
array Returns the array extracted from the value.
Source
File: wp-includes/rest-api.php. View all references
function rest_sanitize_array( $maybe_array ) {
if ( is_scalar( $maybe_array ) ) {
return wp_parse_list( $maybe_array );
}
if ( ! is_array( $maybe_array ) ) {
return array();
}
// Normalize to numeric array so nothing unexpected is in the keys.
return array_values( $maybe_array );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_parse_list() wp-includes/functions.php | Converts a comma- or space-separated list of scalar values to an array. |
Used By
| Used By | Description |
|---|---|
| rest_validate_array_value_from_schema() wp-includes/rest-api.php | Validates an array value based on a schema. |
| rest_sanitize_value_from_schema() wp-includes/rest-api.php | Sanitize a value based on a schema. |
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_sanitize_array