WP_REST_Server::get_data_for_routes() WordPress Method

The WP_REST_Server::get_data_for_routes() method is responsible for providing data to the routes registered with the server. This data is typically provided in the form of an array, but can also be a WP_Error object if there is an error.

WP_REST_Server::get_data_for_routes( array $routes, string $context = 'view' ) #

Retrieves the publicly-visible data for routes.


Parameters

$routes

(array)(Required)Routes to get data for.

$context

(string)(Optional) Context for data. Accepts 'view' or 'help'.

Default value: 'view'


Top ↑

Return

(array[]) Route data to expose in indexes, keyed by route.


Top ↑

Source

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

	public function get_data_for_routes( $routes, $context = 'view' ) {
		$available = array();

		// Find the available routes.
		foreach ( $routes as $route => $callbacks ) {
			$data = $this->get_data_for_route( $route, $callbacks, $context );
			if ( empty( $data ) ) {
				continue;
			}

			/**
			 * Filters the publicly-visible data for a single REST API route.
			 *
			 * @since 4.4.0
			 *
			 * @param array $data Publicly-visible data for the route.
			 */
			$available[ $route ] = apply_filters( 'rest_endpoints_description', $data );
		}

		/**
		 * Filters the publicly-visible data for REST API routes.
		 *
		 * This data is exposed on indexes and can be used by clients or
		 * developers to investigate the site and find out how to use it. It
		 * acts as a form of self-documentation.
		 *
		 * @since 4.4.0
		 *
		 * @param array[] $available Route data to expose in indexes, keyed by route.
		 * @param array   $routes    Internal route data as an associative array.
		 */
		return apply_filters( 'rest_route_data', $available, $routes );
	}


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.