acf_field_select::get_rest_schema
Return the schema array for the REST API.
Method of the class: acf_field_select{}
No Hooks.
Returns
Array.
Usage
$acf_field_select = new acf_field_select(); $acf_field_select->get_rest_schema( $field );
- $field(array) (required)
- .
acf_field_select::get_rest_schema() acf field select::get rest schema code ACF 6.0.4
public function get_rest_schema( array $field ) {
/**
* If a user has defined keys for the select options,
* we should use the keys for the available options to POST to,
* since they are what is displayed in GET requests.
*/
$option_keys = array_diff(
array_keys( $field['choices'] ),
array_values( $field['choices'] )
);
$schema = array(
'type' => array( 'string', 'array', 'int', 'null' ),
'required' => ! empty( $field['required'] ),
'items' => array(
'type' => array( 'string', 'int' ),
'enum' => empty( $option_keys ) ? $field['choices'] : $option_keys,
),
);
if ( empty( $field['allow_null'] ) ) {
$schema['minItems'] = 1;
}
if ( empty( $field['multiple'] ) ) {
$schema['maxItems'] = 1;
}
if ( isset( $field['default_value'] ) && '' !== $field['default_value'] ) {
$schema['default'] = $field['default_value'];
}
return $schema;
}