/** * Creates a WordPress user with the passed in account. * * @param Social_Service_Account $account * @param string $nonce * @return int|bool */ public function create_user($account, $nonce = null) { $username = $account->username(); $username = sanitize_user($username, true); if (!empty($username)) { $user = get_user_by('login', $this->_key . '_' . $username); if ($user === false) { $id = wp_create_user($this->_key . '_' . $username, wp_generate_password(20, false), $this->_key . '.' . $username . '@example.com'); if (is_wp_error($id)) { Social::log('Failed to create/find user with username of :username.', array('username' => $username)); return false; } $role = ''; if (get_option('users_can_register') == '1') { $role = get_option('default_role'); } else { // Set commenter flag update_user_meta($id, 'social_commenter', 'true'); } $user = new WP_User($id); $user->set_role($role); $user->show_admin_bar_front = 'false'; wp_update_user(get_object_vars($user)); } else { $id = $user->ID; } // Set the nonce if ($nonce !== null) { wp_set_current_user($id); update_user_meta($id, 'social_commenter', 'true'); update_user_meta($id, 'social_auth_nonce_' . $nonce, 'true'); } Social::log('Created/found user :username. (#:id)', array('username' => $username, 'id' => $id)); return $id; } Social::log('Failed to create/find user with username of :username.', array('username' => $username)); return false; }