WC_REST_Authentication::check_permissions()privateWC 1.0

Check that the API keys provided have the proper key-specific permissions to either read or write API resources.

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

Хуков нет.

Возвращает

true|false|WP_Error.

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

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

Код WC_REST_Authentication::check_permissions() WC 8.7.0

private function check_permissions( $method ) {
	$permissions = $this->user->permissions;

	switch ( $method ) {
		case 'HEAD':
		case 'GET':
			if ( 'read' !== $permissions && 'read_write' !== $permissions ) {
				return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have read permissions.', 'woocommerce' ), array( 'status' => 401 ) );
			}
			break;
		case 'POST':
		case 'PUT':
		case 'PATCH':
		case 'DELETE':
			if ( 'write' !== $permissions && 'read_write' !== $permissions ) {
				return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have write permissions.', 'woocommerce' ), array( 'status' => 401 ) );
			}
			break;
		case 'OPTIONS':
			return true;

		default:
			return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Unknown request method.', 'woocommerce' ), array( 'status' => 401 ) );
	}

	return true;
}