: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function rest_validate_number_value_from_schema( $value, $args, $param ) {
if ( ! is_numeric( $value ) ) {
/* translators: 1: Parameter, 2: Type name. */
sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ),
array( 'param' => $param )
if ( isset( $args['multipleOf'] ) && fmod( $value, $args['multipleOf'] ) !== 0.0 ) {
/* translators: 1: Parameter, 2: Multiplier. */
sprintf( __( '%1$s must be a multiple of %2$s.' ), $param, $args['multipleOf'] )
if ( isset( $args['minimum'] ) && ! isset( $args['maximum'] ) ) {
if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number. */
sprintf( __( '%1$s must be greater than %2$d' ), $param, $args['minimum'] )
if ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number. */
sprintf( __( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] )
if ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) {
if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) {
/* translators: 1: Parameter, 2: Maximum number. */
sprintf( __( '%1$s must be less than %2$d' ), $param, $args['maximum'] )
if ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) {
/* translators: 1: Parameter, 2: Maximum number. */
sprintf( __( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] )
if ( isset( $args['minimum'], $args['maximum'] ) ) {
if ( ! empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) {
if ( $value >= $args['maximum'] || $value <= $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number, 3: Maximum number. */
__( '%1$s must be between %2$d (exclusive) and %3$d (exclusive)' ),
if ( ! empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) {
if ( $value > $args['maximum'] || $value <= $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number, 3: Maximum number. */
__( '%1$s must be between %2$d (exclusive) and %3$d (inclusive)' ),
if ( ! empty( $args['exclusiveMaximum'] ) && empty( $args['exclusiveMinimum'] ) ) {
if ( $value >= $args['maximum'] || $value < $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number, 3: Maximum number. */
__( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ),
if ( empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) {
if ( $value > $args['maximum'] || $value < $args['minimum'] ) {
/* translators: 1: Parameter, 2: Minimum number, 3: Maximum number. */
__( '%1$s must be between %2$d (inclusive) and %3$d (inclusive)' ),
* Validates a string value based on a schema.
* @param mixed $value The value to validate.
* @param array $args Schema array to use for validation.
* @param string $param The parameter name, used in error messages.
function rest_validate_string_value_from_schema( $value, $args, $param ) {
if ( ! is_string( $value ) ) {
/* translators: 1: Parameter, 2: Type name. */
sprintf( __( '%1$s is not of type %2$s.' ), $param, 'string' ),
array( 'param' => $param )
if ( isset( $args['minLength'] ) && mb_strlen( $value ) < $args['minLength'] ) {
/* translators: 1: Parameter, 2: Number of characters. */
'%1$s must be at least %2$s character long.',
'%1$s must be at least %2$s characters long.',
number_format_i18n( $args['minLength'] )
if ( isset( $args['maxLength'] ) && mb_strlen( $value ) > $args['maxLength'] ) {
/* translators: 1: Parameter, 2: Number of characters. */
'%1$s must be at most %2$s character long.',
'%1$s must be at most %2$s characters long.',
number_format_i18n( $args['maxLength'] )
if ( isset( $args['pattern'] ) && ! rest_validate_json_schema_pattern( $args['pattern'], $value ) ) {
/* translators: 1: Parameter, 2: Pattern. */
sprintf( __( '%1$s does not match pattern %2$s.' ), $param, $args['pattern'] )
* Validates an integer value based on a schema.
* @param mixed $value The value to validate.
* @param array $args Schema array to use for validation.
* @param string $param The parameter name, used in error messages.
function rest_validate_integer_value_from_schema( $value, $args, $param ) {
$is_valid_number = rest_validate_number_value_from_schema( $value, $args, $param );
if ( is_wp_error( $is_valid_number ) ) {
if ( ! rest_is_integer( $value ) ) {
/* translators: 1: Parameter, 2: Type name. */
sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ),
array( 'param' => $param )
* Sanitize a value based on a schema.
* @since 5.5.0 Added the `$param` parameter.
* @since 5.6.0 Support the "anyOf" and "oneOf" keywords.
* @since 5.9.0 Added `text-field` and `textarea-field` formats.
* @param mixed $value The value to sanitize.
* @param array $args Schema array to use for sanitization.
* @param string $param The parameter name, used in error messages.
* @return mixed|WP_Error The sanitized value or a WP_Error instance if the value cannot be safely sanitized.
function rest_sanitize_value_from_schema( $value, $args, $param = '' ) {
if ( isset( $args['anyOf'] ) ) {
$matching_schema = rest_find_any_matching_schema( $value, $args, $param );
if ( is_wp_error( $matching_schema ) ) {
if ( ! isset( $args['type'] ) ) {
$args['type'] = $matching_schema['type'];
$value = rest_sanitize_value_from_schema( $value, $matching_schema, $param );
if ( isset( $args['oneOf'] ) ) {
$matching_schema = rest_find_one_matching_schema( $value, $args, $param );
if ( is_wp_error( $matching_schema ) ) {
if ( ! isset( $args['type'] ) ) {
$args['type'] = $matching_schema['type'];
$value = rest_sanitize_value_from_schema( $value, $matching_schema, $param );
$allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' );
if ( ! isset( $args['type'] ) ) {
/* translators: %s: Parameter. */
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The "type" schema keyword for %s is required.' ), $param ), '5.5.0' );
if ( is_array( $args['type'] ) ) {
$best_type = rest_handle_multi_type_schema( $value, $args, $param );
$args['type'] = $best_type;
if ( ! in_array( $args['type'], $allowed_types, true ) ) {
/* translators: 1: Parameter, 2: The list of allowed types. */
wp_sprintf( __( 'The "type" schema keyword for %1$s can only be one of the built-in types: %2$l.' ), $param, $allowed_types ),
if ( 'array' === $args['type'] ) {
$value = rest_sanitize_array( $value );
if ( ! empty( $args['items'] ) ) {
foreach ( $value as $index => $v ) {
$value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' );
if ( ! empty( $args['uniqueItems'] ) && ! rest_validate_array_contains_unique_items( $value ) ) {
/* translators: %s: Parameter. */
return new WP_Error( 'rest_duplicate_items', sprintf( __( '%s has duplicate items.' ), $param ) );
if ( 'object' === $args['type'] ) {
$value = rest_sanitize_object( $value );
foreach ( $value as $property => $v ) {
if ( isset( $args['properties'][ $property ] ) ) {
$value[ $property ] = rest_sanitize_value_from_schema( $v, $args['properties'][ $property ], $param . '[' . $property . ']' );
$pattern_property_schema = rest_find_matching_pattern_property_schema( $property, $args );
if ( null !== $pattern_property_schema ) {
$value[ $property ] = rest_sanitize_value_from_schema( $v, $pattern_property_schema, $param . '[' . $property . ']' );
if ( isset( $args['additionalProperties'] ) ) {
if ( false === $args['additionalProperties'] ) {
unset( $value[ $property ] );
} elseif ( is_array( $args['additionalProperties'] ) ) {
$value[ $property ] = rest_sanitize_value_from_schema( $v, $args['additionalProperties'], $param . '[' . $property . ']' );
if ( 'null' === $args['type'] ) {
if ( 'integer' === $args['type'] ) {
if ( 'number' === $args['type'] ) {
if ( 'boolean' === $args['type'] ) {
return rest_sanitize_boolean( $value );
// This behavior matches rest_validate_value_from_schema().
if ( isset( $args['format'] )
&& ( ! isset( $args['type'] ) || 'string' === $args['type'] || ! in_array( $args['type'], $allowed_types, true ) )
switch ( $args['format'] ) {
return (string) sanitize_hex_color( $value );
return sanitize_text_field( $value );
// sanitize_email() validates, which would be unexpected.
return sanitize_text_field( $value );
return sanitize_url( $value );
return sanitize_text_field( $value );
return sanitize_text_field( $value );
return sanitize_text_field( $value );
return sanitize_textarea_field( $value );
if ( 'string' === $args['type'] ) {
* Append result of internal request to REST API for purpose of preloading data to be attached to a page.
* Expected to be called in the context of `array_reduce`.
* @param array $memo Reduce accumulator.
* @param string $path REST API path to preload.
* @return array Modified reduce accumulator.
function rest_preload_api_request( $memo, $path ) {
* array_reduce() doesn't support passing an array in PHP 5.2,
* so we need to make sure we start with one.
if ( ! is_array( $memo ) ) {
if ( is_array( $path ) && 2 === count( $path ) ) {
if ( ! in_array( $method, array( 'GET', 'OPTIONS' ), true ) ) {
$path = untrailingslashit( $path );
$path_parts = parse_url( $path );
if ( false === $path_parts ) {
$request = new WP_REST_Request( $method, $path_parts['path'] );
if ( ! empty( $path_parts['query'] ) ) {
parse_str( $path_parts['query'], $query_params );
$request->set_query_params( $query_params );
$response = rest_do_request( $request );
if ( 200 === $response->status ) {
$server = rest_get_server();
/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
$response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $server, $request );
$embed = $request->has_param( '_embed' ) ? rest_parse_embed_param( $request['_embed'] ) : false;
$data = (array) $server->response_to_data( $response, $embed );
if ( 'OPTIONS' === $method ) {
$memo[ $method ][ $path ] = array(
'headers' => $response->headers,
'headers' => $response->headers,
* Parses the "_embed" parameter into the list of resources to embed.
* @param string|array $embed Raw "_embed" parameter value.
* @return true|string[] Either true to embed all embeds, or a list of relations to embed.
function rest_parse_embed_param( $embed ) {
if ( ! $embed || 'true' === $embed || '1' === $embed ) {
$rels = wp_parse_list( $embed );
* Filters the response to remove any fields not available in the given context.
* @since 5.6.0 Support the "patternProperties" keyword for objects.
* Support the "anyOf" and "oneOf" keywords.
* @param array|object $response_data The response data to modify.
* @param array $schema The schema for the endpoint used to filter the response.
* @param string $context The requested context.
* @return array|object The filtered response data.
function rest_filter_response_by_context( $response_data, $schema, $context ) {
if ( isset( $schema['anyOf'] ) ) {
$matching_schema = rest_find_any_matching_schema( $response_data, $schema, '' );
if ( ! is_wp_error( $matching_schema ) ) {
if ( ! isset( $schema['type'] ) ) {
$schema['type'] = $matching_schema['type'];
$response_data = rest_filter_response_by_context( $response_data, $matching_schema, $context );
if ( isset( $schema['oneOf'] ) ) {
$matching_schema = rest_find_one_matching_schema( $response_data, $schema, '', true );
if ( ! is_wp_error( $matching_schema ) ) {
if ( ! isset( $schema['type'] ) ) {
$schema['type'] = $matching_schema['type'];