public function unlink() { if (!$this->user) { return new WP_Error('no-user-set'); } if (!get_user_meta($this->user->ID, '_fb_uid', true)) { return true; } delete_user_meta($this->user->ID, '_fb_uid'); delete_user_meta($this->user->ID, '_fb_access_token'); $this->avatar_option->remove_local_avatar(); hm_success_message('Successfully unlinked Facebook from your account.', 'update-user'); return $this->logout('http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]); }
/** * Update a users information * * Can take a variety of arguments all in the form of a userinfo array. * * You can pass any of the default WordPress user fields, you can also pass * an avatar to upload or an image url to use as an avatar. * You can also pass any amount of additonal fields which will be added to the * 'profile_info' user meta. * * This function does not do any stripping or sanitizing, all that should be done before the data gets here. * * @param: (array) of user information * @return: (mixed) user_id on success, WP_Error on failure **/ function hma_update_user_info($info) { // If an email was passed, check that it is valid if (!empty($info['user_email']) && !is_email($info['user_email'])) { hm_error_message('Please enter a valid email address', 'update-user'); return new WP_Error('invalid-email', 'Please enter a valid email address'); } // If an ID wasn't passed then use the current user if (empty($info['ID'])) { $info['ID'] = get_current_user_id(); } if (empty($info['ID'])) { hm_error_message('Invalid user.', 'update-user'); return new WP_Error('invalid-user', 'Empty user ID'); } // Prepare the array for wp_update_user $userdata['ID'] = $info['ID']; if (isset($info['user_email'])) { $userdata['user_email'] = $info['user_email']; } if (isset($info['display_name'])) { $userdata['display_name'] = $info['display_name']; } if (isset($info['first_name'])) { $userdata['first_name'] = $info['first_name']; } if (isset($info['last_name'])) { $userdata['last_name'] = $info['last_name']; } if (isset($info['nickname'])) { $userdata['nickname'] = $info['nickname']; } if (isset($info['description'])) { $userdata['description'] = $info['description']; } if (isset($info['user_pass'])) { $userdata['user_pass'] = $info['user_pass']; } if (isset($info['user_url'])) { $userdata['user_url'] = $info['user_url']; } $user_id = wp_update_user($userdata); // User avatar if (!empty($info['user_avatar'])) { require_once ABSPATH . 'wp-admin/includes/admin.php'; $file = wp_handle_upload($info['user_avatar'], array('test_form' => false)); $info['user_avatar_path'] = str_replace(ABSPATH, '', $file['file']); $info['user_avatar_option'] = 'uploaded'; unset($info['user_avatar']); } $meta_info = array_diff_key($info, $userdata); // Unset some important fields unset($meta_info['user_pass']); unset($meta_info['user_pass2']); unset($meta_info['user_login']); // Anything left gets added to user meta as separate fields if (!empty($meta_info)) { foreach ((array) $meta_info as $key => $value) { update_user_meta($user_id, $key, $value); } } if ($user_id) { hm_success_message('Information successfully updated', 'update-user'); } return $user_id; }
public function unlink() { if (!$this->user->ID) { return new WP_Error('user-not-logged-in'); } delete_user_meta($this->user->ID, '_twitter_uid'); delete_user_meta($this->user->ID, '_twitter_access_token'); delete_user_meta($this->user->ID, '_twitter_oauth_token'); delete_user_meta($this->user->ID, '_twitter_oauth_token_secret'); delete_user_meta($this->user->ID, '_twitter_data'); delete_user_meta($this->user->ID, 'twitter_username'); if (!$this->usingSession) { setcookie('twitter_oauth_token', '', time() - 100, COOKIEPATH); setcookie('twitter_oauth_token_secret', '', time() - 100, COOKIEPATH); } $this->avatar_option->remove_local_avatar(); setcookie('twitter_anywhere_identity', '', time() - 100, COOKIEPATH); hm_success_message('Successfully unlinked Twitter from your account.', 'update-user'); return true; }