wordpress-develop
wordpress-develop copied to clipboard
[RFC] Posts: Introduce register_content_type() API for declarative content modeling
Summary
This is a prototype implementation of the Declarative Content Modeling RFC that introduces register_content_type() - a higher-level API for registering content types in WordPress.
Try it out
Try the demo in WordPress Playground - includes a "Books" content type with sample data.
What it does
- Registers a post type via
register_post_type() - Registers meta fields via
register_post_meta()for each declared field - Provides automatic REST API schema generation
- Supports field type validation (string, integer, number, boolean, array, object)
- Stores UI hints for potential editor/admin integrations
Example usage
register_content_type( 'book', array(
'labels' => array( 'name' => 'Books' ),
'public' => true,
'show_in_rest' => true,
'fields' => array(
'isbn' => array(
'type' => 'string',
'required' => true,
'label' => 'ISBN',
),
'published_year' => array(
'type' => 'integer',
'label' => 'Published Year',
),
),
'ui' => array(
'editor_panel' => array(
'title' => 'Book Details',
'fields' => array( 'isbn', 'published_year' ),
),
),
) );
New functions
-
register_content_type()/unregister_content_type() -
content_type_exists()/get_content_type_object()/get_content_types() -
get_content_type_fields()/get_content_type_field() -
get_content_type_ui()/get_content_type_rest_schema() -
validate_content_type_values()
Files added
-
src/wp-includes/class-wp-content-type.php- Core class -
src/wp-includes/content-type.php- API functions -
tests/phpunit/tests/post/wpContentType.php- Unit tests (38 tests)
Status
🚧 Work in Progress - This is an early prototype for discussion and feedback.
Test plan
- [x] All 38 unit tests pass
- [ ] Manual testing with example plugin
- [ ] REST API endpoint testing
- [ ] Editor integration testing