/** * Process email change verification or cancel requests. * * @since 2.1.0 */ function bp_settings_verify_email_change() { if (!bp_is_settings_component()) { return; } if (!bp_is_my_profile()) { return; } $redirect_to = trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug()); // Email change is being verified if (isset($_GET['verify_email_change'])) { $pending_email = bp_get_user_meta(bp_displayed_user_id(), 'pending_email_change', true); // Bail if the hash provided doesn't match the one saved in the database if (urldecode($_GET['verify_email_change']) !== $pending_email['hash']) { return; } $email_changed = wp_update_user(array('ID' => bp_displayed_user_id(), 'user_email' => trim($pending_email['newemail']))); if ($email_changed) { // Delete object cache for displayed user wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp'); // Delete the pending email change key bp_delete_user_meta(bp_displayed_user_id(), 'pending_email_change'); // Post a success message and redirect bp_core_add_message(__('You have successfully verified your new email address.', 'buddypress')); } else { // Unknown error bp_core_add_message(__('There was a problem verifying your new email address. Please try again.', 'buddypress'), 'error'); } bp_core_redirect($redirect_to); die; // Email change is being dismissed } elseif (!empty($_GET['dismiss_email_change'])) { bp_delete_user_meta(bp_displayed_user_id(), 'pending_email_change'); bp_core_add_message(__('You have successfully dismissed your pending email change.', 'buddypress')); bp_core_redirect($redirect_to); die; } }
/** * Remove all friends-related data concerning a given user. * * Removes the following: * * - Friendships of which the user is a member * - Cached friend count for the user * - Notifications of friendship requests sent by the user * * @param int $user_id ID of the user whose friend data is being removed. */ function friends_remove_data($user_id) { do_action('friends_before_remove_data', $user_id); BP_Friends_Friendship::delete_all_for_user($user_id); // Remove usermeta bp_delete_user_meta($user_id, 'total_friend_count'); do_action('friends_remove_data', $user_id); }
/** * Activate a signup, as identified by an activation key. * * @since 1.2.2 * * @param string $key Activation key. * @return int|bool User ID on success, false on failure. */ function bp_core_activate_signup($key) { global $wpdb; $user = false; // Multisite installs have their own activation routine. if (is_multisite()) { $user = wpmu_activate_signup($key); // If there were errors, add a message and redirect. if (!empty($user->errors)) { return $user; } $user_id = $user['user_id']; } else { $signups = BP_Signup::get(array('activation_key' => $key)); if (empty($signups['signups'])) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } $signup = $signups['signups'][0]; if ($signup->active) { if (empty($signup->domain)) { return new WP_Error('already_active', __('The user is already active.', 'buddypress'), $signup); } else { return new WP_Error('already_active', __('The site is already active.', 'buddypress'), $signup); } } // Password is hashed again in wp_insert_user. $password = wp_generate_password(12, false); $user_id = username_exists($signup->user_login); // Create the user. This should only be necessary if BP_SIGNUPS_SKIP_USER_CREATION is true. if (!$user_id) { $user_id = wp_create_user($signup->user_login, $password, $signup->user_email); // Otherwise, update the existing user's status. } elseif ($key === bp_get_user_meta($user_id, 'activation_key', true) || $key === wp_hash($user_id)) { // Change the user's status so they become active. if (!$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id))) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } bp_delete_user_meta($user_id, 'activation_key'); $member = get_userdata($user_id); $member->set_role(get_option('default_role')); $user_already_created = true; } else { $user_already_exists = true; } if (!$user_id) { return new WP_Error('create_user', __('Could not create user', 'buddypress'), $signup); } // Fetch the signup so we have the data later on. $signups = BP_Signup::get(array('activation_key' => $key)); $signup = isset($signups['signups']) && !empty($signups['signups'][0]) ? $signups['signups'][0] : false; // Activate the signup. BP_Signup::validate($key); if (isset($user_already_exists)) { return new WP_Error('user_already_exists', __('That username is already activated.', 'buddypress'), $signup); } // Set up data to pass to the legacy filter. $user = array('user_id' => $user_id, 'password' => $signup->meta['password'], 'meta' => $signup->meta); // Notify the site admin of a new user registration. wp_new_user_notification($user_id); if (isset($user_already_created)) { /** * Fires if the user has already been created. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; } } // Set any profile data. if (bp_is_active('xprofile')) { if (!empty($user['meta']['profile_field_ids'])) { $profile_field_ids = explode(',', $user['meta']['profile_field_ids']); foreach ((array) $profile_field_ids as $field_id) { $current_field = isset($user['meta']["field_{$field_id}"]) ? $user['meta']["field_{$field_id}"] : false; if (!empty($current_field)) { xprofile_set_field_data($field_id, $user_id, $current_field); } // Save the visibility level. $visibility_level = !empty($user['meta']['field_' . $field_id . '_visibility']) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level); } } } // Replace the password automatically generated by WordPress by the one the user chose. if (!empty($user['meta']['password'])) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id)); /** * Make sure to clean the user's cache as we've * directly edited the password without using * wp_update_user(). * * If we can't use wp_update_user() that's because * we already hashed the password at the signup step. */ $uc = wp_cache_get($user_id, 'users'); if (!empty($uc->ID)) { clean_user_cache($uc->ID); } } /** * Fires at the end of the user activation process. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; }
public static function delete_cover_photo() { $old_file_path = get_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', true); if ($old_file_path) { @unlink($old_file_path); bp_delete_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path'); bp_delete_user_meta(bp_loggedin_user_id(), 'profile_cover_photo'); delete_transient('is_cover_photo_uploaded_' . bp_displayed_user_id()); delete_transient('profile_cover_photo_' . bp_displayed_user_id()); } }
/** * Delete activity item(s). * * If you're looking to hook into one action that provides the ID(s) of * the activity/activities deleted, then use: * * add_action( 'bp_activity_deleted_activities', 'my_function' ); * * The action passes one parameter that is a single activity ID or an * array of activity IDs depending on the number deleted. * * If you are deleting an activity comment please use bp_activity_delete_comment(); * * @since BuddyPress (1.0.0) * * @see BP_Activity_Activity::get() For more information on accepted arguments. * @uses wp_parse_args() * @uses bp_activity_adjust_mention_count() * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity} * @uses do_action() To call the 'bp_before_activity_delete' hook. * @uses bp_get_user_meta() * @uses bp_delete_user_meta() * @uses do_action() To call the 'bp_activity_delete' hook. * @uses do_action() To call the 'bp_activity_deleted_activities' hook. * @uses wp_cache_delete() * * @param array $args To delete specific activity items, use * $args = array( 'id' => $ids ); * Otherwise, to use filters for item deletion, the argument format is * the same as BP_Activity_Activity::get(). See that method for a description. * @return bool True on success, false on failure. */ function bp_activity_delete($args = '') { // Pass one or more the of following variables to delete by those variables $args = bp_parse_args($args, array('id' => false, 'action' => false, 'content' => false, 'component' => false, 'type' => false, 'primary_link' => false, 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'date_recorded' => false, 'hide_sitewide' => false)); do_action('bp_before_activity_delete', $args); // Adjust the new mention count of any mentioned member bp_activity_adjust_mention_count($args['id'], 'delete'); $activity_ids_deleted = BP_Activity_Activity::delete($args); if (empty($activity_ids_deleted)) { return false; } // Check if the user's latest update has been deleted $user_id = empty($args['user_id']) ? bp_loggedin_user_id() : $args['user_id']; $latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true); if (!empty($latest_update)) { if (in_array((int) $latest_update['id'], (array) $activity_ids_deleted)) { bp_delete_user_meta($user_id, 'bp_latest_update'); } } do_action('bp_activity_delete', $args); do_action('bp_activity_deleted_activities', $activity_ids_deleted); wp_cache_delete('bp_activity_sitewide_front', 'bp'); return true; }
/** * Remove all friends-related data concerning a given user. * * Removes the following: * * - Friendships of which the user is a member. * - Cached friend count for the user. * - Notifications of friendship requests sent by the user. * * @since 1.0.0 * * @param int $user_id ID of the user whose friend data is being removed. */ function friends_remove_data($user_id) { /** * Fires before deletion of friend-related data for a given user. * * @since 1.5.0 * * @param int $user_id ID for the user whose friend data is being removed. */ do_action('friends_before_remove_data', $user_id); BP_Friends_Friendship::delete_all_for_user($user_id); // Remove usermeta. bp_delete_user_meta($user_id, 'total_friend_count'); /** * Fires after deletion of friend-related data for a given user. * * @since 1.0.0 * * @param int $user_id ID for the user whose friend data is being removed. */ do_action('friends_remove_data', $user_id); }
/** * Deletes usermeta for the user when the user is deleted. * * @package BuddyPress Core * @param $user_id The user id for the user to delete usermeta for * @uses bp_delete_user_meta() deletes a row from the wp_usermeta table based on meta_key */ function bp_core_remove_data($user_id) { // Remove usermeta bp_delete_user_meta($user_id, 'last_activity'); // Flush the cache to remove the user from all cached objects wp_cache_flush(); }
/** * Activate a signup, as identified by an activation key. * * @param string $key Activation key. * @return int|bool User ID on success, false on failure. */ function bp_core_activate_signup($key) { global $wpdb; $user = false; // Multisite installs have their own activation routine. if (is_multisite()) { $user = wpmu_activate_signup($key); // If there were errors, add a message and redirect. if (!empty($user->errors)) { return $user; } $user_id = $user['user_id']; } else { $signups = BP_Signup::get(array('activation_key' => $key)); if (empty($signups['signups'])) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } $signup = $signups['signups'][0]; if ($signup->active) { if (empty($signup->domain)) { return new WP_Error('already_active', __('The user is already active.', 'buddypress'), $signup); } else { return new WP_Error('already_active', __('The site is already active.', 'buddypress'), $signup); } } // Password is hashed again in wp_insert_user. $password = wp_generate_password(12, false); $user_id = username_exists($signup->user_login); // Create the user. if (!$user_id) { $user_id = wp_create_user($signup->user_login, $password, $signup->user_email); // If a user ID is found, this may be a legacy signup, or one // created locally for backward compatibility. Process it. } elseif ($key == wp_hash($user_id)) { // Change the user's status so they become active. if (!$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id))) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } bp_delete_user_meta($user_id, 'activation_key'); $member = get_userdata($user_id); $member->set_role(get_option('default_role')); $user_already_created = true; } else { $user_already_exists = true; } if (!$user_id) { return new WP_Error('create_user', __('Could not create user', 'buddypress'), $signup); } // Fetch the signup so we have the data later on. $signups = BP_Signup::get(array('activation_key' => $key)); $signup = isset($signups['signups']) && !empty($signups['signups'][0]) ? $signups['signups'][0] : false; // Activate the signup. BP_Signup::validate($key); if (isset($user_already_exists)) { return new WP_Error('user_already_exists', __('That username is already activated.', 'buddypress'), $signup); } // Set up data to pass to the legacy filter. $user = array('user_id' => $user_id, 'password' => $signup->meta['password'], 'meta' => $signup->meta); // Notify the site admin of a new user registration. wp_new_user_notification($user_id); if (isset($user_already_created)) { /** * Fires if the user has already been created. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; } } // Set any profile data. if (bp_is_active('xprofile')) { if (!empty($user['meta']['profile_field_ids'])) { $profile_field_ids = explode(',', $user['meta']['profile_field_ids']); foreach ((array) $profile_field_ids as $field_id) { $current_field = isset($user['meta']["field_{$field_id}"]) ? $user['meta']["field_{$field_id}"] : false; if (!empty($current_field)) { xprofile_set_field_data($field_id, $user_id, $current_field); } // Save the visibility level. $visibility_level = !empty($user['meta']['field_' . $field_id . '_visibility']) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level); } } } // Update the display_name. wp_update_user(array('ID' => $user_id, 'display_name' => bp_core_get_user_displayname($user_id))); // Set the password on multisite installs. if (!empty($user['meta']['password'])) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id)); } /** * Fires at the end of the user activation process. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; }
/** * Check the member's latest (activity) update to see if it's the item that was (just) marked as spam. * * This can't be done in BP_Akismet::check_activity() due to BP-Default's AJAX implementation; see bp_dtheme_post_update(). * * @param string $content Activity update text * @param int $user_id User ID * @param int $activity_id Activity ID * @see bp_dtheme_post_update() * @since BuddyPress (1.6) */ public function check_member_activity_update($content, $user_id, $activity_id) { // By default, only handle activity updates and activity comments. if (empty($this->last_activity) || !in_array($this->last_activity->type, BP_Akismet::get_activity_types())) { return; } // Was this $activity_id just marked as spam? If not, bail out. if (!$this->last_activity->id || $activity_id != $this->last_activity->id || 'false' == $this->last_activity->akismet_submission['bp_as_result']) { return; } // It was, so delete the member's latest activity update. bp_delete_user_meta($user_id, 'bp_latest_update'); }
function friends_remove_data($user_id) { global $bp; do_action('friends_before_remove_data', $user_id); BP_Friends_Friendship::delete_all_for_user($user_id); // Remove usermeta bp_delete_user_meta($user_id, 'total_friend_count'); // Remove friendship requests FROM user bp_core_delete_notifications_from_user($user_id, $bp->friends->id, 'friendship_request'); do_action('friends_remove_data', $user_id); }
/** * Delete activity item(s). * * If you're looking to hook into one action that provides the ID(s) of * the activity/activities deleted, then use: * * add_action( 'bp_activity_deleted_activities', 'my_function' ); * * The action passes one parameter that is a single activity ID or an * array of activity IDs depending on the number deleted. * * If you are deleting an activity comment please use bp_activity_delete_comment(); * * @since 1.0.0 * * @see BP_Activity_Activity::get() For more information on accepted arguments. * @uses wp_parse_args() * @uses bp_activity_adjust_mention_count() * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity} * @uses do_action() To call the 'bp_before_activity_delete' hook. * @uses bp_get_user_meta() * @uses bp_delete_user_meta() * @uses do_action() To call the 'bp_activity_delete' hook. * @uses do_action() To call the 'bp_activity_deleted_activities' hook. * @uses wp_cache_delete() * * @param array|string $args To delete specific activity items, use * $args = array( 'id' => $ids ); Otherwise, to use * filters for item deletion, the argument format is * the same as BP_Activity_Activity::get(). * See that method for a description. * @return bool True on success, false on failure. */ function bp_activity_delete($args = '') { // Pass one or more the of following variables to delete by those variables. $args = bp_parse_args($args, array('id' => false, 'action' => false, 'content' => false, 'component' => false, 'type' => false, 'primary_link' => false, 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'date_recorded' => false, 'hide_sitewide' => false)); /** * Fires before an activity item proceeds to be deleted. * * @since 1.5.0 * * @param array $args Array of arguments to be used with the activity deletion. */ do_action('bp_before_activity_delete', $args); // Adjust the new mention count of any mentioned member. bp_activity_adjust_mention_count($args['id'], 'delete'); $activity_ids_deleted = BP_Activity_Activity::delete($args); if (empty($activity_ids_deleted)) { return false; } // Check if the user's latest update has been deleted. $user_id = empty($args['user_id']) ? bp_loggedin_user_id() : $args['user_id']; $latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true); if (!empty($latest_update)) { if (in_array((int) $latest_update['id'], (array) $activity_ids_deleted)) { bp_delete_user_meta($user_id, 'bp_latest_update'); } } /** * Fires after the activity item has been deleted. * * @since 1.0.0 * * @param array $args Array of arguments used with the activity deletion. */ do_action('bp_activity_delete', $args); /** * Fires after the activity item has been deleted. * * @since 1.2.0 * * @param array $activity_ids_deleted Array of affected activity item IDs. */ do_action('bp_activity_deleted_activities', $activity_ids_deleted); wp_cache_delete('bp_activity_sitewide_front', 'bp'); return true; }
function active_user_for_wps($user_id, $user_login, $user_password, $user_email, $usermeta) { global $bp, $wpdb; $user = null; if (defined('DOING_AJAX')) { return $user_id; } if (is_multisite()) { return $user_id; } //do not proceed for mu $signups = BP_Signup::get(array('user_login' => $user_login)); $signups = $signups['signups']; if (!$signups) { return false; } //if we are here, just popout the array $signup = array_pop($signups); // password is hashed again in wp_insert_user $password = wp_generate_password(12, false); $user_id = username_exists($signup->user_login); $key = $signup->activation_key; if (!$key) { $key = bp_get_user_meta($user_id, 'activation_key', true); } // Create the user if (!$user_id) { //this should almost never happen $user_id = wp_create_user($signup->user_login, $password, $signup->user_email); // If a user ID is found, this may be a legacy signup, or one // created locally for backward compatibility. Process it. } elseif ($key == wp_hash($user_id)) { // Change the user's status so they become active if (!$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id))) { return new WP_Error('invalid_key', __('Invalid activation key', 'buddypress')); } bp_delete_user_meta($user_id, 'activation_key'); $member = get_userdata($user_id); $member->set_role(get_option('default_role')); $user_already_created = true; } else { $user_already_exists = true; } if (!$user_id) { return new WP_Error('create_user', __('Could not create user', 'buddypress'), $signup); } // Fetch the signup so we have the data later on $signups = BP_Signup::get(array('activation_key' => $key)); $signup = isset($signups['signups']) && !empty($signups['signups'][0]) ? $signups['signups'][0] : false; // Activate the signup BP_Signup::validate($key); if (isset($user_already_exists)) { return new WP_Error('user_already_exists', __('That username is already activated.', 'buddypress'), $signup); } // Set up data to pass to the legacy filter $user = array('user_id' => $user_id, 'password' => $signup->meta['password'], 'meta' => $signup->meta); // Notify the site admin of a new user registration wp_new_user_notification($user_id); wp_cache_delete('bp_total_member_count', 'bp'); /* Add a last active entry */ bp_update_user_last_activity($user_id); do_action('bp_core_activated_user', $user_id, $key, $user); bp_core_add_message(__('Your account is now active!')); $bp->activation_complete = true; xprofile_sync_wp_profile(); //$ud = get_userdata($signup['user_id']); self::login_redirect($user_login, $user_password); //will never reach here anyway return $user_id; }
function delete_bg_for_user() { //delete the associated image and send a message $old_file_path = get_user_meta(bp_loggedin_user_id(), 'profile_bg_file_path', true); if ($old_file_path) { @unlink($old_file_path); } //remove old files with each new upload bp_delete_user_meta(bp_loggedin_user_id(), 'profile_bg_file_path'); bp_delete_user_meta(bp_loggedin_user_id(), 'profile_bg'); }
function delete_cover_for_user($user_id = null) { if (!$user_id) { $user_id = bp_loggedin_user_id(); } //delete the associated image and send a message $old_file_path = get_user_meta($user_id, 'profile_cover_file_path', true); if ($old_file_path) { @unlink($old_file_path); //remove old files with each new upload } bp_delete_user_meta($user_id, 'profile_cover_file_path'); bp_delete_user_meta($user_id, 'profile_cover'); }