WP_REST_Meta_Fields::get_field_schema() WordPress Method

The WP_REST_Meta_Fields::get_field_schema() method is used to retrieve the schema for a given meta field. This can be used to validate a meta value before it is saved or updated.

WP_REST_Meta_Fields::get_field_schema() #

Retrieves the object’s meta schema, conforming to JSON Schema.


Return

(array) Field schema data.


Top ↑

Source

File: wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

	public function get_field_schema() {
		$fields = $this->get_registered_fields();

		$schema = array(
			'description' => __( 'Meta fields.' ),
			'type'        => 'object',
			'context'     => array( 'view', 'edit' ),
			'properties'  => array(),
			'arg_options' => array(
				'sanitize_callback' => null,
				'validate_callback' => array( $this, 'check_meta_is_array' ),
			),
		);

		foreach ( $fields as $args ) {
			$schema['properties'][ $args['name'] ] = $args['schema'];
		}

		return $schema;
	}


Top ↑

Changelog

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