user_email) ? wp_unslash($oldData->user_email) : ''; if (!$user || EmailVerificationService::isSame($oldEmail, $user->user_email)) { return; } // Account changes do not prove inbox ownership or change customer contact details. EmailVerificationService::markPending((int) $userId, $user->user_email); } public function maybeCreateUser($data) { $cart = Arr::get($data, 'cart'); $order = Arr::get($data, 'order'); $customer = $order->customer; if ($customer->getWpUserId()) { return; // User already exists } $willCreateUser = $order->type === Status::ORDER_TYPE_SUBSCRIPTION; if (!$willCreateUser) { // check if cart has set it $willCreateUser = $cart && Arr::get($cart, '_register_user', false); } if (!$willCreateUser) { // get the global settings where we may have auto create user enabled $willCreateUser = ''; // TODO: get the global settings } if (!$willCreateUser) { return; // No need to create user } // create the user from the customer data } /** * @return void */ public function userDeleteHandler($userId) { if (!$userId) { return; } // Unlink by identity. Matching on the account's email unlinked whichever // customer happened to hold it — possibly another account's — and left // this account's own customers pointing at a dead user id when their // contact address had drifted from the account's. Customer::query()->where('user_id', $userId)->update(['user_id' => null]); } public function userRegistrationHandler($userId) { $user = $userId ? get_userdata($userId) : false; if ($user) { EmailVerificationService::markPending((int) $userId, $user->user_email); } } }