WP_REST_Themes_Controller::prepare_links( WP_Theme $theme ): array
- Since
- 5.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php:380
Compatibility
- WordPress
- since 5.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.
Parameters
$themeWP_Theme- Theme data.
Return value
array- Links for the given block type.
Performance profile
How much work a call to WP_REST_Themes_Controller::prepare_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
- Trivial
- Scaling
- Constant
- Instructions
- 39–51
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 56.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Themes_Controller::prepare_links() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 39–44 | ->get_stylesheet(), rest_url(), rest_url(), wp_get_theme(), ->is_same_theme(), ::WP_Theme_JSON_Resolver() |
| always | 46–51 | ->get_stylesheet(), rest_url(), rest_url(), wp_get_theme(), ->is_same_theme(), ::WP_Theme_JSON_Resolver(), rest_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 56 | 39–51 | 3 | |
| 8.5 | 56 | 39–51 | 3 | |
| 8.4 | 56 | 39–51 | 3 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 59 | 42–54 | 3 | |
| 8.2 | 59 | 42–54 | 3 | |
| 8.1 | 59 | 42–54 | 3 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 60 | 42–55 | 3 |
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.
- wp_get_theme()Gets a WP_Theme object for a theme.
- WP_REST_Themes_Controller::is_same_theme()Helper function to compare two themes.
- WP_Theme_JSON_Resolver::get_user_global_styles_post_id()Returns the ID of the custom post type that stores user data.
- WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles()Returns the custom post type that contains the user's origin config for the active theme or an empty array if none are found.
Used by · 1
- WP_REST_Themes_Controller::prepare_item_for_response()Prepares a single theme output for response.
Source code
protected function prepare_links( $theme ) { $links = array( 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $theme->get_stylesheet() ) ), ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), ); if ( $this->is_same_theme( $theme, wp_get_theme() ) ) { // This creates a record for the active theme if not existent. $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); } else { $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); $id = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null; } if ( $id ) { $links['https://api.w.org/user-global-styles'] = array( 'href' => rest_url( 'wp/v2/global-styles/' . $id ), ); } return $links; }Changelog
Introduced in 5.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 6.7.7 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-themes-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.