WC_API_Authentication::check_api_key_permissions()publicWC 1.0

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

Method of the class: WC_API_Authentication{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_API_Authentication = new WC_API_Authentication();
$WC_API_Authentication->check_api_key_permissions( $key_permissions );
$key_permissions(string) (required)
-

WC_API_Authentication::check_api_key_permissions() code WC 8.9.0

public function check_api_key_permissions( $key_permissions ) {
	switch ( WC()->api->server->method ) {

		case 'HEAD':
		case 'GET':
			if ( 'read' !== $key_permissions && 'read_write' !== $key_permissions ) {
				throw new Exception( __( 'The API key provided does not have read permissions.', 'woocommerce' ), 401 );
			}
			break;

		case 'POST':
		case 'PUT':
		case 'PATCH':
		case 'DELETE':
			if ( 'write' !== $key_permissions && 'read_write' !== $key_permissions ) {
				throw new Exception( __( 'The API key provided does not have write permissions.', 'woocommerce' ), 401 );
			}
			break;
	}
}