/** * Update the status of a user in the database. * * @since 0.1.3 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $user The user. * @param string $pref The column in the wp_users table to update the user's status * in (presumably user_status, spam, or deleted). * @param int $value The new status for the user. * * @return int The initially passed $value. */ function wp_user_profiles_update_user_status($user, $status = 'inactive') { global $wpdb; // Get the user $user = new WP_User($user); // Save the old status for help with transitioning $old_status = $user->user_status; // Update user status accordingly if ('spam' === $status) { $wpdb->update($wpdb->users, array('user_status' => '1', 'spam' => '1'), array('ID' => $user->ID)); } elseif ('ham' === $status) { $wpdb->update($wpdb->users, array('user_status' => '0', 'spam' => '0'), array('ID' => $user->ID)); } elseif ('deleted' === $status) { $wpdb->update($wpdb->users, array('user_status' => '2', 'deleted' => '1'), array('ID' => $user->ID)); } elseif ('undeleted' === $status) { $wpdb->update($wpdb->users, array('user_status' => '0', 'deleted' => '0'), array('ID' => $user->ID)); } elseif ('inactive' === $status) { $wpdb->update($wpdb->users, array('user_status' => '2', 'spam' => '0', 'deleted' => '0'), array('ID' => $user->ID)); } else { $wpdb->update($wpdb->users, array('user_status' => '0', 'spam' => '0', 'deleted' => '0'), array('ID' => $user->ID)); } // Bust the user's cache clean_user_cache($user); // Get the user, again $user = new WP_User($user); // Backpat for multisite if ('spam' === $status) { do_action('make_spam_user', $user->ID); } elseif ('active' === $status) { do_action('make_ham_user', $user->ID); } // Transition a user from one status to another wp_user_profiles_transition_user_status($user->user_status, $old_status, $user); return $user; }
public function setUp() { parent::setUp(); // There's a bug in the multisite tests that causes the // transaction rollback to fail for the first user created, // which busts every other attempt to create users. This is a // hack workaround. global $wpdb; if (is_multisite()) { $user_1 = get_user_by('login', 'user 1'); if ($user_1) { $wpdb->delete($wpdb->users, array('ID' => $user_1->ID)); clean_user_cache($user_1); } } $this->factory = new BBP_UnitTest_Factory(); if (class_exists('BP_UnitTest_Factory')) { $this->bp_factory = new BP_UnitTest_Factory(); } // Our default is ugly permalinks, so reset when needed. global $wp_rewrite; if ($wp_rewrite->permalink_structure) { $this->set_permalink_structure(); } }
/** * Block User * * @return boolean * * @access public * @global wpdb $wpdb */ public function block() { global $wpdb; $response = false; if (current_user_can('edit_users') && $this->getId() != get_current_user_id()) { $status = $this->getSubject()->user_status == 0 ? 1 : 0; if ($wpdb->update($wpdb->users, array('user_status' => $status), array('ID' => $this->getId()))) { $this->getSubject()->user_status = $status; clean_user_cache($this->getSubject()); $response = true; } } return $response; }
/** * Set a custom password after registration. * * @param WP_User $user WordPress user object * @return WP_User */ public static function setInvalidPasswordForUser($user) { if (self::isAmazonOnlyUser($user)) { global $wpdb; $pass = '******'; $wpdb->update('wp_users', array('user_pass' => $pass), array('ID' => $user->ID), array('%s'), array('%d')); clean_user_cache($user); return self::findUserByEmail($user->user_email); } return $user; }
function refresh_user_details( $id ) { $id = (int) $id; if ( !$user = get_userdata( $id ) ) return false; clean_user_cache( $id ); return $id; }
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to an User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since unknown * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; // allow for transaction statement do_action('delete_user', $id); if ('novalue' === $reassign || null === $reassign) { $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $reassign = (int) $reassign; $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); } clean_user_cache($id); // FINALLY, delete user if (!is_multisite()) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->users} WHERE ID = %d", $id)); } else { $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE user_id = {$id} AND meta_key = '{$level_key}'"); } // allow for commit transaction do_action('deleted_user', $id); return true; }
/** * Handles Profile modifications. * * @package s2Member\Profiles * @since 3.5 * * @attaches-to ``add_action('init');`` */ public static function handle_profile_modifications() { global $current_user; // We'll need to update this global object. $user =& $current_user; // Shorter reference to the $current_user object. do_action('ws_plugin__s2member_before_handle_profile_modifications', get_defined_vars()); if (!empty($_POST['ws_plugin__s2member_profile_save']) && is_user_logged_in() && is_object($user) && !empty($user->ID) && ($user_id = $user->ID)) { if (($nonce = $_POST['ws_plugin__s2member_profile_save']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-profile-save')) { $GLOBALS['ws_plugin__s2member_profile_saved'] = TRUE; // Global flag as having been saved/updated successfully. $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); // Clean ``$_POST`` vars. $userdata['ID'] = $user_id; // Needed for database update. if (!empty($_p['ws_plugin__s2member_profile_email'])) { if (is_email($_p['ws_plugin__s2member_profile_email']) && !email_exists($_p['ws_plugin__s2member_profile_email'])) { $userdata['user_email'] = $_p['ws_plugin__s2member_profile_email']; if (strcasecmp($userdata['user_email'], $user->user_email) !== 0) { $email_change = TRUE; } } } if (!empty($_p['ws_plugin__s2member_profile_password1'])) { if ($user->user_login !== 'demo') { // No pass change on demo! $userdata['user_pass'] = $_p['ws_plugin__s2member_profile_password1']; } } if (!empty($_p['ws_plugin__s2member_profile_first_name'])) { $userdata['first_name'] = $_p['ws_plugin__s2member_profile_first_name']; } if (!empty($_p['ws_plugin__s2member_profile_display_name'])) { $userdata['display_name'] = $_p['ws_plugin__s2member_profile_display_name']; } if (!empty($_p['ws_plugin__s2member_profile_last_name'])) { $userdata['last_name'] = $_p['ws_plugin__s2member_profile_last_name']; } wp_update_user(wp_slash($userdata)); // OK. Now send this array for an update. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level('auto-detection', 'profile')) { $fields = array(); // Initialize the array of fields. $_existing_fields = get_user_option('s2member_custom_fields', $user_id); foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (!in_array($field['id'], $fields_applicable) || strpos($field['editable'], 'no') === 0) { if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) { $fields[$field_var] = $_existing_fields[$field_var]; } else { unset($fields[$field_var]); } } else { if ($field['required'] === 'yes' && (!isset($_p['ws_plugin__s2member_profile_' . $field_var]) || !is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && !is_string($_p['ws_plugin__s2member_profile_' . $field_var]) || is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && empty($_p['ws_plugin__s2member_profile_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_' . $field_var]) && !strlen($_p['ws_plugin__s2member_profile_' . $field_var])) || isset($_p['ws_plugin__s2member_profile_' . $field_var]) && c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_' . $field_var]), array($field))) { if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) { $fields[$field_var] = $_existing_fields[$field_var]; } else { unset($fields[$field_var]); } } else { if (isset($_p['ws_plugin__s2member_profile_' . $field_var])) { if ((is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && !empty($_p['ws_plugin__s2member_profile_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_' . $field_var]) && strlen($_p['ws_plugin__s2member_profile_' . $field_var])) && !c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_' . $field_var]), array($field))) { $fields[$field_var] = $_p['ws_plugin__s2member_profile_' . $field_var]; } else { unset($fields[$field_var]); } } else { unset($fields[$field_var]); } } } } if (!empty($fields)) { update_user_option($user_id, 's2member_custom_fields', $fields); } else { // Else delete their Custom Fields? delete_user_option($user_id, 's2member_custom_fields'); } } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_handle_profile_modifications', get_defined_vars()); unset($__refs, $__v); clean_user_cache($user_id); wp_cache_delete($user_id, 'user_meta'); $user = new WP_User($user_id); // Fresh object. if (function_exists('setup_userdata')) { setup_userdata(); } $role = c_ws_plugin__s2member_user_access::user_access_role($user); $level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role); if (!empty($_p['ws_plugin__s2member_profile_opt_in']) && $role && $level >= 0) { c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $user->user_login, !empty($userdata['user_pass']) ? $userdata['user_pass'] : '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, TRUE, $user_id); } else { if ($role && $level >= 0 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in']) { c_ws_plugin__s2member_list_servers::process_list_server_removals($role, $level, $user->user_login, !empty($userdata['user_pass']) ? $userdata['user_pass'] : '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, $user_id); } } $lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url($user); $lwp = !$lwp ? get_page_link($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_welcome_page']) : $lwp; if (empty($_p['ws_plugin__s2member_sc_profile_save'])) { echo '<script type="text/javascript">' . "\n"; echo "if(window.parent && window.parent != window) { window.parent.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.parent.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; }"; echo "else if(window.opener) { window.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.opener.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; window.close(); }"; echo "else { alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; }"; echo '</script>' . "\n"; exit; } } } do_action('ws_plugin__s2member_after_handle_profile_modifications', get_defined_vars()); }
/** * Deletes this user. * * @note In the case of a multisite network installation of WordPress®, * this will simply remove the user from the current blog (e.g. they're NOT actually deleted). * * @param null|integer $reassign_posts_to_user_id Optional. A user ID to which any posts will be reassigned. * If this is NULL (which it is by default), all posts will simply be deleted, along with the user. * * @return boolean|errors TRUE if the user is deleted, else an errors object on failure. * * @throws exception If invalid types are passed through arguments list. * @throws exception If this user does NOT have an ID (e.g. we CANNOT delete them). */ public function delete($reassign_posts_to_user_id = NULL) { $this->check_arg_types(array('null', 'integer:!empty'), func_get_args()); if (!$this->has_id()) { throw $this->©exception($this->method(__FUNCTION__) . '#id_missing', array_merge(get_defined_vars(), array('user' => $this)), $this->__('User has no ID (cannot delete).')); } if ($this->is_super_admin()) { return $this->©error($this->method(__FUNCTION__) . '#super_admin', array_merge(get_defined_vars(), array('user' => $this)), sprintf($this->__('Cannot delete super administrator: `%1$s`.'), $this->username)); } if (!wp_delete_user($this->ID, $reassign_posts_to_user_id)) { return $this->©error($this->method(__FUNCTION__) . '#failure', array_merge(get_defined_vars(), array('user' => $this)), sprintf($this->__('Failed to delete user ID: `%1$s`.'), $this->ID)); } $this->do_action('delete', $this, array_merge(get_defined_vars(), array('user' => $this))); $ID = $this->ID; // Save for use below. $this->ID = 0; // Delete this ID now (force empty ID). $this->wp = NULL; $this->cache = array(); $this->ip = ''; $this->email = ''; $this->username = ''; $this->nicename = ''; $this->password = ''; $this->first_name = ''; $this->last_name = ''; $this->full_name = ''; $this->display_name = ''; $this->url = ''; $this->aim = ''; $this->yim = ''; $this->jabber = ''; $this->description = ''; $this->registration_time = 0; $this->activation_key = ''; $this->status = 0; $this->data = array(); clean_user_cache($ID); wp_cache_delete($ID, 'user_meta'); return TRUE; // Default return value. }
function acui_hack_restore_remapped_email_address($user_id, $email) { global $wpdb; $wpdb->update($wpdb->users, array('user_email' => $hacked_email), array('ID' => $user_id)); clean_user_cache($user_id); }
public static function wpmu_delete_user($id) { global $wpdb; $id = (int) $id; $user = new WP_User($id); if (!$user->exists()) { return false; } /** * Fires before a user is deleted from the network. * * @since MU * * @param int $id ID of the user about to be deleted from the network. */ do_action('wpmu_delete_user', $id); $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); clean_user_cache($user); do_action('deleted_user', $id); return true; }
/** * Handles Profile modifications for Custom Fields *(created with s2Member)*; integrated with BuddyPress. * * @package s2Member\Profiles * @since 3.5 * * @attaches-to ``add_action('xprofile_updated_profile');`` */ public static function handle_profile_modifications_4bp() { global $current_user; // We'll need to update this global object. $user =& $current_user; // Shorter reference to the ``$current_user`` object. do_action('ws_plugin__s2member_before_handle_profile_modifications_4bp', get_defined_vars()); if (!empty($_POST['ws_plugin__s2member_profile_4bp_save']) && is_user_logged_in() && is_object($user) && !empty($user->ID) && ($user_id = $user->ID)) { if (($nonce = $_POST['ws_plugin__s2member_profile_4bp_save']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-profile-4bp-save')) { $GLOBALS['ws_plugin__s2member_profile_4bp_saved'] = TRUE; // Global flag as having been saved/updated successfully. $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); // Clean ``$_POST`` vars. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level('auto-detection', 'profile')) { $fields = array(); // Initialize the array of fields. $_existing_fields = get_user_option('s2member_custom_fields', $user_id); foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (!in_array($field['id'], $fields_applicable) || strpos($field['editable'], 'no') === 0) { if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) { $fields[$field_var] = $_existing_fields[$field_var]; } else { unset($fields[$field_var]); } } else { if ($field['required'] === 'yes' && (!isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || !is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && empty($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !strlen($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) || isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_' . $field_var]), array($field))) { if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) { $fields[$field_var] = $_existing_fields[$field_var]; } else { unset($fields[$field_var]); } } else { if (isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) { if ((is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !empty($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && strlen($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) && !c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_' . $field_var]), array($field))) { $fields[$field_var] = $_p['ws_plugin__s2member_profile_4bp_' . $field_var]; } else { unset($fields[$field_var]); } } else { unset($fields[$field_var]); } } } } if (!empty($fields)) { update_user_option($user_id, 's2member_custom_fields', $fields); } else { // Else delete their Custom Fields? delete_user_option($user_id, 's2member_custom_fields'); } } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_handle_profile_modifications_4bp', get_defined_vars()); unset($__refs, $__v); clean_user_cache($user_id); wp_cache_delete($user_id, 'user_meta'); $user = new WP_User($user_id); // Fresh object. if (function_exists('setup_userdata')) { setup_userdata(); } $role = c_ws_plugin__s2member_user_access::user_access_role($user); $level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role); if (!empty($_p['ws_plugin__s2member_profile_4bp_opt_in']) && $role && $level >= 0) { c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, TRUE, $user_id); } else { if ($role && $level >= 0 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in']) { c_ws_plugin__s2member_list_servers::process_list_server_removals($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, $user_id); } } } } do_action('ws_plugin__s2member_after_handle_profile_modifications_4bp', get_defined_vars()); }
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to an User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; $user = new WP_User($id); // allow for transaction statement do_action('delete_user', $id); if ('novalue' === $reassign || null === $reassign) { $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $reassign = (int) $reassign; $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); } // FINALLY, delete user if (is_multisite()) { remove_user_from_blog($id, get_current_blog_id()); } else { $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); } clean_user_cache($user); // allow for commit transaction do_action('deleted_user', $id); return true; }
function wp_edit_username() { global $wpdb, $user_ID; $new_username = trim($_POST['new_username']); $old_username = trim($_POST['old_username']); if ($new_username && $new_username != $old_username) { if (!validate_username($new_username)) { wp_die("<strong>错误</strong>:用户名只能包含字母、数字、空格、下划线、连字符(-)、点号(.)和 @ 符号。 [ <a href='javascript:onclick=history.go(-1)'>返回</a> ]"); } elseif (username_exists($new_username)) { wp_die(__('<strong>ERROR</strong>: This username is already registered, please choose another one.') . " [ <a href='javascript:onclick=history.go(-1)'>返回</a> ]"); } else { $userid = trim($_POST['user_id']); clean_user_cache($userid); $wpdb->update($wpdb->users, array('user_login' => $new_username, 'user_nicename' => $new_username, 'user_status' => 3), array('ID' => $userid)); if ($user_ID == $userid) { wp_set_auth_cookie($user_ID, true, false); } // 更新缓存 } } }
/** * Process list server removals against current user. * * See {@link process_list_server_removals()} for further details. * * @since 141004 * @package s2Member\List_Servers * * @param bool $opt_out Defaults to `FALSE`; must be set to `TRUE`. * @param bool $clean_user_cache Defaults to `TRUE`; i.e., we start from a fresh copy of the current user. * * @return bool True if at least one list server removal is processed successfully. */ public static function process_list_server_removals_against_current_user($opt_out = FALSE, $clean_user_cache = TRUE) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_process_list_server_removals_against_current_user', get_defined_vars()); unset($__refs, $__v); // Allows vars to be modified by reference. if ($clean_user_cache) { clean_user_cache(get_current_user_id()); wp_cache_delete(get_current_user_id(), 'user_meta'); $user = new WP_User(get_current_user_id()); } else { $user = wp_get_current_user(); } return self::process_list_server_removals($role = c_ws_plugin__s2member_user_access::user_access_role($user), $level = c_ws_plugin__s2member_user_access::user_access_level($user), $login = $user->user_login, $pass = $user->user_pass, $email = $user->user_email, $fname = $user->first_name, $lname = $user->last_name, $ip = @$_SERVER['REMOTE_ADDR'], $opt_out = $opt_out, $user_id = $user->ID); }
function maybe_fix_user_nicename($user_id, $old_user_data = null) { global $wpdb; $user = new WP_User($user_id); $user_login = $user->user_login; $user_nicename = $user->user_nicename; if ($user_nicename != $user_login) { return; } //nothing to fix $user_nicename = sanitize_user($user->display_name, true); //base the slug/nicename on display name $user_nicename = preg_replace('|[ _@]|i', '', $user_nicename); $user_nicename = preg_replace('|[^a-z\\-]|i', '', strtolower($user_nicename)); $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s OR user_login = %s LIMIT 1", $user_nicename, $user_nicename)); if ($user_nicename_check) { $suffix = 2; while ($user_nicename_check) { $alt_user_nicename = $user_nicename . "-{$suffix}"; $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s OR user_login = %s LIMIT 1", $alt_user_nicename, $alt_user_nicename)); $suffix++; } $user_nicename = $alt_user_nicename; } //update the user_nicename $compacted = compact('user_nicename'); $data = wp_unslash($compacted); $ID = (int) $user_id; $wpdb->update($wpdb->users, $data, compact('ID')); clean_user_cache($user_id); }
/** * Handles the importation of Users/Members. * * @package s2Member\Imports * @since 110815 */ public static function import_users() { if (!empty($_POST['ws_plugin__s2member_pro_import_users']) && ($nonce = $_POST['ws_plugin__s2member_pro_import_users']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-pro-import-users') && current_user_can('create_users')) { global $wpdb; // Global database object reference. /** @var \wpdb $wpdb This line for IDEs that need a reference. */ global $current_site, $current_blog; // Multisite Networking. @set_time_limit(0); // Make time for processing large import files. @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); remove_all_actions('profile_update') . remove_all_actions('user_register'); remove_all_actions('added_existing_user') . remove_all_actions('add_user_to_blog'); if (!empty($_FILES['ws_plugin__s2member_pro_import_users_file']) && empty($_FILES['ws_plugin__s2member_pro_import_users_file']['error'])) { $file = fopen($_FILES['ws_plugin__s2member_pro_import_users_file']['tmp_name'], 'r'); } else { if (!empty($_POST['ws_plugin__s2member_pro_import_users_direct_input'])) { fwrite($file = tmpfile(), trim(stripslashes($_POST['ws_plugin__s2member_pro_import_users_direct_input']))) . fseek($file, 0); } } $imported = $line = $line_index = 0; // Initialize these counters. $headers = array(); // Initialize the array of CSV import file headers. $user_keys = array(); // Initialize array of user keys. if (is_object($_user_row = $wpdb->get_row("SELECT * FROM `" . $wpdb->users . "` LIMIT 1"))) { foreach (array_keys((array) $_user_row) as $_user_key) { $user_keys[] = $_user_key; } } unset($_user_row, $_user_key); // Housekeeping. $user_keys = array_unique($user_keys); // Only unique keys please. if (isset($file) && is_resource($file)) { while (($_csv_data = version_compare(PHP_VERSION, '5.3', '>=') ? fgetcsv($file, 0, ',', '"', '"') : fgetcsv($file, 0, ',', '"')) !== FALSE) { $line_index = (int) $line_index + 1; // CSV lines. $line = (int) $line + 1; // CSV lines. $_csv_data = c_ws_plugin__s2member_utils_strings::trim_deep($_csv_data); if ($line_index === 1 && isset($_csv_data[0])) { $line = $line - 1; foreach ($_csv_data as $_header) { $headers[] = $_header; } unset($_header); // Housekeeping. continue; // We've got the headers now; let's move to the next line. } if ($line_index >= 1 && (!$headers || !in_array('ID', $headers, TRUE) && !in_array('user_login', $headers, TRUE))) { $errors[] = 'Line #' . $line . '. Missing first-line CSV headers; please try again.' . ' Please note that your CSV headers MUST contain (at a minimum), one of: "ID", or "user_login"'; break; // Stop here; we have no headers in this importation. } $_user_ID_key = array_search('ID', $headers); $_user_id = $_user_ID_key !== FALSE && !empty($_csv_data[$_user_ID_key]) ? (int) $_csv_data[$_user_ID_key] : 0; unset($_user_ID_key); // Housekeeping. $_user_login_key = array_search('user_login', $headers); $_user_login = $_user_login_key !== FALSE && !empty($_csv_data[$_user_login_key]) ? $_csv_data[$_user_login_key] : ''; unset($_user_login_key); // Housekeeping. $_user_pass_key = array_search('user_pass', $headers); $_user_pass = $_user_pass_key !== FALSE && !empty($_csv_data[$_user_pass_key]) ? $_csv_data[$_user_pass_key] : ''; unset($_user_pass_key); // Housekeeping. $_user_email_key = array_search('user_email', $headers); $_user_email = $_user_email_key !== FALSE && !empty($_csv_data[$_user_email_key]) ? $_csv_data[$_user_email_key] : ''; unset($_user_email_key); // Housekeeping. $_user_role_key = array_search('role', $headers); $_user_role = $_user_role_key !== FALSE && !empty($_csv_data[$_user_role_key]) ? $_csv_data[$_user_role_key] : ''; $_user_role = is_numeric($_user_role) ? $_user_role == 0 ? 'subscriber' : 's2member_level' . $_user_role : $_user_role; unset($_user_role_key); // Housekeeping. $_user_ccaps_key = array_search('ccaps', $headers); $_user_ccaps = $_user_ccaps_key !== FALSE && !empty($_csv_data[$_user_ccaps_key]) ? $_csv_data[$_user_ccaps_key] : ''; unset($_user_ccaps_key); // Housekeeping. if ($_user_login) { if (is_multisite()) { $_user_login = strtolower($_user_login); } $_user_login = sanitize_user($_user_login, is_multisite()); } if ($_user_email) { $_user_email = sanitize_email($_user_email); } $_user_id_exists_but_not_on_blog = 0; // Initialize. if (!$_user_id && $_user_login && $_user_email && is_multisite()) { $_user_id = $_user_id_exists_but_not_on_blog = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($_user_login, $_user_email); } if (strcasecmp($_user_role, 'administrator') === 0) { $errors[] = 'Line #' . $line . '. Users cannot be updated to an Administrator. Bypassing this line for security.'; continue; // Skip this line. } if ($_user_email && !is_email($_user_email)) { $errors[] = 'Line #' . $line . '. Invalid email address (<code>' . esc_html($_user_email) . '</code>); please try again.'; continue; // Skip this line. } if ($_user_login && !validate_username($_user_login)) { $errors[] = 'Line #' . $line . '. Invalid username (<code>' . esc_html($_user_login) . '</code>).'; continue; // Skip this line. } if ($_user_id) { if (!is_object($_user = new WP_User($_user_id)) || !$_user->ID) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> does NOT belong to an existing User.'; continue; // Skip this line. } if (is_super_admin($_user_id) || $_user->has_cap('administrator')) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> belongs to an Administrator. Bypassing this line for security.'; continue; // Skip this line. } if (is_multisite() && $_user_id_exists_but_not_on_blog && add_existing_user_to_blog(array('user_id' => $_user_id, 'role' => 'subscriber')) !== TRUE) { $errors[] = 'Line #' . $line . '. Unknown user/site addition error, please try again.'; continue; // Skip this line. } if (is_multisite() && !is_user_member_of_blog($_user_id)) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> does NOT belong to an existing User on this site.'; continue; // Skip this line. } if ($_user_email && strcasecmp($_user_email, $_user->user_email) !== 0 && email_exists($_user_email)) { $errors[] = 'Line #' . $line . '. Conflicting; the email address (<code>' . esc_html($_user_email) . '</code>), already exists.'; continue; // Skip this line. } if ($_user_login && strcasecmp($_user_login, $_user->user_login) !== 0 && username_exists($_user_login)) { $errors[] = 'Line #' . $line . '. Conflicting; the username (<code>' . esc_html($_user_login) . '</code>), already exists.'; continue; // Skip this line. } /** @var WP_Error $_email_login_validation */ if (is_multisite() && strcasecmp($_user_email, $_user->user_email) !== 0 && strcasecmp($_user_login, $_user->user_login) !== 0) { if (is_wp_error($_email_login_validation = wpmu_validate_user_signup($_user_login, $_user_email))) { if ($_email_login_validation->get_error_code()) { $errors[] = 'Line #' . $line . '. Network. The email and/or username (<code>' . esc_html($_user_email) . '</code> / <code>' . esc_html($_user_login) . '</code>) are in conflict w/ network rules.'; continue; // Skip this line. } } } unset($_email_login_validation); // Housekeeping. $_wp_update_user = array(); foreach ($user_keys as $_user_key) { if (($_user_data_key = array_search($_user_key, $headers)) !== FALSE && isset($_csv_data[$_user_data_key])) { $_wp_update_user[$_user_key] = $_csv_data[$_user_data_key]; } } unset($_user_key, $_user_data_key); // Housekeeping. if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { unset($_wp_update_user['user_login'], $_wp_update_user['user_pass']); } if (!wp_update_user(wp_slash($_wp_update_user))) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> could NOT be updated. Unknown error, please try again.'; continue; // Skip this line. } unset($_wp_update_user); // Housekeeping. clean_user_cache($_user_id); wp_cache_delete($_user_id, 'user_meta'); $_user = new WP_User($_user_id); $imported = $imported + 1; } else { if (!$_user_email) { $errors[] = 'Line #' . $line . '. Missing email address.'; continue; // Skip this line. } if (email_exists($_user_email)) { $errors[] = 'Line #' . $line . '. Conflicting; the email address (<code>' . esc_html($_user_email) . '</code>), already exists.'; continue; // Skip this line. } if (!$_user_login) { $errors[] = 'Line #' . $line . '. Missing user login (i.e., username).'; continue; // Skip this line. } if (username_exists($_user_login)) { $errors[] = 'Line #' . $line . '. Conflicting; the username (<code>' . esc_html($_user_login) . '</code>), already exists.'; continue; // Skip this line. } /** @var WP_Error $_email_login_validation */ if (is_multisite() && is_wp_error($_email_login_validation = wpmu_validate_user_signup($_user_login, $_user_email))) { if ($_email_login_validation->get_error_code()) { $errors[] = 'Line #' . $line . '. Network. The email and/or username (<code>' . esc_html($_user_email) . '</code> / <code>' . esc_html($_user_login) . '</code>) are in conflict w/ network rules.'; continue; // Skip this line. } } unset($_email_login_validation); // Housekeeping. if (!($_user_id = wp_insert_user(wp_slash(array('user_login' => $_user_login, 'user_pass' => $_user_pass ? $_user_pass : wp_generate_password(12, FALSE), 'user_email' => $_user_email)))) || is_wp_error($_user_id)) { $errors[] = 'Line #' . $line . '. Unknown insertion error, please try again.'; continue; // Skip this line. } $_wp_update_user = array('ID' => $_user_id); foreach ($user_keys as $_user_key) { if (($_user_data_key = array_search($_user_key, $headers)) !== FALSE && isset($_csv_data[$_user_data_key])) { $_wp_update_user[$_user_key] = $_csv_data[$_user_data_key]; } } unset($_user_key, $_user_data_key); // Housekeeping. if (!wp_update_user(wp_slash($_wp_update_user))) { $errors[] = 'Line #' . $line . '. Post insertion update failed on User ID# <code>' . esc_html($_user_id) . '</code>. Unknown error, please try again.'; continue; // Skip this line. } unset($_wp_update_user); // Housekeeping. if (is_multisite()) { // New Users on a Multisite Network need this too. update_user_meta($_user_id, 's2member_originating_blog', $current_blog->blog_id); } clean_user_cache($_user_id); wp_cache_delete($_user_id, 'user_meta'); $_user = new WP_User($_user_id); $imported = $imported + 1; } if ($_user_role) { $_user->set_role($_user_role); } if ($_user_ccaps) { foreach ($_user->allcaps as $_cap => $_cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $_cap)) { $_user->remove_cap($_cap); } } unset($_cap, $_cap_enabled); // Housekeeping. if (preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $_user_ccaps))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $_user_ccaps))) as $_ccap) { if (strlen($_ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $_ccap))))) { $_user->add_cap('access_s2member_ccap_' . $_ccap); } } } } $_user_custom_fields = get_user_option('s2member_custom_fields', $_user_id); $_user_custom_fields = is_array($_user_custom_fields) ? $_user_custom_fields : array(); foreach ($headers as $_index => $_header) { if (strpos($_header, 'meta_key__') === 0) { if (isset($_csv_data[$_index])) { $_new_meta_value = $_csv_data[$_index]; $_user_meta_key = substr($_header, strlen('meta_key__')); if ($_user_meta_key === $wpdb->prefix . 'capabilities' && ($_user_role || $_user_ccaps)) { continue; } // Already handled via `role` and `ccaps`. if ($_user_meta_key === $wpdb->prefix . 'capabilities' && stripos($_new_meta_value, 'administrator') !== FALSE) { continue; } // Do not allow this for security purposes. if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { if (strpos($_user_meta_key, $wpdb->prefix) !== 0 && !in_array($_user_meta_key, array('first_name', 'last_name', 'nickname', 'description'), TRUE)) { continue; } } // Child sites may NOT update meta data for other child blogs. switch ($_user_meta_key) { case $wpdb->prefix . 'capabilities': case $wpdb->prefix . 's2member_sp_references': case $wpdb->prefix . 's2member_ipn_signup_vars': case $wpdb->prefix . 's2member_access_cap_times': case $wpdb->prefix . 's2member_paid_registration_times': case $wpdb->prefix . 's2member_file_download_access_arc': case $wpdb->prefix . 's2member_file_download_access_log': if (isset($_new_meta_value[0])) { // This handles JSON-decoding for known array values. if (!is_null($_new_meta_value_decoded = json_decode($_new_meta_value, TRUE))) { $_new_meta_value = maybe_serialize($_new_meta_value_decoded); } } break; } $_existing_meta_row = $wpdb->get_row("SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . esc_sql($_user_id) . "' AND `meta_key` = '" . esc_sql($_user_meta_key) . "' AND `meta_value` = '" . esc_sql($_new_meta_value) . "' LIMIT 1"); if (is_object($_existing_meta_row)) { continue; } // No need to update this; it is still the same value. $_existing_meta_rows = $wpdb->get_results("SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . esc_sql($_user_id) . "' AND `meta_key` = '" . esc_sql($_user_meta_key) . "' LIMIT 2"); if ($_existing_meta_rows && count($_existing_meta_rows) > 1) { continue; } // We don't update multivalue keys. This can cause database corruption via CSV import files. $_existing_meta_row = $_existing_meta_rows ? $_existing_meta_rows[0] : NULL; /** @var object $_existing_meta_row This line is for IDEs; so they don't choke. */ if (is_object($_existing_meta_row) && $_new_meta_value !== $_existing_meta_row->meta_value) { $wpdb->update($wpdb->usermeta, array('meta_value' => $_new_meta_value), array('umeta_id' => $_existing_meta_row->umeta_id)); } else { if (!is_object($_existing_meta_row)) { $wpdb->insert($wpdb->usermeta, array('user_id' => $_user_id, 'meta_key' => $_user_meta_key, 'meta_value' => $_new_meta_value)); } } } } else { if (strpos($_header, 'custom_field_key__') === 0) { if (isset($_csv_data[$_index])) { $_new_custom_field_value = $_csv_data[$_index]; if (!is_null($_new_custom_field_value_decoded = json_decode($_new_custom_field_value, TRUE))) { $_new_custom_field_value = $_new_custom_field_value_decoded; } $_user_custom_field_key = substr($_header, strlen('custom_field_key__')); $_user_custom_fields[$_user_custom_field_key] = $_new_custom_field_value; } } } } update_user_option($_user_id, 's2member_custom_fields', $_user_custom_fields); unset($_user_custom_fields, $_index, $_header); // Housekeeping. unset($_new_meta_value, $_new_meta_value_decoded, $_user_meta_key, $_existing_meta_rows, $_existing_meta_row); unset($_new_custom_field_value, $_new_custom_field_value_decoded, $_user_custom_field_key); } fclose($file); // Close the file resource handle now. unset($_csv_data, $_user, $_user_id, $_user_login, $_user_email); unset($_user_id_exists_but_not_on_blog, $_user_role, $_user_ccaps); } else { $errors[] = 'No data was received. Please try again.'; } // The upload failed, or it was empty. c_ws_plugin__s2member_admin_notices::display_admin_notice('Operation complete. Users/Members imported: <code>' . (int) $imported . '</code>.'); if (!empty($errors)) { // Here is where a detailed error log will be returned to the Site Owner; as a way of clarifying what just happened during importation. c_ws_plugin__s2member_admin_notices::display_admin_notice('<strong>The following errors were encountered during importation:</strong><ul style="font-size:80%; list-style:disc outside; margin-left:25px;"><li>' . implode('</li><li>', $errors) . '</li></ul>', TRUE); } } }
function pmpromc_pmpro_after_change_membership_level($level_id, $user_id) { clean_user_cache($user_id); global $pmpromc_levels; $options = get_option("pmpromc_options"); $all_lists = get_option("pmpromc_all_lists"); //should we add them to any lists? if (!empty($options['level_' . $level_id . '_lists']) && !empty($options['api_key'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list foreach ($options['level_' . $level_id . '_lists'] as $list) { //subscribe them pmpromc_subscribe($list, $list_user); } //unsubscribe them from lists not selected, or all lists from their old level pmpromc_unsubscribeFromLists($user_id, $level_id); } elseif (!empty($options['api_key']) && count($options) > 3) { //now they are a normal user should we add them to any lists? //Case where PMPro is not installed? if (!empty($options['users_lists']) && !empty($options['api_key'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list foreach ($options['users_lists'] as $list) { //subscribe them pmpromc_subscribe($list, $list_user); } //unsubscribe from any list not assigned to users pmpromc_unsubscribeFromLists($user_id, $level_id); } else { //some memberships are on lists. assuming the admin intends this level to be unsubscribed from everything pmpromc_unsubscribeFromLists($user_id, $level_id); } } }
function pmproaw_pmpro_after_change_membership_level($level_id, $user_id) { clean_user_cache($user_id); global $pmproaw_levels; $options = get_option("pmproaw_options"); $all_lists = get_option("pmproaw_all_lists"); //should we add them to any lists? if (!empty($options['level_' . $level_id . '_lists']) && !empty($options['access_key']) && !empty($options['access_secret'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list try { $aweber = new AWeberAPI(PMPROAW_CONSUMER_KEY, PMPROAW_CONSUMER_SECRET); $account = $aweber->getAccount($options['access_key'], $options['access_secret']); foreach ($options['level_' . $level_id . '_lists'] as $list_id) { //echo "<hr />Trying to subscribe to " . $list_id . "..."; //subscribe them $listURL = "/accounts/{$account->id}/lists/{$list_id}"; $list = $account->loadFromUrl($listURL); $subscribers = $list->subscribers; if (!($custom_fields = apply_filters("pmpro_aweber_custom_fields", array(), $list_user))) { $new_subscriber = $subscribers->create(array('email' => $list_user->user_email, 'name' => trim($list_user->first_name . " " . $list_user->last_name))); } else { $new_subscriber = $subscribers->create(array('email' => $list_user->user_email, 'name' => trim($list_user->first_name . " " . $list_user->last_name), 'custom_fields' => $custom_fields)); } } //unsubscribe them from lists not selected foreach ($all_lists as $list) { if (!in_array($list['id'], $options['level_' . $level_id . '_lists'])) { //get list $listURL = "/accounts/{$account->id}/lists/{$list['id']}"; $aw_list = $account->loadFromUrl($listURL); //find subscriber $subscribers = $aw_list->subscribers; $params = array('email' => $list_user->user_email); $found_subscribers = $subscribers->find($params); //unsubscribe foreach ($found_subscribers as $subscriber) { $subscriber->status = 'unsubscribed'; $subscriber->save(); } } } } catch (AWeberAPIException $exc) { //just catching errors so users don't see them } } elseif (!empty($options['access_key']) && !empty($options['access_secret'])) { //now they are a normal user should we add them to any lists? if (!empty($options['users_lists'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list try { $aweber = new AWeberAPI(PMPROAW_CONSUMER_KEY, PMPROAW_CONSUMER_SECRET); $account = $aweber->getAccount($options['access_key'], $options['access_secret']); foreach ($options['users_lists'] as $list) { //subscribe them $listURL = "/accounts/{$account->id}/lists/{$list['id']}"; $list = $account->loadFromUrl($listURL); $subscribers = $list->subscribers; if (!($custom_fields = apply_filters("pmpro_aweber_custom_fields", array(), $list_user))) { $new_subscriber = $subscribers->create(array('email' => $list_user->user_email, 'name' => trim($list_user->first_name . " " . $list_user->last_name))); } else { $new_subscriber = $subscribers->create(array('email' => $list_user->user_email, 'name' => trim($list_user->first_name . " " . $list_user->last_name), 'custom_fields' => $custom_fields)); } } //unsubscribe from any list not assigned to users foreach ($all_lists as $list) { //get list $listURL = "/accounts/{$account->id}/lists/{$list['id']}"; $aw_list = $account->loadFromUrl($listURL); //find subscriber $subscribers = $aw_list->subscribers; $params = array('email' => $list_user->user_email); $found_subscribers = $subscribers->find($params); //unsubscribe foreach ($found_subscribers as $subscriber) { $subscriber->status = 'unsubscribed'; $subscriber->save(); } } } catch (AWeberAPIException $exc) { //just catching errors so users don't see them } } else { //some memberships are on lists. assuming the admin intends this level to be unsubscribed from everything if (is_array($all_lists)) { //get user info $list_user = get_userdata($user_id); //unsubscribe to each list try { $aweber = new AWeberAPI(PMPROAW_CONSUMER_KEY, PMPROAW_CONSUMER_SECRET); $account = $aweber->getAccount($options['access_key'], $options['access_secret']); foreach ($all_lists as $list) { //get list $listURL = "/accounts/{$account->id}/lists/{$list['id']}"; $aw_list = $account->loadFromUrl($listURL); //find subscriber $subscribers = $aw_list->subscribers; $params = array('email' => $list_user->user_email); $found_subscribers = $subscribers->find($params); //unsubscribe foreach ($found_subscribers as $subscriber) { $subscriber->status = 'unsubscribed'; $subscriber->save(); } } } catch (AWeberAPIException $exc) { //just catching errors to hide them from users } } } } }
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to an User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; $user = new WP_User($id); // allow for transaction statement do_action('delete_user', $id); if ('novalue' === $reassign || null === $reassign) { $post_types_to_delete = array(); foreach (get_post_types(array(), 'objects') as $post_type) { if ($post_type->delete_with_user) { $post_types_to_delete[] = $post_type->name; } elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) { $post_types_to_delete[] = $post_type->name; } } $post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id); $post_types_to_delete = implode("', '", $post_types_to_delete); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $reassign = (int) $reassign; $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); } // FINALLY, delete user if (is_multisite()) { remove_user_from_blog($id, get_current_blog_id()); } else { $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); } clean_user_cache($user); // allow for commit transaction do_action('deleted_user', $id); return true; }
/** * @group bp_members_migrate_signups */ public function test_bp_members_migrate_signups_no_activation_key_but_user_status_2() { $u = $this->factory->user->create(); $u_obj = new WP_User($u); // Fake an old-style registration but without an activation key global $wpdb; $wpdb->update($wpdb->users, array('user_status' => '2'), array('ID' => $u), array('%d'), array('%d')); clean_user_cache($u); bp_members_migrate_signups(); // Use email address as a sanity check $found = BP_Signup::get(); $found_email = isset($found['signups'][0]->user_email) ? $found['signups'][0]->user_email : ''; $this->assertSame($u_obj->user_email, $found_email); }
/** * 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; }
/** * Restores a potentially remapped email address. * * The remapping is part of a hack to bypass difficult to bypass WP checks for * email address uniqueness. * * @since 3.0 * * @param int $user_id The id of the user just registered or updated. */ public function hack_restore_remapped_email_address($user_id) { $user = get_user_by('id', $user_id); if (!$user instanceof WP_User) { return; } $email = $user->user_email; if ($email && isset($this->hack_remapped_emails[$email])) { global $wpdb; $wpdb->update($wpdb->users, array('user_email' => $this->hack_remapped_emails[$email]), array('ID' => $user_id)); unset($this->hack_remapped_emails[$email]); clean_user_cache($user_id); } }
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to a User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = null) { global $wpdb; if (!is_numeric($id)) { return false; } $id = (int) $id; $user = new WP_User($id); if (!$user->exists()) { return false; } // Normalize $reassign to null or a user ID. 'novalue' was an older default. if ('novalue' === $reassign) { $reassign = null; } elseif (null !== $reassign) { $reassign = (int) $reassign; } /** * Fires immediately before a user is deleted from the database. * * @since 2.0.0 * * @param int $id ID of the user to delete. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action('delete_user', $id, $reassign); if (null === $reassign) { $post_types_to_delete = array(); foreach (get_post_types(array(), 'objects') as $post_type) { if ($post_type->delete_with_user) { $post_types_to_delete[] = $post_type->name; } elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) { $post_types_to_delete[] = $post_type->name; } } /** * Filter the list of post types to delete with a user. * * @since 3.4.0 * * @param array $post_types_to_delete Post types to delete. * @param int $id User ID. */ $post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id); $post_types_to_delete = implode("', '", $post_types_to_delete); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); if (!empty($post_ids)) { foreach ($post_ids as $post_id) { clean_post_cache($post_id); } } $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); if (!empty($link_ids)) { foreach ($link_ids as $link_id) { clean_bookmark_cache($link_id); } } } // FINALLY, delete user if (is_multisite()) { remove_user_from_blog($id, get_current_blog_id()); } else { $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); } clean_user_cache($user); /** * Fires immediately after a user is deleted from the database. * * @since 2.9.0 * * @param int $id ID of the deleted user. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action('deleted_user', $id, $reassign); return true; }
/** * Create and Display Leaky Paywall Subscribers page * * @since 1.0.0 */ function subscribers_page() { global $blog_id; $settings = get_leaky_paywall_settings(); if (is_multisite_premium() && !is_main_site($blog_id)) { $site = '_' . $blog_id; } else { $site = ''; } $date_format = get_option('date_format'); $jquery_date_format = leaky_paywall_jquery_datepicker_format($date_format); $headings = apply_filters('leaky_paywall_bulk_add_headings', array('username', 'email', 'price', 'expires', 'status', 'level-id', 'subscriber-id')); $mode = 'off' === $settings['test_mode'] ? 'live' : 'test'; $this->display_zeen101_dot_com_leaky_rss_item(); ?> <div class="wrap"> <div id="icon-users" class="icon32"><br/></div> <h2><?php _e('Leaky Paywall Subscribers', 'issuem-leaky-paywall'); ?> </h2> <?php if (!empty($_POST['leaky_paywall_add_subscriber'])) { if (!wp_verify_nonce($_POST['leaky_paywall_add_subscriber'], 'add_new_subscriber')) { echo '<div class="error settings-error" id="setting-error-invalid_nonce"><p><strong>' . __('Unable to verify security token. Subscriber not added. Please try again.', 'issuem-leaky-paywall') . '</strong></p></div>'; } else { // process form data if (!empty($_POST['leaky-paywall-subscriber-email']) && is_email(trim(rawurldecode($_POST['leaky-paywall-subscriber-email']))) && !empty($_POST['leaky-paywall-subscriber-login'])) { $login = trim(rawurldecode($_POST['leaky-paywall-subscriber-login'])); $email = trim(rawurldecode($_POST['leaky-paywall-subscriber-email'])); $payment_gateway = trim(rawurldecode($_POST['leaky-paywall-subscriber-payment-gateway'])); $subscriber_id = trim(rawurldecode($_POST['leaky-paywall-subscriber-id'])); if (empty($_POST['leaky-paywall-subscriber-expires'])) { $expires = 0; } else { $expires = date('Y-m-d 23:59:59', strtotime(trim(urldecode($_POST['leaky-paywall-subscriber-expires'])))); } $meta = array('level_id' => $_POST['leaky-paywall-subscriber-level-id'], 'subscriber_id' => $subscriber_id, 'price' => trim($_POST['leaky-paywall-subscriber-price']), 'description' => __('Manual Addition', 'issuem-leaky-paywall'), 'expires' => $expires, 'payment_gateway' => $payment_gateway, 'payment_status' => $_POST['leaky-paywall-subscriber-status'], 'interval' => 0, 'plan' => '', 'site' => $site); $user_id = leaky_paywall_new_subscriber(NULL, $email, $subscriber_id, $meta, $login); do_action('add_leaky_paywall_subscriber', $user_id); } else { echo '<div class="error settings-error" id="setting-error-missing_email"><p><strong>' . __('You must include a valid email address.', 'issuem-leaky-paywall') . '</strong></p></div>'; } } } else { if (!empty($_POST['leaky_paywall_edit_subscriber'])) { if (!wp_verify_nonce($_POST['leaky_paywall_edit_subscriber'], 'edit_subscriber')) { echo '<div class="error settings-error" id="setting-error-invalid_nonce"><p><strong>' . __('Unable to verify security token. Subscriber not added. Please try again.', 'issuem-leaky-paywall') . '</strong></p></div>'; } else { // process form data if (!empty($_POST['leaky-paywall-subscriber-email']) && is_email(trim(rawurldecode($_POST['leaky-paywall-subscriber-email']))) && !empty($_POST['leaky-paywall-subscriber-original-email']) && is_email(trim(rawurldecode($_POST['leaky-paywall-subscriber-original-email']))) && !empty($_POST['leaky-paywall-subscriber-login']) && !empty($_POST['leaky-paywall-subscriber-original-login'])) { $orig_login = trim(rawurldecode($_POST['leaky-paywall-subscriber-original-login'])); $orig_email = trim(rawurldecode($_POST['leaky-paywall-subscriber-original-email'])); $user = get_user_by('email', $orig_email); if (!empty($user)) { $new_login = trim(rawurldecode($_POST['leaky-paywall-subscriber-login'])); $new_email = trim(rawurldecode($_POST['leaky-paywall-subscriber-email'])); $price = trim($_POST['leaky-paywall-subscriber-price']); $status = $_POST['leaky-paywall-subscriber-status']; $payment_gateway = trim(rawurldecode($_POST['leaky-paywall-subscriber-payment-gateway'])); $subscriber_id = trim(rawurldecode($_POST['leaky-paywall-subscriber-id'])); if (empty($_POST['leaky-paywall-subscriber-expires'])) { $expires = 0; } else { $expires = date('Y-m-d 23:59:59', strtotime(trim(urldecode($_POST['leaky-paywall-subscriber-expires'])))); } if ($price !== get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_price' . $site, true)) { update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_price' . $site, $price); } if ($expires !== get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true)) { update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, $expires); } if ($status !== get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true)) { update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, $status); } if ($payment_gateway !== get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true)) { update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, $payment_gateway); } if ($subscriber_id !== get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true)) { update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, $subscriber_id); } if ($orig_email !== $new_email) { $args = array('ID' => $user->ID); $args['user_email'] = $orig_email === $new_email ? $orig_email : $new_email; $user_id = wp_update_user($args); } if ($orig_login !== $new_login) { global $wpdb; $wpdb->update($wpdb->users, array('user_login' => $new_login), array('ID' => $user->ID), array('%s'), array('%d')); clean_user_cache($user->ID); } update_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, $_POST['leaky-paywall-subscriber-level-id']); do_action('update_leaky_paywall_subscriber', $user->ID); } } else { echo '<div class="error settings-error" id="setting-error-missing_email"><p><strong>' . __('You must include a valid email address.', 'issuem-leaky-paywall') . '</strong></p></div>'; } } } } //Create an instance of our package class... $subscriber_table = new Leaky_Paywall_Subscriber_List_Table(); $pagenum = $subscriber_table->get_pagenum(); //Fetch, prepare, sort, and filter our data... $subscriber_table->prepare_items(); $total_pages = $subscriber_table->get_pagination_arg('total_pages'); if ($pagenum > $total_pages && $total_pages > 0) { wp_redirect(esc_url_raw(add_query_arg('paged', $total_pages))); exit; } ?> <div id="leaky-paywall-subscriber-add-edit"> <?php $email = !empty($_GET['edit']) ? trim(rawurldecode($_GET['edit'])) : ''; $user = get_user_by('email', $email); if (!empty($email) && !empty($user)) { $login = $user->user_login; $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); $subscriber_level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); $payment_status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $price = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_price' . $site, true); $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); if ('0000-00-00 00:00:00' === $expires) { $expires = ''; } else { $expires = mysql2date($date_format, $expires); } ?> <form id="leaky-paywall-susbcriber-edit" name="leaky-paywall-subscriber-edit" method="post"> <div style="display: table"> <p><label for="leaky-paywall-subscriber-login" style="display:table-cell"><?php _e('Username (required)', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-login" class="regular-text" type="text" value="<?php echo $login; ?> " name="leaky-paywall-subscriber-login" /></p><input id="leaky-paywall-subscriber-original-login" type="hidden" value="<?php echo $login; ?> " name="leaky-paywall-subscriber-original-login" /></p> <p><label for="leaky-paywall-subscriber-email" style="display:table-cell"><?php _e('Email Address (required)', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-email" class="regular-text" type="text" value="<?php echo $email; ?> " placeholder="*****@*****.**" name="leaky-paywall-subscriber-email" /></p><input id="leaky-paywall-subscriber-original-email" type="hidden" value="<?php echo $email; ?> " name="leaky-paywall-subscriber-original-email" /></p> <p><label for="leaky-paywall-subscriber-price" style="display:table-cell"><?php _e('Price Paid', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-price" class="regular-text" type="text" value="<?php echo $price; ?> " placeholder="0.00" name="leaky-paywall-subscriber-price" /></p> <p> <label for="leaky-paywall-subscriber-expires" style="display:table-cell"><?php _e('Expires', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-expires" class="regular-text datepicker" type="text" value="<?php echo $expires; ?> " placeholder="<?php echo date_i18n($date_format, time()); ?> "name="leaky-paywall-subscriber-expires" /> <input type="hidden" name="date_format" value="<?php echo $jquery_date_format; ?> " /> </p> <p> <label for="leaky-paywall-subscriber-level-id" style="display:table-cell"><?php _e('Subscription Level', 'issuem-leaky-paywall'); ?> </label> <select name="leaky-paywall-subscriber-level-id"> <?php foreach ($settings['levels'] as $key => $level) { echo '<option value="' . $key . '" ' . selected($key, $subscriber_level_id, true) . '>' . stripslashes($level['label']) . '</option>'; } ?> </select> </p> <p> <label for="leaky-paywall-subscriber-status" style="display:table-cell"><?php _e('Status', 'issuem-leaky-paywall'); ?> </label> <select name="leaky-paywall-subscriber-status"> <option value="active" <?php selected('active', $payment_status); ?> ><?php _e('Active', 'issuem-leaky-paywall'); ?> </option> <option value="canceled" <?php selected('canceled', $payment_status); ?> ><?php _e('Canceled', 'issuem-leaky-paywall'); ?> </option> <option value="deactivated" <?php selected('deactivated', $payment_status); ?> ><?php _e('Deactivated', 'issuem-leaky-paywall'); ?> </option> </select> </p> <p> <label for="leaky-paywall-subscriber-payment-gateway" style="display:table-cell"><?php _e('Payment Method', 'issuem-leaky-paywall'); ?> </label> <?php $payment_gateways = leaky_paywall_payment_gateways(); ?> <select name="leaky-paywall-subscriber-payment-gateway"> <?php foreach ($payment_gateways as $key => $gateway) { echo '<option value="' . $key . '" ' . selected($key, $payment_gateway, false) . '>' . $gateway . '</option>'; } echo apply_filters('leaky_paywall_subscriber_payment_gateway_select_option', ''); ?> </select> </p> <p> <label for="leaky-paywall-subscriber-id" style="display:table-cell"><?php _e('Subscriber ID', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-id" class="regular-text" type="text" value="<?php echo $subscriber_id; ?> " name="leaky-paywall-subscriber-id" /> </p> <?php do_action('update_leaky_paywall_subscriber_form', $user->ID); ?> </div> <?php submit_button('Update Subscriber'); ?> <p> <a href="<?php echo esc_url(remove_query_arg('edit')); ?> "><?php _e('Cancel', 'issuem-leaky-paywall'); ?> </a> </p> <?php wp_nonce_field('edit_subscriber', 'leaky_paywall_edit_subscriber'); ?> </form> <?php } else { ?> <form id="leaky-paywall-susbcriber-add" name="leaky-paywall-subscriber-add" method="post"> <div style="display: table"> <p><label for="leaky-paywall-subscriber-login" style="display:table-cell"><?php _e('Username (required)', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-login" class="regular-text" type="text" value="" name="leaky-paywall-subscriber-login" /></p> <p><label for="leaky-paywall-subscriber-email" style="display:table-cell"><?php _e('Email Address (required)', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-email" class="regular-text" type="text" value="" placeholder="*****@*****.**" name="leaky-paywall-subscriber-email" /></p> <p><label for="leaky-paywall-subscriber-price" style="display:table-cell"><?php _e('Price Paid', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-price" class="regular-text" type="text" value="" placeholder="0.00" name="leaky-paywall-subscriber-price" /></p> <p> <label for="leaky-paywall-subscriber-expires" style="display:table-cell"><?php _e('Expires', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-expires" class="regular-text datepicker" type="text" value="" placeholder="<?php echo date_i18n($date_format, time()); ?> "name="leaky-paywall-subscriber-expires" /> <input type="hidden" name="date_format" value="<?php echo $jquery_date_format; ?> " /> </p> <p> <label for="leaky-paywall-subscriber-level-id" style="display:table-cell"><?php _e('Subscription Level', 'issuem-leaky-paywall'); ?> </label> <select name="leaky-paywall-subscriber-level-id"> <?php foreach ($settings['levels'] as $key => $level) { echo '<option value="' . $key . '">' . stripslashes($level['label']) . '</option>'; } ?> </select> </p> <p> <label for="leaky-paywall-subscriber-status" style="display:table-cell"><?php _e('Status', 'issuem-leaky-paywall'); ?> </label> <select name="leaky-paywall-subscriber-status"> <option value="active"><?php _e('Active', 'issuem-leaky-paywall'); ?> </option> <option value="canceled"><?php _e('Canceled', 'issuem-leaky-paywall'); ?> </option> <option value="deactivated"><?php _e('Deactivated', 'issuem-leaky-paywall'); ?> </option> </select> </p> <p> <label for="leaky-paywall-subscriber-payment-gateway" style="display:table-cell"><?php _e('Payment Method', 'issuem-leaky-paywall'); ?> </label> <select name="leaky-paywall-subscriber-payment-gateway"> <option value="manual"><?php _e('Manual', 'issuem-leaky-paywall'); ?> </option> <option value="stripe"><?php _e('Stripe', 'issuem-leaky-paywall'); ?> </option> <option value="paypal_standard"><?php _e('PayPal', 'issuem-leaky-paywall'); ?> </option> </select> </p> <p> <label for="leaky-paywall-subscriber-id" style="display:table-cell"><?php _e('Subscriber ID', 'issuem-leaky-paywall'); ?> </label><input id="leaky-paywall-subscriber-id" class="regular-text" type="text" value="" name="leaky-paywall-subscriber-id" /> </p> <?php do_action('add_leaky_paywall_subscriber_form'); ?> </div> <?php submit_button('Add New Subscriber'); ?> <?php wp_nonce_field('add_new_subscriber', 'leaky_paywall_add_subscriber'); ?> </form> <?php do_action('leaky_paywall_after_new_subscriber_form'); ?> <?php } ?> <br class="clear"> </div> <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions --> <form id="leaky-paywall-subscribers" method="get"> <!-- For plugins, we also need to ensure that the form posts back to our current page --> <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?> " /> <!-- Now we can render the completed list table --> <div class="tablenav top"> <?php $subscriber_table->user_views(); ?> <?php $subscriber_table->search_box(__('Search Subscribers'), 'issuem-leaky-paywall'); ?> </div> <?php $subscriber_table->display(); ?> </form> </div> <?php }
/** * See {@link process_list_server_removals()} for further details about this wrapper. * * @param bool $opt_out Defaults to false; must be set to true. Indicates the User IS opting out. * @param bool $clean_user_cache Defaults to true; i.e. we start from a fresh copy of the current user. * * @return bool True if at least one List Server removal is processed successfully, else false. */ public static function process_list_server_removals_against_current_user($opt_out = TRUE, $clean_user_cache = TRUE) { if ($clean_user_cache) { clean_user_cache(get_current_user_id()); wp_cache_delete(get_current_user_id(), 'user_meta'); $user = new WP_User(get_current_user_id()); } else { $user = wp_get_current_user(); } return self::process_list_server_removals($role = c_ws_plugin__s2member_user_access::user_access_role($user), $level = c_ws_plugin__s2member_user_access::user_access_level($user), $login = $user->user_login, $pass = $user->user_pass, $email = $user->user_email, $fname = $user->first_name, $lname = $user->last_name, $ip = $_SERVER['REMOTE_ADDR'], $opt_out = $opt_out, $user_id = $user->ID); }
/** * Process a spammed or unspammed user. * * This function is called from three places: * * - in bp_settings_action_capabilities() (from the front-end) * - by bp_core_mark_user_spam_admin() (from wp-admin) * - bp_core_mark_user_ham_admin() (from wp-admin) * * @since 1.6.0 * * @param int $user_id The ID of the user being spammed/hammed. * @param string $status 'spam' if being marked as spam, 'ham' otherwise. * @param bool $do_wp_cleanup True to force the cleanup of WordPress content * and status, otherwise false. Generally, this should * only be false if WordPress is expected to have * performed this cleanup independently, as when hooked * to 'make_spam_user'. * @return bool True on success, false on failure. */ function bp_core_process_spammer_status($user_id, $status, $do_wp_cleanup = true) { global $wpdb; // Bail if no user ID. if (empty($user_id)) { return; } // Bail if user ID is super admin. if (is_super_admin($user_id)) { return; } // Get the functions file. if (is_multisite()) { require_once ABSPATH . 'wp-admin/includes/ms.php'; } $is_spam = 'spam' == $status; // Only you can prevent infinite loops. remove_action('make_spam_user', 'bp_core_mark_user_spam_admin'); remove_action('make_ham_user', 'bp_core_mark_user_ham_admin'); // Force the cleanup of WordPress content and status for multisite configs. if ($do_wp_cleanup) { // Get the blogs for the user. $blogs = get_blogs_of_user($user_id, true); foreach ((array) array_values($blogs) as $details) { // Do not mark the main or current root blog as spam. if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) { continue; } // Update the blog status. update_blog_status($details->userblog_id, 'spam', $is_spam); } // Finally, mark this user as a spammer. if (is_multisite()) { update_user_status($user_id, 'spam', $is_spam); } } // Update the user status. $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id)); // Clean user cache. clean_user_cache($user_id); if (!is_multisite()) { // Call multisite actions in single site mode for good measure. if (true === $is_spam) { /** * Fires at end of processing spammer in Dashboard if not multisite and user is spam. * * @since 1.5.0 * * @param int $value user ID. */ do_action('make_spam_user', $user_id); } else { /** * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. * * @since 1.5.0 * * @param int $value user ID. */ do_action('make_ham_user', $user_id); } } // Hide this user's activity. if (true === $is_spam && bp_is_active('activity')) { bp_activity_hide_user_activity($user_id); } // We need a special hook for is_spam so that components can delete data at spam time. if (true === $is_spam) { /** * Fires at the end of the process spammer process if the user is spam. * * @since 1.5.0 * * @param int $value Displayed user ID. */ do_action('bp_make_spam_user', $user_id); } else { /** * Fires at the end of the process spammer process if the user is not spam. * * @since 1.5.0 * * @param int $value Displayed user ID. */ do_action('bp_make_ham_user', $user_id); } /** * Fires at the end of the process for hanlding spammer status. * * @since 1.5.5 * * @param int $user_id ID of the processed user. * @param bool $is_spam The determined spam status of processed user. */ do_action('bp_core_process_spammer_status', $user_id, $is_spam); // Put things back how we found them. add_action('make_spam_user', 'bp_core_mark_user_spam_admin'); add_action('make_ham_user', 'bp_core_mark_user_ham_admin'); return true; }
function test_changing_email_invalidates_password_reset_key() { global $wpdb; $user = $this->author; $wpdb->update($wpdb->users, array('user_activation_key' => 'key'), array('ID' => $user->ID)); clean_user_cache($user); $user = get_userdata($user->ID); $this->assertEquals('key', $user->user_activation_key); // Check that changing something other than the email doesn't remove the key. $userdata = array('ID' => $user->ID, 'user_nicename' => 'wat'); wp_update_user($userdata); $user = get_userdata($user->ID); $this->assertEquals('key', $user->user_activation_key); // Now check that changing the email does remove it. $userdata = array('ID' => $user->ID, 'user_nicename' => 'cat', 'user_email' => '*****@*****.**'); wp_update_user($userdata); $user = get_userdata($user->ID); $this->assertEmpty($user->user_activation_key); }
function pmproaw_pmpro_after_change_membership_level($level_id, $user_id) { clean_user_cache($user_id); global $pmproaw_levels; $options = get_option("pmproaw_options"); $all_lists = get_option("pmproaw_all_lists"); //should we add them to any lists? if (!empty($options['level_' . $level_id . '_lists']) && !empty($options['access_key']) && !empty($options['access_secret'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list try { foreach ($options['level_' . $level_id . '_lists'] as $list_id) { //echo "<hr />Trying to subscribe to " . $list_id . "..."; pmproaw_subscribe($list_id, $list_user); } foreach ($all_lists as $list) { //Unsubscribe set to "No" if (!$options['unsubscribe']) { return; } //Unsubscribe set to "Yes" if ($options['unsubscribe'] == "all") { if (!in_array($list['id'], $options['level_' . $level_id . '_lists'])) { pmproaw_unsubscribe($list, $list_user); } } else { //get their prevous level lists global $wpdb; if ($level_id) { $last_level = $wpdb->get_results("SELECT* FROM {$wpdb->pmpro_memberships_users} WHERE `user_id` = {$user_id} ORDER BY `id` DESC LIMIT 1,1"); } else { $last_level = $wpdb->get_results("SELECT* FROM {$wpdb->pmpro_memberships_users} WHERE `user_id` = {$user_id} ORDER BY `id` DESC LIMIT 1"); } if ($last_level) { $last_level_id = $last_level[0]->membership_id; if (!empty($options['level_' . $last_level_id . '_lists'])) { $old_level_lists = $options['level_' . $last_level_id . '_lists']; } else { $old_level_lists = array(); } } else { $old_level_lists = array(); } //if we find this list id in thier old level, then unsubscribe if (in_array($list['id'], $old_level_lists)) { pmproaw_unsubscribe($list, $list_user); } } } } catch (AWeberAPIException $exc) { //just catching errors so users don't see them } } elseif (!empty($options['access_key']) && !empty($options['access_secret'])) { //now they are a normal user should we add them to any lists? if (!empty($options['users_lists'])) { //get user info $list_user = get_userdata($user_id); //subscribe to each list try { foreach ($options['users_lists'] as $list) { pmproaw_subscribe($list['id'], $list_user); } //unsubscribe from any list not assigned to users foreach ($all_lists as $list) { pmproaw_unsubscribe($list, $list_user); } } catch (AWeberAPIException $exc) { //just catching errors so users don't see them } } else { //some memberships are on lists. assuming the admin intends this level to be unsubscribed from everything if (is_array($all_lists)) { //get user info $list_user = get_userdata($user_id); //unsubscribe to each list try { foreach ($all_lists as $list) { pmproaw_unsubscribe($list, $list_user); } } catch (AWeberAPIException $exc) { //just catching errors to hide them from users } } } } }
/** * Update metadata of user. * * There is no need to serialize values, they will be serialized if it is * needed. The metadata key can only be a string with underscores. All else will * be removed. * * Will remove the metadata, if the meta value is empty. * * @since 2.0.0 * @deprecated 3.0.0 * @deprecated Use update_user_meta() * @see update_user_meta() * * @param int $user_id User ID * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. * @return bool True on successful update, false on failure. */ function update_usermeta($user_id, $meta_key, $meta_value) { _deprecated_function(__FUNCTION__, '3.0', 'update_user_meta()'); global $wpdb; if (!is_numeric($user_id)) { return false; } $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); /** @todo Might need fix because usermeta data is assumed to be already escaped */ if (is_string($meta_value)) { $meta_value = stripslashes($meta_value); } $meta_value = maybe_serialize($meta_value); if (empty($meta_value)) { return delete_usermeta($user_id, $meta_key); } $cur = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key)); if ($cur) { do_action('update_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value); } if (!$cur) { $wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value')); } else { if ($cur->meta_value != $meta_value) { $wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key')); } else { return false; } } clean_user_cache($user_id); wp_cache_delete($user_id, 'user_meta'); if (!$cur) { do_action('added_usermeta', $wpdb->insert_id, $user_id, $meta_key, $meta_value); } else { do_action('updated_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value); } return true; }
/** * Delete metadata for the specified object. * * @since 2.9.0 * @uses $wpdb WordPress database object for queries. * @uses do_action() Calls 'deleted_{$meta_type}_meta' after deleting with meta_id of * deleted metadata entries, object ID, meta key, and meta value * * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) * @param int $object_id ID of the object metadata is for * @param string $meta_key Metadata key * @param string $meta_value Optional. Metadata value. If specified, only delete metadata entries * with this value. Otherwise, delete all entries with the specified meta_key. * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries * for all objects, ignoring the specified object_id. Otherwise, only delete matching * metadata entries for the specified object_id. * @return bool True on successful delete, false on failure. */ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) { if (!$meta_type || !$meta_key) { return false; } if (!($object_id = absint($object_id)) && !$delete_all) { return false; } if (!($table = _get_meta_table($meta_type))) { return false; } global $wpdb; $type_column = esc_sql($meta_type . '_id'); $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; // expected_slashed ($meta_key) $meta_key = stripslashes($meta_key); $meta_value = stripslashes_deep($meta_value); $check = apply_filters("delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all); if (null !== $check) { return (bool) $check; } $_meta_value = $meta_value; $meta_value = maybe_serialize($meta_value); $query = $wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s", $meta_key); if (!$delete_all) { $query .= $wpdb->prepare(" AND {$type_column} = %d", $object_id); } if ($meta_value) { $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value); } $meta_ids = $wpdb->get_col($query); if (!count($meta_ids)) { return false; } do_action("delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value); $query = "DELETE FROM {$table} WHERE {$id_column} IN( " . implode(',', $meta_ids) . " )"; $count = $wpdb->query($query); if (!$count) { return false; } wp_cache_delete($object_id, $meta_type . '_meta'); // users cache stores usermeta that must be cleared. if ('user' == $meta_type) { clean_user_cache($object_id); } do_action("deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value); return true; }