ACF\AI\Abilities
PostType::get_rest_item_input_schema
Builds a basic input schema for creating or updating a post type item.
We only include a few common properties since the REST API handles the validation and updates.
Method of the class: PostType{}
No Hooks.
Returns
array.
Usage
// private - for code of main (parent) class only $result = $this->get_rest_item_input_schema( $acf_fields, $post_type_label, $action, $post_type_name ): array;
- $acf_fields(array) (required)
- An array of ACF fields present on the post type.
- $post_type_label(string) (required)
- The singular label for the post type.
- $action(string)
- The action being performed on the item.
Default:'create' - $post_type_name(string)
- The post type name/key.
Default:''
Changelog
| Since 6.8.0 | Introduced. |
PostType::get_rest_item_input_schema() PostType::get rest item input schema code ACF 6.8.8
private function get_rest_item_input_schema( array $acf_fields, string $post_type_label, string $action = 'create', string $post_type_name = '' ): array {
$schema = array(
'type' => 'object',
'properties' => array(),
);
if ( 'update' === $action ) {
$schema['properties']['id'] = array(
'type' => 'integer',
'description' => sprintf( 'The ID of the %s to update.', strtolower( $post_type_label ) ),
'required' => true,
);
}
$schema['properties']['title'] = array(
'type' => 'string',
'description' => sprintf( 'The title of the %s.', strtolower( $post_type_label ) ),
'required' => 'update' !== $action,
);
$schema['properties']['content'] = array(
'type' => 'string',
'description' => sprintf( 'The content of the %s.', strtolower( $post_type_label ) ),
'required' => false,
);
// TODO: Provide enum?
$schema['properties']['status'] = array(
'type' => 'string',
'description' => 'The status of the post (publish, draft, etc.)',
'required' => false,
);
// Only add featured_media if the post type supports thumbnails.
if ( ! empty( $post_type_name ) && post_type_supports( $post_type_name, 'thumbnail' ) ) {
$schema['properties']['featured_media'] = array(
'type' => 'integer',
'description' => 'The ID of the featured image (attachment) for this post. The attachment must exist and be an image. Set to 0 to remove; invalid or non-image IDs will not set a featured image.',
'required' => false,
);
}
// Only add author if the post type supports author.
if ( ! empty( $post_type_name ) && post_type_supports( $post_type_name, 'author' ) ) {
$schema['properties']['author'] = array(
'type' => 'integer',
'description' => 'The ID of the user to assign as the author of this post. The user must exist and have permission to be assigned as an author.',
'required' => false,
);
}
return $this->add_acf_fields_to_schema( $schema, $acf_fields );
}