ACF_Rest_Api::enrich_options_endpoint_args │ public │ ACF 6.8.10

Filter callback for rest_endpoints. Swaps the per-object properties into the acf entry of each matching endpoint's args. Only runs for OPTIONS requests on routes matching the current URL, so write validation is left untouched.

Метод класса: ACF_Rest_Api{}

Хуков нет.

Возвращает

array.

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

$ACF_Rest_Api = new ACF_Rest_Api();
$ACF_Rest_Api->enrich_options_endpoint_args( $endpoints );
$endpoints(массив) (обязательный)
Endpoints as passed by WP_REST_Server::get_routes().

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

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

Код ACF_Rest_Api::enrich_options_endpoint_args() ACF 6.8.11

public function enrich_options_endpoint_args( $endpoints ) {
	if (
		empty( $this->per_object_schema )
		|| ! ( $this->wp_request instanceof WP_REST_Request )
		|| 'OPTIONS' !== $this->wp_request->get_method()
	) {
		return $endpoints;
	}

	$current_route = $this->wp_request->get_route();
	if ( empty( $current_route ) ) {
		return $endpoints;
	}

	$per_object_properties = $this->per_object_schema['properties'];

	foreach ( $endpoints as $route_pattern => &$handlers ) {
		if ( ! preg_match( '@^' . $route_pattern . '$@i', $current_route ) ) {
			continue;
		}

		foreach ( $handlers as &$handler ) {
			if ( ! is_array( $handler ) || ! isset( $handler['args']['acf'] ) || ! is_array( $handler['args']['acf'] ) ) {
				continue;
			}
			// Preserve validate_callback, sanitize_callback, etc — only swap properties.
			$handler['args']['acf']['properties'] = $per_object_properties;
		}
		unset( $handler );
	}
	unset( $handlers );

	return $endpoints;
}