Automattic\WooCommerce\Internal\Api
Utils::check_current_user_can
Assert that the current user has the given WordPress capability.
Throws a GraphQL UNAUTHORIZED error if the check fails. Intended to be called from generated resolver methods so the capability-check boilerplate doesn't have to be repeated in every resolver.
Method of the class: Utils{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Utils::check_current_user_can( $capability ): void;
- $capability(string) (required)
- A WordPress capability slug.
Utils::check_current_user_can() Utils::check current user can code WC 10.8.1
public static function check_current_user_can( string $capability ): void {
if ( ! current_user_can( $capability ) ) {
throw new \Automattic\WooCommerce\Vendor\GraphQL\Error\Error(
'You do not have permission to perform this action.',
extensions: array( 'code' => 'UNAUTHORIZED' )
);
}
}