ACF_Rest_Api::current_user_can_read_request_object │ private │ ACF 6.8.10

Whether the current caller can read the given object. Fails closed (returns false) when permission cannot be conclusively verified. Callers guarantee that $this->wp_request is a WP_REST_Request.

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

Хуков нет.

Возвращает

boolean.

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

// private - только в коде основоного (родительского) класса
$result = $this->current_user_can_read_request_object( $object_id, $child_id );
$object_id(int|строка) (обязательный)
The effective target ID (child ID if present, otherwise the URL id).
$child_id(int|строка) (обязательный)
The URL child_id, if any — signals a revision/autosave context.

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

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

Код ACF_Rest_Api::current_user_can_read_request_object() ACF 6.8.11

private function current_user_can_read_request_object( $object_id, $child_id ) {
	// Revisions and autosaves inherit edit_post on the parent.
	if ( $child_id ) {
		$parent_id = (int) $this->request->get_url_param( 'id' );
		return $parent_id > 0 && acf_current_user_can_edit_post( $parent_id );
	}

	$controller = $this->resolve_rest_controller();
	if ( ! $controller instanceof WP_REST_Controller ) {
		return false;
	}

	// untrailingslashit so trailing-slash URLs still match core's route registrations.
	$route = untrailingslashit( $this->wp_request->get_route() );
	if ( '' === $route ) {
		return false;
	}

	$check = new WP_REST_Request( 'GET', $route );
	$check->set_url_params( array( 'id' => $object_id ) );
	$check->set_query_params( array( 'context' => 'view' ) );

	// Strict === so WP_Error is treated as unauthorized.
	return true === $controller->get_item_permissions_check( $check );
}