WP_REST_Server::get_index() WordPress Method

The WP_REST_Server::get_index() method is used to retrieve a list of all available routes for the current request. This is useful for debugging and for creating documentation.

WP_REST_Server::get_index( array $request ) #

Retrieves the site index.


Description

This endpoint describes the capabilities of the site.


Top ↑

Parameters

$request

(array)(Required)Request.

  • 'context'
    (string) Context.


Top ↑

Return

(WP_REST_Response) The API root index data.


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-server.php

	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' ),
			'namespaces'      => array_keys( $this->namespaces ),
			'authentication'  => array(),
			'routes'          => $this->get_data_for_routes( $this->get_routes(), $request['context'] ),
		);

		$response = new WP_REST_Response( $available );
		$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 );

		/**
		 * 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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.