Summery Summery
Append result of internal request to REST API for purpose of preloading data to be attached to a page.
Syntax Syntax
Description Description
Expected to be called in the context of array_reduce
.
Parameters Parameters
- $memo
-
(Required) Reduce accumulator.
- $path
-
(Required) REST API path to preload.
Return Return
(array) Modified reduce accumulator.
Source Source
File: wp-includes/rest-api.php
* @return mixed The stabilized value. */ function rest_stabilize_value( $value ) { if ( is_scalar( $value ) || is_null( $value ) ) { return $value; } if ( is_object( $value ) ) { _doing_it_wrong( __FUNCTION__, __( 'Cannot stabilize objects. Convert the object to an array first.' ), '5.5.0' ); return $value; } ksort( $value ); foreach ( $value as $k => $v ) { $value[ $k ] = rest_stabilize_value( $v ); } return $value; } /** * Validate a value based on a schema. * * @since 4.7.0 * @since 4.9.0 Support the "object" type. * @since 5.2.0 Support validating "additionalProperties" against a schema. * @since 5.3.0 Support multiple types. * @since 5.4.0 Convert an empty string to an empty object. * @since 5.5.0 Add the "uuid" and "hex-color" formats. * Support the "minLength", "maxLength" and "pattern" keywords for strings. * Support the "minItems", "maxItems" and "uniqueItems" keywords for arrays. * Validate required properties. * * @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. * @return true|WP_Error */ function rest_validate_value_from_schema( $value, $args, $param = '' ) { $allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' ); if ( ! isset( $args['type'] ) ) { /* translators: 1. 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 ); if ( ! $best_type ) { /* translators: 1: Parameter, 2: List of types. */ return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, implode( ',', $args['type'] ) ) ); } $args['type'] = $best_type; }
Advertisement
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |