WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_REST_Server::get_data_for_route() WP 4.4.0

Retrieves publicly-visible data for the route.

Это метод класса: WP_REST_Server

Хуков нет.

Возвращает

Массив/null. Data for the route, or null if no publicly-visible data.

Использование

$WP_REST_Server = new WP_REST_Server();
$var = $WP_REST_Server->get_data_for_route( $route, $callbacks, $context );
$route(строка) (обязательный)
Route to get data for.
$callbacks(массив) (обязательный)
Callbacks to convert to data.
$context(строка)
Context for the data. Accepts 'view' or 'help'.
По умолчанию: 'view'

Список изменений

С версии 4.4.0 Введена.

Код WP REST Server::get data for route: wp-includes/rest-api/class-wp-rest-server.php WP 5.2.2

<?php
public function get_data_for_route( $route, $callbacks, $context = 'view' ) {
	$data = array(
		'namespace' => '',
		'methods'   => array(),
		'endpoints' => array(),
	);

	if ( isset( $this->route_options[ $route ] ) ) {
		$options = $this->route_options[ $route ];

		if ( isset( $options['namespace'] ) ) {
			$data['namespace'] = $options['namespace'];
		}

		if ( isset( $options['schema'] ) && 'help' === $context ) {
			$data['schema'] = call_user_func( $options['schema'] );
		}
	}

	$route = preg_replace( '#\(\?P<(\w+?)>.*?\)#', '{$1}', $route );

	foreach ( $callbacks as $callback ) {
		// Skip to the next route if any callback is hidden.
		if ( empty( $callback['show_in_index'] ) ) {
			continue;
		}

		$data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) );
		$endpoint_data   = array(
			'methods' => array_keys( $callback['methods'] ),
		);

		if ( isset( $callback['args'] ) ) {
			$endpoint_data['args'] = array();
			foreach ( $callback['args'] as $key => $opts ) {
				$arg_data = array(
					'required' => ! empty( $opts['required'] ),
				);
				if ( isset( $opts['default'] ) ) {
					$arg_data['default'] = $opts['default'];
				}
				if ( isset( $opts['enum'] ) ) {
					$arg_data['enum'] = $opts['enum'];
				}
				if ( isset( $opts['description'] ) ) {
					$arg_data['description'] = $opts['description'];
				}
				if ( isset( $opts['type'] ) ) {
					$arg_data['type'] = $opts['type'];
				}
				if ( isset( $opts['items'] ) ) {
					$arg_data['items'] = $opts['items'];
				}
				$endpoint_data['args'][ $key ] = $arg_data;
			}
		}

		$data['endpoints'][] = $endpoint_data;

		// For non-variable routes, generate links.
		if ( strpos( $route, '{' ) === false ) {
			$data['_links'] = array(
				'self' => rest_url( $route ),
			);
		}
	}

	if ( empty( $data['methods'] ) ) {
		// No methods supported, hide the route.
		return null;
	}

	return $data;
}