rest_sanitize_array() WordPress Function

The rest_sanitize_array() function is a utility function that sanitizes a given array, by running each value through the rest_sanitize_value() function. This is useful for sanitizing data retrieved from the REST API, before passing it to the application.

rest_sanitize_array( mixed $maybe_array ) #

Converts an array-like value to an array.


Parameters

$maybe_array

(mixed)(Required)The value being evaluated.


Top ↑

Return

(array) Returns the array extracted from the value.


Top ↑

Source

File: wp-includes/rest-api.php

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 );
}


Top ↑

Changelog

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