Retrieves the post’s schema, conforming to JSON Schema.
Source
public function get_item_schema() {
if ( $this->schema ) {
return $this->add_additional_fields_schema( $this->schema );
}
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
'type' => 'object',
// Base properties for every Post.
'properties' => array(
'id' => array(
'description' => __( 'Unique identifier for the post.', 'default' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
'readonly' => true,
),
'theme_json_version' => array(
'description' => __( 'Version of the theme.json schema used for the typography settings.' ),
'type' => 'integer',
'default' => static::LATEST_THEME_JSON_VERSION_SUPPORTED,
'minimum' => 2,
'maximum' => static::LATEST_THEME_JSON_VERSION_SUPPORTED,
'context' => array( 'view', 'edit', 'embed' ),
),
'parent' => array(
'description' => __( 'The ID for the parent font family of the font face.' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),
// Font face settings come directly from theme.json schema
// See https://schemas.wp.org/trunk/theme.json
'font_face_settings' => array(
'description' => __( 'font-face declaration in theme.json format.' ),
'type' => 'object',
'context' => array( 'view', 'edit', 'embed' ),
'properties' => array(
'fontFamily' => array(
'description' => __( 'CSS font-family value.' ),
'type' => 'string',
'default' => '',
'arg_options' => array(
'sanitize_callback' => array( 'WP_Font_Utils', 'sanitize_font_family' ),
),
),
'fontStyle' => array(
'description' => __( 'CSS font-style value.' ),
'type' => 'string',
'default' => 'normal',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'fontWeight' => array(
'description' => __( 'List of available font weights, separated by a space.' ),
'default' => '400',
// Changed from `oneOf` to avoid errors from loose type checking.
// e.g. a fontWeight of "400" validates as both a string and an integer due to is_numeric check.
'type' => array( 'string', 'integer' ),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'fontDisplay' => array(
'description' => __( 'CSS font-display value.' ),
'type' => 'string',
'default' => 'fallback',
'enum' => array(
'auto',
'block',
'fallback',
'swap',
'optional',
),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'src' => array(
'description' => __( 'Paths or URLs to the font files.' ),
// Changed from `oneOf` to `anyOf` due to rest_sanitize_array converting a string into an array,
// and causing a "matches more than one of the expected formats" error.
'anyOf' => array(
array(
'type' => 'string',
),
array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
),
'default' => array(),
'arg_options' => array(
'sanitize_callback' => function ( $value ) {
return is_array( $value ) ? array_map( array( $this, 'sanitize_src' ), $value ) : $this->sanitize_src( $value );
},
),
),
'fontStretch' => array(
'description' => __( 'CSS font-stretch value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'ascentOverride' => array(
'description' => __( 'CSS ascent-override value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'descentOverride' => array(
'description' => __( 'CSS descent-override value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'fontVariant' => array(
'description' => __( 'CSS font-variant value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'fontFeatureSettings' => array(
'description' => __( 'CSS font-feature-settings value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'fontVariationSettings' => array(
'description' => __( 'CSS font-variation-settings value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'lineGapOverride' => array(
'description' => __( 'CSS line-gap-override value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'sizeAdjust' => array(
'description' => __( 'CSS size-adjust value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'unicodeRange' => array(
'description' => __( 'CSS unicode-range value.' ),
'type' => 'string',
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'preview' => array(
'description' => __( 'URL to a preview image of the font face.' ),
'type' => 'string',
'format' => 'uri',
'default' => '',
'arg_options' => array(
'sanitize_callback' => 'sanitize_url',
),
),
),
'required' => array( 'fontFamily', 'src' ),
'additionalProperties' => false,
),
),
);
$this->schema = $schema;
return $this->add_additional_fields_schema( $this->schema );
}
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.