rest_sanitize_object() WordPress Function

The rest_sanitize_object() function is used to sanitize a REST request object before it is passed to the server. This function ensures that only the allowed parameters are passed to the server, and that any dangerous characters are escaped. This function is called automatically by the WordPress REST API when a REST request is made.

rest_sanitize_object( mixed $maybe_object ) #

Converts an object-like value to an object.


Parameters

$maybe_object

(mixed)(Required)The value being evaluated.


Top ↑

Return

(array) Returns the object extracted from the value.


Top ↑

Source

File: wp-includes/rest-api.php

function rest_sanitize_object( $maybe_object ) {
	if ( '' === $maybe_object ) {
		return array();
	}

	if ( $maybe_object instanceof stdClass ) {
		return (array) $maybe_object;
	}

	if ( $maybe_object instanceof JsonSerializable ) {
		$maybe_object = $maybe_object->jsonSerialize();
	}

	if ( ! is_array( $maybe_object ) ) {
		return array();
	}

	return $maybe_object;
}


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