rest_validate_json_schema_pattern() WordPress Function

The rest_validate_json_schema_pattern() function is used to validate a JSON schema pattern. This function is used by the WordPress REST API to validate the request and response bodies of JSON requests.

rest_validate_json_schema_pattern( string $pattern, string $value ) #

Validates if the JSON Schema pattern matches a value.


Parameters

$pattern

(string)(Required)The pattern to match against.

$value

(string)(Required)The value to check.


Top ↑

Return

(bool) True if the pattern matches the given value, false otherwise.


Top ↑

Source

File: wp-includes/rest-api.php

function rest_validate_json_schema_pattern( $pattern, $value ) {
	$escaped_pattern = str_replace( '#', '\\#', $pattern );

	return 1 === preg_match( '#' . $escaped_pattern . '#u', $value );
}


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.