WP_REST_Posts_Controller::get_item_schema(): array
- Since
- 4.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:2404
Compatibility
- WordPress
- since 4.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
array- Item schema data.
Performance profile
How much work a call to WP_REST_Posts_Controller::get_item_schema() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 8–279
- Plugin surface
- 1 hook
- Called by
- 6
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 550.
Third-party callbacks on 'rest_{$this->post_type}_item_schema' run inside this call, and their cost is not bounded by anything here.
6 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Posts_Controller::get_item_schema() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | ->add_additional_fields_schema() |
!$post_type_obj | 212–218 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
| always | 221–227 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
!$post_type_obj | 224–230 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
$post_type_obj | 230–236 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
| always | 233–239 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
$post_type_obj | 242–248 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
is_post_type_viewable() | 245–249 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
is_post_type_viewable() && $post_type_obj | 254–258 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
is_post_type_viewable() | 257–261 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
is_post_type_viewable() && $post_type_obj | 263–267 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), ->add_additional_fields_schema() |
is_post_type_viewable() && $post_type_obj | 266–270 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
1 further outcome, up to 279 instructions
is_post_type_viewable() && $post_type_obj | 275–279 | __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_post_stati(), array_keys(), __(), __(), get_post_type_object(), is_post_type_viewable(), __(), __(), __(), __(), __(), __(), get_object_taxonomies(), wp_list_filter(), ->get_schema_links(), array_keys(), apply_filters(), array_keys(), array_diff(), __(), sprintf(), _doing_it_wrong(), ->add_additional_fields_schema() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 550 | 8–279 | 28 | |
| 8.5 | 550 | 8–279 | 28 | |
| 8.4 | 550 | 8–279 | 28 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 553 | 8–279 | 28 | |
| 8.2 | 553 | 8–279 | 28 | 1 more instruction than PHP 8.1 |
| 8.1 | 552 | 8–279 | 28 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 553 | 8–279 | 28 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while WP_REST_Posts_Controller::get_item_schema() runs, in this order:
- apply_filters( rest_{$this->post_type}_item_schema )filterline 2818 (+414 into the body)
Filters the post's schema.
Uses · 12
- __()Retrieves the translation of $text.
- get_post_stati()Gets a list of post statuses.
- get_post_type_object()Retrieves a post type object by name.
- is_post_type_viewable()Determines whether a post type is considered "viewable".
- post_type_supports()Checks a post type's support for a given feature.
- get_post_format_slugs()Retrieves the array of post format slugs.
- wp_list_filter()Filters a list of objects, based on a set of key => value arguments.
- get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
- _doing_it_wrong()Marks something as being incorrectly called.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_REST_Posts_Controller::add_additional_fields_schema()
- WP_REST_Posts_Controller::get_schema_links()Retrieves Link Description Objects that should be added to the Schema for the posts collection.
Used by · 6
- WP_REST_Attachments_Controller::get_item_schema()Retrieves the attachment's schema, conforming to JSON Schema.
- WP_REST_Blocks_Controller::get_item_schema()Retrieves the pattern's schema, conforming to JSON Schema.
- WP_REST_Posts_Controller::create_item()Creates a single post.
- WP_REST_Posts_Controller::prepare_item_for_database()Prepares a single post for create or update.
- WP_REST_Posts_Controller::register_routes()Registers the routes for posts.
- WP_REST_Posts_Controller::update_item()Updates a single post.
Source code
public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->post_type, 'type' => 'object', // Base properties for every Post. 'properties' => array( 'date' => array( 'description' => __( "The date the post was published, in the site's timezone." ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'edit', 'embed' ), ), 'date_gmt' => array( 'description' => __( 'The date the post was published, as GMT.' ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), 'guid' => array( 'description' => __( 'The globally unique identifier for the post.' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'GUID for the post, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), 'readonly' => true, ), 'rendered' => array( 'description' => __( 'GUID for the post, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), ), ), 'id' => array( 'description' => __( 'Unique identifier for the post.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'link' => array( 'description' => __( 'URL to the post.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'modified' => array( 'description' => __( "The date the post was last modified, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'modified_gmt' => array( 'description' => __( 'The date the post was last modified, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'slug' => array( 'description' => __( 'An alphanumeric identifier for the post unique to its type.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => array( $this, 'sanitize_slug' ), ), ), 'status' => array( 'description' => __( 'A named status for the post.' ),Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.