Automattic\WooCommerce\Api\Attributes
RequiredCapability::authorize
Decide whether the given principal holds the required capability.
Reads the WordPress user from the principal wrapper and delegates to \user_can(). Anonymous principals (the WP user has ID === 0) never hold any capability, so the check returns false naturally.
Method of the class: RequiredCapability{}
No Hooks.
Returns
null. Nothing (null).
Usage
$RequiredCapability = new RequiredCapability(); $RequiredCapability->authorize( $principal ): bool;
- $principal(Principal) (required)
- The resolved request principal.
RequiredCapability::authorize() RequiredCapability::authorize code WC 10.9.1
public function authorize( Principal $principal ): bool {
return user_can( $principal->user, $this->capability );
}