WP_REST_Server::get_data_for_routes( array $routes, string $context = ‘view’ ): array[]

In this article

Retrieves the publicly-visible data for routes.

Parameters

$routesarrayrequired
Routes to get data for.
$contextstringoptional
Context for data. Accepts 'view' or 'help'. Default 'view'.

Default:'view'

Return

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

Source

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

Hooks

apply_filters( ‘rest_endpoints_description’, array $data )

Filters the publicly-visible data for a single REST API route.

apply_filters( ‘rest_route_data’, array[] $available, array $routes )

Filters the publicly-visible data for REST API routes.

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.