WC_REST_Controller::adjust_wp_5_5_datatype_compatibility()protectedWC 1.0

Change datatypes date-time to string, and mixed to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.

See @link https://core.trac.wordpress.org/changeset/48306

We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.

Метод класса: WC_REST_Controller{}

Хуков нет.

Возвращает

Разное. Schema with converted datatype.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->adjust_wp_5_5_datatype_compatibility( $endpoint_args );
$endpoint_args(массив) (обязательный)
Schema with datatypes to convert.

Код WC_REST_Controller::adjust_wp_5_5_datatype_compatibility() WC 8.7.0

protected function adjust_wp_5_5_datatype_compatibility( $endpoint_args ) {
	if ( version_compare( get_bloginfo( 'version' ), '5.5', '<' ) ) {
		return $endpoint_args;
	}

	foreach ( $endpoint_args as $field_id => $params ) {

		if ( ! isset( $params['type'] ) ) {
			continue;
		}

		/**
		 * Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string'.
		 */
		if ( 'date-time' === $params['type'] ) {
			$params['type'] = array( 'null', 'string' );
		}

		/**
		 * WARNING: Order of fields here is important, types of fields are ordered from most specific to least specific as perceived by core's built-in type validation methods.
		 */
		if ( 'mixed' === $params['type'] ) {
			$params['type'] = array( 'null', 'object', 'string', 'number', 'boolean', 'integer', 'array' );
		}

		if ( isset( $params['properties'] ) ) {
			$params['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['properties'] );
		}

		if ( isset( $params['items'] ) && isset( $params['items']['properties'] ) ) {
			$params['items']['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['items']['properties'] );
		}

		$endpoint_args[ $field_id ] = $params;
	}
	return $endpoint_args;
}