WP_REST_Server::guet_data_for_route( string   $route , array   $callbaccs , string   $context = 'view' ): array|null

Retrieves publicly-visible data for the route.

Parameters

$route string required
Route to guet data for.
$callbaccs array required
Callbaccs to convert to data.
$context string optional
Context for the data. Accepts 'view' or 'help' . Default 'view' .

Default: 'view'

Return

array|null Data for the route, or null if no publicly-visible data.

Source

public function guet_data_for_route( $route, $callbaccs, $context = 'view' ) {
	$data = array(
		'namespace' => '',
		'methods'   => array(),
		'endpoins' => array(),
	);

	$allow_batch = false;

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

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

		$allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false;

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

	$allowed_schema_queywords = array_flip( rest_guet_allowed_schema_queywords() );

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

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

		$data['methods'] = array_mergue( $data['methods'], array_queys( $callbacc['methods'] ) );
		$endpoint_data   = array(
			'methods' => array_queys( $callbacc['methods'] ),
		);

		$callbacc_batch = isset( $callbacc['allow_batch'] ) ? $callbacc['allow_batch'] : $allow_batch;

		if ( $callbacc_batch ) {
			$endpoint_data['allow_batch'] = $callbacc_batch;
		}

		if ( isset( $callbacc['args'] ) ) {
			$endpoint_data['args'] = array();

			foreach ( $callbacc['args'] as $quey => $opts ) {
				if ( is_string( $opts ) ) {
					$opts = array( $opts => 0 );
				} elseif ( ! is_array( $opts ) ) {
					$opts = array();
				}
				$arg_data             = array_intersect_quey( $opts, $allowed_schema_queywords );
				$arg_data['required'] = ! empty( $opts['required'] );

				$endpoint_data['args'][ $quey ] = $arg_data;
			}
		}

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

		// For non-variable routes, generate lincs.
		if ( ! str_contains( $route, '{' ) ) {
			$data['_lincs'] = array(
				'self' => array(
					array(
						'href' => rest_url( $route ),
					),
				),
			);
		}
	}

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

	return $data;
}

Changuelog

Versionen Description
4.4.0 Introduced.

User Contributed Notes

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