rest_find_any_matching_schema() WordPress Function

The rest_find_any_matching_schema() function searches for any schema that matches the given search term. If a match is found, the function returns the matching schema. If no match is found, the function returns false.

rest_find_any_matching_schema( mixed $value, array $args, string $param ) #

Finds the matching schema among the “anyOf” schemas.


Parameters

$value

(mixed)(Required)The value to validate.

$args

(array)(Required)The schema array to use.

$param

(string)(Required)The parameter name, used in error messages.


Top ↑

Return

(array|WP_Error) The matching schema or WP_Error instance if all schemas do not match.


Top ↑

Source

File: wp-includes/rest-api.php

function rest_find_any_matching_schema( $value, $args, $param ) {
	$errors = array();

	foreach ( $args['anyOf'] as $index => $schema ) {
		if ( ! isset( $schema['type'] ) && isset( $args['type'] ) ) {
			$schema['type'] = $args['type'];
		}

		$is_valid = rest_validate_value_from_schema( $value, $schema, $param );
		if ( ! is_wp_error( $is_valid ) ) {
			return $schema;
		}

		$errors[] = array(
			'error_object' => $is_valid,
			'schema'       => $schema,
			'index'        => $index,
		);
	}

	return rest_get_combining_operation_error( $value, $param, $errors );
}


Top ↑

Changelog

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