public function updateProfile($data) { if (is_user_logged_in()) { $is_sig_validate = SigUtils::validateUserSignature($data['UID'], $data['signatureTimestamp'], GIGYA__API_SECRET, $data['UIDSignature']); if ($is_sig_validate) { $gigyaCMS = new GigyaCMS(); $gigya_account = $gigyaCMS->getAccount($data['UID']); if (!is_wp_error($gigya_account)) { _gigya_add_to_wp_user_meta($gigya_account['profile'], get_current_user_id()); } } } }
/** * Register new WP user from Gigya user. */ private function register() { // Before we insert new user to the system, we check // if there is a user with the same email in our DB. // When there is we ask the user login in the // previous account and link it to the new one. $email_exists = email_exists($this->gigya_user['email']); if (!empty($email_exists)) { // Return JSON with login form to client. wp_send_json_success(array('type' => 'form', 'html' => $this->linkAccountForm($email_exists))); } // If the name of the new user already exists in the system, // WP will reject the registration and return an error. to prevent this // we attach an extra value to the name to make it unique. $username_exist = username_exists($this->gigya_user['nickname']); if (!empty($username_exist)) { $this->gigya_user['nickname'] .= uniqid('-'); } // When the admin checked to // show the entire registration form to the user. if (!empty($this->login_options['registerExtra'])) { $this->registerExtraForm(); } // Register a new user to WP with params from Gigya. $name = $this->gigya_user['nickname']; $email = $this->gigya_user['email']; // Hook just before register new user from Gigya Social Login. do_action('gigya_before_social_register', $name, $email); $user_id = register_new_user($name, $email); // On registration error. if (!empty($user_id->errors)) { $msg = ''; foreach ($user_id->errors as $error) { foreach ($error as $err) { $msg .= $err . "\n"; } } // Return JSON to client. wp_send_json_error(array('msg' => $msg)); } // map user social fields to wordpress user _gigya_add_to_wp_user_meta($this->{"gigya_user"}, $user_id); $wp_user = get_userdata($user_id); // If we got here, the user is already registered. // But if we have the 'email_not_verified' flag turned on, // we can't auto login, and we need to verify the email first. if (!empty($this->gigya_user['email_not_verified'])) { // Return JSON with login form to client. wp_send_json_success(array('type' => 'form', 'html' => $this->emailVerifyForm())); } // Finally, let's login the user. $this->login($wp_user); }