registerClientRepository(); } /** * Register client role if it doesn't exist. * * Idempotent — short-circuits when WooCommerce (or anything else) * has already registered the role. Two implications worth knowing: * * 1. We register WITHOUT the `read` capability. On a site that * never had WooCommerce, existing 'customer'-role users had no * effective `read` cap because the role wasn't registered at * all (and `WP_User::has_cap` couldn't pull `read` from a role * that didn't exist). Registering with `['read' => true]` here * would silently UPGRADE those users — granting wp-admin access * they never had. We pass `[]` so the registration only fixes * the display label, not the cap surface. * * 2. On a site WITH WooCommerce, WC has already registered * 'customer' with its full cap set (including `read`). Our * add_role() is a no-op there — get_role() returns truthy and * we bail. WC customers retain WC's caps unchanged. */ public function registerClientRole() { if (get_role('customer')) { return; } add_role( 'customer', __('Customer', 'easy-invoice'), [] ); } /** * Register client repository */ protected function registerClientRepository() { // Create and store the repository instance self::$repository = new ClientRepository(); } /** * Get the client repository * * @return ClientRepositoryInterface The client repository */ public static function getClientRepository() { // Create the repository if it doesn't exist if (self::$repository === null) { self::$repository = new ClientRepository(); } return self::$repository; } }