wppaste
WordPress

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:1365
Retrieves the site index.

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
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
97–114

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

Plugin surface
1 hook

Third-party callbacks on 'rest_index' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP_REST_Server::get_index()
  • serializeserialisationmaybe_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 · 8 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.

WhenInstructionsCalls it makes
rest_is_field_included()97–102get_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(), 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()
always101–106get_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(), 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()
always102–107get_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(), 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()
!rest_is_field_included()103–108get_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(), 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()
always104–109get_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(), 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()
always106–111get_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(), 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()
always106–111get_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(), 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()
always109–114get_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(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev12997–1148
8.512997–1148
8.412997–1148
8.312997–1148
8.212997–1148
8.112997–11481 fewer instruction than PHP 7.4
7.413097–1158

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_Server::get_index() runs, in this order:

  1. apply_filters( rest_index )filterline 1421 (+56 into the body)

    Filters the REST API root index data.

Uses · 11

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'] ),		); 		$response = new WP_REST_Response( $available ); 		$fields = isset( $request['_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.		 * @param WP_REST_Request  $request  Request data.		 */		return apply_filters( 'rest_index', $response, $request );	}

Changelog

Introduced in 4.4.0. One change between 6.7.7 and 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.

6.9.7
Parameter $request retyped from array to WP_REST_Request.verified against source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.