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:1360
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
Heavy

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

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
99–152

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

Plugin surface
4 hooks

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.

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 · 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.

WhenInstructionsCalls it makes
!wp_is_client_side_media_processing_enabled() && rest_is_field_included()99–104get_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–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(), 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–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(), 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–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(), 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–110get_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–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(), 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–112get_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–113get_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–113get_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–113get_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–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(), 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–115get_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–116get_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–117get_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–117get_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–120get_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–140get_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–144get_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–145get_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–146get_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–147get_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–149get_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–149get_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–152get_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:

  1. apply_filters( big_image_size_threshold )filterline 1386 (+26 into the body)

    Filters the "BIG image" threshold value.

  2. apply_filters( image_strip_meta )filterline 1389 (+29 into the body)

    Filters whether to strip metadata from images when they're resized.

  3. apply_filters( image_max_bit_depth )filterline 1400 (+40 into the body)

    Filters the maximum bit depth of resized images.

  4. apply_filters( rest_index )filterline 1442 (+82 into the body)

    Filters the REST API root index data.

Uses · 14

Show all 14

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.

  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 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.