WP_REST_Posts_Controller::get_schema_links(): array
- Since
- 4.9.8
- Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:2846
Compatibility
- WordPress
- since 4.9.8
- 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
Performance profile
How much work a call to WP_REST_Posts_Controller::get_schema_links() 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
- 47–75
- Plugin surface
- None
- Called by
- 2
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 120.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 6 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_schema_links() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!post_type_supports() | 47–48 | rest_url(), __(), post_type_supports(), get_object_taxonomies(), wp_list_filter() |
post_type_supports() | 56–57 | rest_url(), __(), post_type_supports(), __(), get_object_taxonomies(), wp_list_filter() |
!post_type_supports() | 56–57 | rest_url(), __(), __(), post_type_supports(), get_object_taxonomies(), wp_list_filter() |
post_type_supports() | 65–66 | rest_url(), __(), __(), post_type_supports(), __(), get_object_taxonomies(), wp_list_filter() |
!post_type_supports() | 65–66 | rest_url(), __(), __(), __(), post_type_supports(), get_object_taxonomies(), wp_list_filter() |
post_type_supports() | 74–75 | rest_url(), __(), __(), __(), post_type_supports(), __(), get_object_taxonomies(), wp_list_filter() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 120 | 47–75 | 6 | |
| 8.5 | 120 | 47–75 | 6 | |
| 8.4 | 120 | 47–75 | 6 | |
| 8.3 | 120 | 47–75 | 6 | |
| 8.2 | 120 | 47–75 | 6 | |
| 8.1 | 120 | 47–75 | 6 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 122 | 47–75 | 6 |
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.
Uses · 5
- rest_url()Retrieves the URL to a REST endpoint.
- __()Retrieves the translation of $text.
- post_type_supports()Checks a post type's support for a given feature.
- 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.
Used by · 2
- WP_REST_Menu_Items_Controller::get_schema_links()Retrieves Link Description Objects that should be added to the Schema for the nav menu items collection.
- WP_REST_Posts_Controller::get_item_schema()Retrieves the post's schema, conforming to JSON Schema.
Source code
protected function get_schema_links() { $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); $links = array(); if ( 'attachment' !== $this->post_type ) { $links[] = array( 'rel' => 'https://api.w.org/action-publish', 'title' => __( 'The current user can publish this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'status' => array( 'type' => 'string', 'enum' => array( 'publish', 'future' ), ), ), ), ); } $links[] = array( 'rel' => 'https://api.w.org/action-unfiltered-html', 'title' => __( 'The current user can post unfiltered HTML markup and JavaScript.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'content' => array( 'raw' => array( 'type' => 'string', ), ), ), ), ); if ( 'post' === $this->post_type ) { $links[] = array( 'rel' => 'https://api.w.org/action-sticky', 'title' => __( 'The current user can sticky this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'sticky' => array( 'type' => 'boolean', ), ), ), ); } if ( post_type_supports( $this->post_type, 'author' ) ) { $links[] = array( 'rel' => 'https://api.w.org/action-assign-author', 'title' => __( 'The current user can change the author on this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'author' => array( 'type' => 'integer', ), ), ), ); } $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $tax ) { $tax_base = ! empty( $tax->rest_base ) ? $tax->rest_base : $tax->name; /* translators: %s: Taxonomy name. */ $assign_title = sprintf( __( 'The current user can assign terms in the %s taxonomy.' ), $tax->name ); /* translators: %s: Taxonomy name. */ $create_title = sprintf( __( 'The current user can create terms in the %s taxonomy.' ), $tax->name );Changelog
Introduced in 4.9.8. 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.