Automattic\WooCommerce\Internal\Admin\Settings

PaymentsRestController::check_permissionsprivateWC 1.0

General permissions check for payments settings REST API endpoint.

Method of the class: PaymentsRestController{}

No Hooks.

Returns

true|false|WP_Error. True if the current user has the capability, otherwise an "Unauthorized" error or False if no error is available for the request method.

Usage

// private - for code of main (parent) class only
$result = $this->check_permissions( $request );
$request(WP_REST_Request) (required)
The request for which the permission is checked.

PaymentsRestController::check_permissions() code WC 9.8.5

private function check_permissions( WP_REST_Request $request ) {
	$context = 'read';
	if ( 'POST' === $request->get_method() ) {
		$context = 'edit';
	} elseif ( 'DELETE' === $request->get_method() ) {
		$context = 'delete';
	}

	if ( wc_rest_check_manager_permissions( 'payment_gateways', $context ) ) {
		return true;
	}

	$error_information = $this->get_authentication_error_by_method( $request->get_method() );
	if ( is_null( $error_information ) ) {
		return false;
	}

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