WP_REST_Server::get_index( WP_REST_Request $request ): WP_REST_Response
- Since
- 4.4.0
- Source
wp-includes/rest-api/class-wp-rest-server.php:1360
Description
This endpoint describes the capabilities of the site.
Compatibility
- WordPress
- since 4.4.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
$requestWP_REST_Request- Request data.
Return value
WP_REST_Response- The API root index data.
Performance profile
How much work a call to WP_REST_Server::get_index() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 99–152
- Plugin surface
- 4 hooks
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 171.
Third-party callbacks on 'big_image_size_threshold', 'image_strip_meta', 'image_max_bit_depth' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below WP_REST_Server::get_index() - serializeserialisation
maybe_unserialize()one call below WP_REST_Server::get_index()
Further down the call graph this can also reach query 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 · 24 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Server::get_index() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!wp_is_client_side_media_processing_enabled() && rest_is_field_included() | 99–104 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
!wp_is_client_side_media_processing_enabled() | 103–108 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() && rest_is_field_included() | 103–108 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
!wp_is_client_side_media_processing_enabled() | 104–109 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
!wp_is_client_side_media_processing_enabled() && !rest_is_field_included() | 105–110 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
!wp_is_client_side_media_processing_enabled() | 106–111 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 107–112 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
!wp_is_client_side_media_processing_enabled() | 108–113 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
!wp_is_client_side_media_processing_enabled() | 108–113 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 108–113 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() && !rest_is_field_included() | 109–114 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 110–115 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
12 further outcomes, up to 152 instructions
!wp_is_client_side_media_processing_enabled() | 111–116 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 112–117 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 112–117 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
wp_is_client_side_media_processing_enabled() && !current_user_can() | 115–120 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() && rest_is_field_included() | 134–140 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 138–144 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 139–145 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), ->add_link(), ->add_active_theme_link_to_index(), ->add_site_logo_to_index(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() && !rest_is_field_included() | 140–146 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 141–147 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 143–149 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 143–149 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), apply_filters() |
wp_is_client_side_media_processing_enabled() && current_user_can() | 146–152 | get_option(), get_option(), get_option(), home_url(), get_option(), get_option(), get_option(), get_option(), get_option(), array_keys(), ->get_routes(), ->get_data_for_routes(), wp_is_client_side_media_processing_enabled(), current_user_can(), wp_get_registered_image_subsizes(), apply_filters(), apply_filters(), apply_filters(), name(), wp_parse_list(), ->has_param(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_site_logo_to_index(), rest_is_field_included(), rest_is_field_included(), ->add_site_icon_to_index(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 171 instructions, 99–152 executed per call, 12 branches. The work does not change between versions.
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 · 4
4 hooks fire while WP_REST_Server::get_index() runs, in this order:
- apply_filters( big_image_size_threshold )filterline 1386 (+26 into the body)
Filters the "BIG image" threshold value.
- apply_filters( image_strip_meta )filterline 1389 (+29 into the body)
Filters whether to strip metadata from images when they're resized.
- apply_filters( image_max_bit_depth )filterline 1400 (+40 into the body)
Filters the maximum bit depth of resized images.
Uses · 14
- get_option()Retrieves an option value based on an option name.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- wp_is_client_side_media_processing_enabled()Checks whether client-side media processing is enabled.
- current_user_can()Returns whether the current user has the specified capability.
- wp_get_registered_image_subsizes()Returns a normalized list of all currently registered image sub-sizes.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_parse_list()Converts a comma- or space-separated list of scalar values to an array.
- rest_is_field_included()Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body.
- WP_REST_Server::get_data_for_routes()Retrieves the publicly-visible data for routes.
- WP_REST_Server::get_routes()Retrieves the route map.
- WP_REST_Response::__construct()
- WP_REST_Server::add_active_theme_link_to_index()Adds a link to the active theme for users who have proper permissions.
Show all 14
- WP_REST_Server::add_site_logo_to_index()Exposes the site logo through the WordPress REST API.
- WP_REST_Server::add_site_icon_to_index()Exposes the site icon through the WordPress REST API.
Source code
public function get_index( $request ) { // General site data. $available = array( 'name' => get_option( 'blogname' ), 'description' => get_option( 'blogdescription' ), 'url' => get_option( 'siteurl' ), 'home' => home_url(), 'gmt_offset' => get_option( 'gmt_offset' ), 'timezone_string' => get_option( 'timezone_string' ), 'page_for_posts' => (int) get_option( 'page_for_posts' ), 'page_on_front' => (int) get_option( 'page_on_front' ), 'show_on_front' => get_option( 'show_on_front' ), 'namespaces' => array_keys( $this->namespaces ), 'authentication' => array(), 'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ), ); // Add media processing settings for users who can upload files. if ( wp_is_client_side_media_processing_enabled() && current_user_can( 'upload_files' ) ) { // Image sizes keyed by name for client-side media processing. $available['image_sizes'] = array(); foreach ( wp_get_registered_image_subsizes() as $name => $size ) { $available['image_sizes'][ $name ] = $size; } /** This filter is documented in wp-admin/includes/image.php */ $available['image_size_threshold'] = (int) apply_filters( 'big_image_size_threshold', 2560, array( 0, 0 ), '', 0 ); /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */ $available['image_strip_meta'] = (bool) apply_filters( 'image_strip_meta', true ); /* * On the server, this filter receives the decoded image's actual bit depth. * The client path never decodes the image on the server, so the filter is * applied with 16 (the maximum depth the client encoder can produce) as * both the value and the current depth. The client caps its output bit * depth at the filtered value, so a plugin lowering it (e.g. to 8) takes * effect on client-generated images too. */ /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */ $available['image_max_bit_depth'] = (int) apply_filters( 'image_max_bit_depth', 16, 16 ); } $response = new WP_REST_Response( $available ); $fields = $request['_fields'] ?? ''; $fields = wp_parse_list( $fields ); if ( empty( $fields ) ) { $fields[] = '_links'; } if ( $request->has_param( '_embed' ) ) { $fields[] = '_embedded'; } if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' ); $this->add_active_theme_link_to_index( $response ); $this->add_site_logo_to_index( $response ); $this->add_site_icon_to_index( $response ); } else { if ( rest_is_field_included( 'site_logo', $fields ) ) { $this->add_site_logo_to_index( $response ); } if ( rest_is_field_included( 'site_icon', $fields ) || rest_is_field_included( 'site_icon_url', $fields ) ) { $this->add_site_icon_to_index( $response ); } } /** * Filters the REST API root index data. * * This contains the data describing the API. This includes information * about supported authentication schemes, supported namespaces, routes * available on the API, and a small amount of data about the site. * * @since 4.4.0 * @since 6.0.0 Added `$request` parameter. * * @param WP_REST_Response $response Response data.Changelog
Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$request retyped from array to WP_REST_Request.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/class-wp-rest-server.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.