/** * 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 }
/** * On the login screen, resends the activation email for a user. * * @since 2.0.0 * * @see bp_core_signup_disable_inactive() */ function bp_members_login_resend_activation_email() { global $error; if (empty($_GET['id']) || empty($_GET['_wpnonce'])) { return; } // Verify nonce. if (!wp_verify_nonce($_GET['_wpnonce'], 'bp-resend-activation')) { die('Security check'); } $signup_id = (int) $_GET['id']; // Resend the activation email. // also updates the 'last sent' and '# of emails sent' values. $resend = BP_Signup::resend(array($signup_id)); // Add feedback message. if (!empty($resend['errors'])) { $error = __('<strong>ERROR</strong>: Your account has already been activated.', 'buddypress'); } else { $error = __('Activation email resent! Please check your inbox or spam folder.', 'buddypress'); } }
/** * @group activate */ public function test_activate_user_accounts_with_blogs() { global $wpdb, $current_site, $base; if (!is_multisite()) { return; } $signups = array(); // Can't trust this first signup :( $signups['testpath1'] = $this->factory->signup->create(array('user_login' => 'testpath1', 'user_email' => '*****@*****.**', 'domain' => '', 'path' => '', 'title' => '', 'activation_key' => 'activationkeyblogone')); $signups['blogtwo'] = $this->factory->signup->create(array('user_login' => 'blogtwo', 'user_email' => '*****@*****.**', 'domain' => $current_site->domain, 'path' => $base . 'blogtwo', 'title' => 'Blog Two', 'activation_key' => 'activationkeyblogtwo')); $signups['blogthree'] = $this->factory->signup->create(array('user_login' => 'blogthree', 'user_email' => '*****@*****.**', 'domain' => '', 'path' => '', 'title' => '', 'activation_key' => 'activationkeyblogthree')); $signups['blogfour'] = $this->factory->signup->create(array('user_login' => 'blogfour', 'user_email' => '*****@*****.**', 'domain' => $current_site->domain, 'path' => $base . 'blogfour', 'title' => 'Blog Four', 'activation_key' => 'activationkeyblogfour')); // Neutralize db errors $suppress = $wpdb->suppress_errors(); $results = BP_Signup::activate($signups); $wpdb->suppress_errors($suppress); $this->assertNotEmpty($results['activated']); $users = array(); foreach ($signups as $login => $signup_id) { $users[$login] = get_user_by('login', $login); } $this->assertEqualSets($results['activated'], wp_list_pluck($users, 'ID')); $blogs = array(); foreach ($users as $path => $user) { // Can't trust this first signup :( if ('testpath1' == $path) { continue; } $blogs[$path] = get_active_blog_for_user($user->ID); } $blogs = array_filter($blogs); $blogs = array_map('basename', wp_list_pluck($blogs, 'path')); $this->assertEqualSets($blogs, array_keys($blogs)); }
public function create_object($args) { return BP_Signup::add($args); }
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); }