wppaste
WordPress

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
Retrieves the post's schema, conforming to JSON Schema.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
8–279

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 550.

Plugin surface
1 hook

Third-party callbacks on 'rest_{$this->post_type}_item_schema' run inside this call, and their cost is not bounded by anything here.

Called by
6

6 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always8->add_additional_fields_schema()
!$post_type_obj212–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()
always221–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_obj224–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_obj230–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()
always233–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_obj242–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_obj254–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_obj263–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_obj266–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_obj275–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

PHPCompiledExecutedBranchesNotes
8.6-dev5508–27928
8.55508–27928
8.45508–279283 fewer instructions than PHP 8.3
8.35538–27928
8.25538–279281 more instruction than PHP 8.1
8.15528–279281 fewer instruction than PHP 7.4
7.45538–27928

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:

  1. apply_filters( rest_{$this->post_type}_item_schema )filterline 2818 (+414 into the body)

    Filters the post's schema.

Uses · 12

Used by · 6

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.