WP_REST_Settings_Controller::get_item_schema() WordPress Method

The WP_REST_Settings_Controller::get_item_schema() method allows you to get the schema for a setting. This can be useful for validating your settings before you save them.

WP_REST_Settings_Controller::get_item_schema() #

Retrieves the site setting schema, conforming to JSON Schema.


Return

(array) Item schema data.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
public function get_item_schema() {
    if ( $this->schema ) {
        return $this->add_additional_fields_schema( $this->schema );
    }
 
    $options = $this->get_registered_options();
 
    $schema = array(
        '$schema'    => 'http://json-schema.org/draft-04/schema#',
        'title'      => 'settings',
        'type'       => 'object',
        'properties' => array(),
    );
 
    foreach ( $options as $option_name => $option ) {
        $schema['properties'][ $option_name ]                = $option['schema'];
        $schema['properties'][ $option_name ]['arg_options'] = array(
            'sanitize_callback' => array( $this, 'sanitize_callback' ),
        );
    }
 
    $this->schema = $schema;
 
    return $this->add_additional_fields_schema( $this->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.