[wp-trac] [WordPress Trac] #64423: Introduce register_content_type() API for declarative content modeling
WordPress Trac
noreply at wordpress.org
Tue Dec 16 21:47:23 UTC 2025
#64423: Introduce register_content_type() API for declarative content modeling
-------------------------------+--------------------------------------
Reporter: whyisjake | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords: has-patch has-unit-tests
Focuses: |
-------------------------------+--------------------------------------
This ticket proposes a new `register_content_type()` function that
provides a higher-level, declarative API for registering custom post types
with their associated meta fields in a single call.
== Background ==
Currently, registering a custom post type with structured data requires
separate calls to `register_post_type()` and multiple calls to
`register_post_meta()`. This pattern is verbose, error-prone, and requires
developers to manually coordinate REST API schema generation across these
separate registrations.
See the full RFC:
https://docs.google.com/document/d/1Z8ei9vOsj_TvyApq1EKet9BhzA4zdm8uFPd9cXJWpJs/edit
== Proposal ==
Introduce `register_content_type()` which:
* 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',
),
),
) );
}}}
== 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()`
== Try It ==
[https://playground.wordpress.net/?blueprint-
url=https://raw.githubusercontent.com/whyisjake/content-type-api-
demo/main/blueprint.json Live demo in WordPress Playground] - includes a
"Books" content type with sample data.
== Implementation ==
Pull request: https://github.com/WordPress/wordpress-develop/pull/10617
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
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64423>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list