/** * Set up items for display in the list table. * * Handles filtering of data, sorting, pagination, and any other data * manipulation required prior to rendering. * * @since 2.0.0 */ public function prepare_items() { global $usersearch; $usersearch = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; $signups_per_page = $this->get_items_per_page(str_replace('-', '_', "{$this->screen->id}_per_page")); $paged = $this->get_pagenum(); $args = array('offset' => ($paged - 1) * $signups_per_page, 'number' => $signups_per_page, 'usersearch' => $usersearch, 'orderby' => 'signup_id', 'order' => 'DESC'); if (isset($_REQUEST['orderby'])) { $args['orderby'] = $_REQUEST['orderby']; } if (isset($_REQUEST['order'])) { $args['order'] = $_REQUEST['order']; } $signups = BP_Signup::get($args); $this->items = $signups['signups']; $this->signup_counts = $signups['total']; $this->set_pagination_args(array('total_items' => $this->signup_counts, 'per_page' => $signups_per_page)); }
/** * This is the confirmation screen for actions. * * @since 2.0.0 * * @param string $action Delete, activate, or resend activation link. * * @return string */ public function signups_admin_manage($action = '') { if (!current_user_can($this->capability) || empty($action)) { die('-1'); } // Get the user IDs from the URL. $ids = false; if (!empty($_POST['allsignups'])) { $ids = wp_parse_id_list($_POST['allsignups']); } elseif (!empty($_GET['signup_id'])) { $ids = absint($_GET['signup_id']); } if (empty($ids)) { return false; } // Query for signups, and filter out those IDs that don't // correspond to an actual signup. $signups_query = BP_Signup::get(array('include' => $ids)); $signups = $signups_query['signups']; $signup_ids = wp_list_pluck($signups, 'signup_id'); // Set up strings. switch ($action) { case 'delete': $header_text = __('Delete Pending Accounts', 'buddypress'); if (1 == count($signup_ids)) { $helper_text = __('You are about to delete the following account:', 'buddypress'); } else { $helper_text = __('You are about to delete the following accounts:', 'buddypress'); } break; case 'activate': $header_text = __('Activate Pending Accounts', 'buddypress'); if (1 == count($signup_ids)) { $helper_text = __('You are about to activate the following account:', 'buddypress'); } else { $helper_text = __('You are about to activate the following accounts:', 'buddypress'); } break; case 'resend': $header_text = __('Resend Activation Emails', 'buddypress'); if (1 == count($signup_ids)) { $helper_text = __('You are about to resend an activation email to the following account:', 'buddypress'); } else { $helper_text = __('You are about to resend an activation email to the following accounts:', 'buddypress'); } break; } // These arguments are added to all URLs. $url_args = array('page' => 'bp-signups'); // These arguments are only added when performing an action. $action_args = array('action' => 'do_' . $action, 'signup_ids' => implode(',', $signup_ids)); if (is_network_admin()) { $base_url = network_admin_url('users.php'); } else { $base_url = bp_get_admin_url('users.php'); } $cancel_url = add_query_arg($url_args, $base_url); $action_url = wp_nonce_url(add_query_arg(array_merge($url_args, $action_args), $base_url), 'signups_' . $action); ?> <div class="wrap"> <h1><?php echo esc_html($header_text); ?> </h1> <p><?php echo esc_html($helper_text); ?> </p> <ol class="bp-signups-list"> <?php foreach ($signups as $signup) { $last_notified = mysql2date('Y/m/d g:i:s a', $signup->date_sent); ?> <li> <?php echo esc_html($signup->user_name); ?> - <?php echo sanitize_email($signup->user_email); ?> <?php if ('resend' == $action) { ?> <p class="description"> <?php printf(esc_html__('Last notified: %s', 'buddypress'), $last_notified); ?> <?php if (!empty($signup->recently_sent)) { ?> <span class="attention wp-ui-text-notification"> <?php esc_html_e('(less than 24 hours ago)', 'buddypress'); ?> </span> <?php } ?> </p> <?php } ?> </li> <?php } ?> </ol> <?php if ('delete' === $action) { ?> <p><strong><?php esc_html_e('This action cannot be undone.', 'buddypress'); ?> </strong></p> <?php } ?> <a class="button-primary" href="<?php echo esc_url($action_url); ?> "><?php esc_html_e('Confirm', 'buddypress'); ?> </a> <a class="button" href="<?php echo esc_url($cancel_url); ?> "><?php esc_html_e('Cancel', 'buddypress'); ?> </a> </div> <?php }
/** * Display a "resend email" link when an unregistered user attempts to log in. * * @since 1.2.2 * * @param WP_User|WP_Error|null $user Either the WP_User or the WP_Error object. * @param string $username The inputted, attempted username. * @param string $password The inputted, attempted password. * @return WP_User|WP_Error */ function bp_core_signup_disable_inactive($user = null, $username = '', $password = '') { // Login form not used. if (empty($username) && empty($password)) { return $user; } // An existing WP_User with a user_status of 2 is either a legacy // signup, or is a user created for backward compatibility. See // {@link bp_core_signup_user()} for more details. if (is_a($user, 'WP_User') && 2 == $user->user_status) { $user_login = $user->user_login; // If no WP_User is found corresponding to the username, this // is a potential signup. } elseif (is_wp_error($user) && 'invalid_username' == $user->get_error_code()) { $user_login = $username; // This is an activated user, so bail. } else { return $user; } // Look for the unactivated signup corresponding to the login name. $signup = BP_Signup::get(array('user_login' => sanitize_user($user_login))); // No signup or more than one, something is wrong. Let's bail. if (empty($signup['signups'][0]) || $signup['total'] > 1) { return $user; } // Unactivated user account found! // Set up the feedback message. $signup_id = $signup['signups'][0]->signup_id; $resend_url_params = array('action' => 'bp-resend-activation', 'id' => $signup_id); $resend_url = wp_nonce_url(add_query_arg($resend_url_params, wp_login_url()), 'bp-resend-activation'); $resend_string = '<br /><br />' . sprintf(__('If you have not received an email yet, <a href="%s">click here to resend it</a>.', 'buddypress'), esc_url($resend_url)); return new WP_Error('bp_account_not_activated', __('<strong>ERROR</strong>: Your account has not been activated. Check your email for the activation link.', 'buddypress') . $resend_string); }
/** * @group get */ public function test_get_with_user_login() { $s1 = $this->factory->signup->create(array('user_login' => 'aaaafoo')); $s2 = $this->factory->signup->create(array('user_login' => 'zzzzfoo')); $s3 = $this->factory->signup->create(array('user_login' => 'jjjjfoo')); $ss = BP_Signup::get(array('user_login' => 'zzzzfoo')); $this->assertEquals(array($s2), wp_list_pluck($ss['signups'], 'signup_id')); }
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; }
/** * @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); }