Automattic\WooCommerce\Internal\RestApi\Routes\V4

AbstractController::get_authentication_error_by_methodprotectedWC 1.0

Returns an authentication error for a given HTTP verb.

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

Хуков нет.

Возвращает

WP_Error|false. WP Error object or false if no error is found.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_authentication_error_by_method( $method );
$method(строка) (обязательный)
HTTP method.

Код AbstractController::get_authentication_error_by_method() WC 11.0.1

protected function get_authentication_error_by_method( string $method ) {
	$errors = array(
		'GET'    => array(
			'code'    => $this->get_error_prefix() . 'cannot_view',
			'message' => __( 'Sorry, you cannot view resources.', 'woocommerce' ),
		),
		'POST'   => array(
			'code'    => $this->get_error_prefix() . 'cannot_create',
			'message' => __( 'Sorry, you cannot create resources.', 'woocommerce' ),
		),
		'PUT'    => array(
			'code'    => $this->get_error_prefix() . 'cannot_update',
			'message' => __( 'Sorry, you cannot update resources.', 'woocommerce' ),
		),
		'PATCH'  => array(
			'code'    => $this->get_error_prefix() . 'cannot_update',
			'message' => __( 'Sorry, you cannot update resources.', 'woocommerce' ),
		),
		'DELETE' => array(
			'code'    => $this->get_error_prefix() . 'cannot_delete',
			'message' => __( 'Sorry, you cannot delete resources.', 'woocommerce' ),
		),
	);

	if ( ! isset( $errors[ $method ] ) ) {
		return false;
	}

	return new WP_Error(
		$errors[ $method ]['code'],
		$errors[ $method ]['message'],
		array( 'status' => rest_authorization_required_code() )
	);
}