/** * Process data submitted at user registration and convert to a signup object. * * @since 1.2.0 * * @todo There appears to be a bug in the return value on success. * * @param string $user_login Login name requested by the user. * @param string $user_password Password requested by the user. * @param string $user_email Email address entered by the user. * @param array $usermeta Miscellaneous metadata about the user (blog-specific * signup data, xprofile data, etc). * @return bool|WP_Error True on success, WP_Error on failure. */ function bp_core_signup_user($user_login, $user_password, $user_email, $usermeta) { $bp = buddypress(); // We need to cast $user_id to pass to the filters. $user_id = false; // Multisite installs have their own install procedure. if (is_multisite()) { wpmu_signup_user($user_login, $user_email, $usermeta); } else { // Format data. $user_login = preg_replace('/\\s+/', '', sanitize_user($user_login, true)); $user_email = sanitize_email($user_email); $activation_key = wp_generate_password(32, false); /** * WordPress's default behavior is to create user accounts * immediately at registration time. BuddyPress uses a system * borrowed from WordPress Multisite, where signups are stored * separately and accounts are only created at the time of * activation. For backward compatibility with plugins that may * be anticipating WP's default behavior, BP silently creates * accounts for registrations (though it does not use them). If * you know that you are not running any plugins dependent on * these pending accounts, you may want to save a little DB * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION * to true in your wp-config.php file. */ if (!defined('BP_SIGNUPS_SKIP_USER_CREATION') || !BP_SIGNUPS_SKIP_USER_CREATION) { $user_id = BP_Signup::add_backcompat($user_login, $user_password, $user_email, $usermeta); if (is_wp_error($user_id)) { return $user_id; } bp_update_user_meta($user_id, 'activation_key', $activation_key); } $args = array('user_login' => $user_login, 'user_email' => $user_email, 'activation_key' => $activation_key, 'meta' => $usermeta); BP_Signup::add($args); /** * Filters if BuddyPress should send an activation key for a new signup. * * @since 1.2.3 * * @param bool $value Whether or not to send the activation key. * @param int $user_id User ID to send activation key to. * @param string $user_email User email to send activation key to. * @param string $activation_key Activation key to be sent. * @param array $usermeta Miscellaneous metadata about the user (blog-specific * signup data, xprofile data, etc). */ if (apply_filters('bp_core_signup_send_activation_key', true, $user_id, $user_email, $activation_key, $usermeta)) { bp_core_signup_send_validation_email($user_id, $user_email, $activation_key, $user_login); } } $bp->signup->username = $user_login; /** * Fires at the end of the process to sign up a user. * * @since 1.2.2 * * @param bool|WP_Error $user_id True on success, WP_Error on failure. * @param string $user_login Login name requested by the user. * @param string $user_password Password requested by the user. * @param string $user_email Email address requested by the user. * @param array $usermeta Miscellaneous metadata about the user (blog-specific * signup data, xprofile data, etc). */ do_action('bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta); return $user_id; }
/** * Resend an activation email. * * @since 2.0.0 * * @param array $signup_ids Single ID or list of IDs to resend. * @return array */ public static function resend($signup_ids = array()) { if (empty($signup_ids) || !is_array($signup_ids)) { return false; } $to_resend = self::get(array('include' => $signup_ids)); if (!($signups = $to_resend['signups'])) { return false; } $result = array(); /** * Fires before activation emails are resent. * * @since 2.0.0 * * @param array $signup_ids Array of IDs to resend activation emails to. */ do_action('bp_core_signup_before_resend', $signup_ids); foreach ($signups as $signup) { $meta = $signup->meta; $meta['sent_date'] = current_time('mysql', true); $meta['count_sent'] = $signup->count_sent + 1; // Send activation email. if (is_multisite()) { wpmu_signup_user_notification($signup->user_login, $signup->user_email, $signup->activation_key, serialize($meta)); } else { // Check user status before sending email. $user_id = email_exists($signup->user_email); if (!empty($user_id) && 2 != self::check_user_status($user_id)) { // Status is not 2, so user's account has been activated. $result['errors'][$signup->signup_id] = array($signup->user_login, esc_html__('the sign-up has already been activated.', 'buddypress')); // Repair signups table. self::validate($signup->activation_key); continue; // Send the validation email. } else { bp_core_signup_send_validation_email(false, $signup->user_email, $signup->activation_key, $signup->user_login); } } // Update metas. $result['resent'][] = self::update(array('signup_id' => $signup->signup_id, 'meta' => $meta)); } /** * Fires after activation emails are resent. * * @since 2.0.0 * * @param array $signup_ids Array of IDs to resend activation emails to. * @param array $result Updated metadata related to activation emails. */ do_action('bp_core_signup_after_resend', $signup_ids, $result); /** * Filters the result of the metadata for signup activation email resends. * * @since 2.0.0 * * @param array $result Updated metadata related to activation emails. */ return apply_filters('bp_core_signup_resend', $result); }
/** * Resends an activation email * * This sends exactly the same email the registrant originally got, using data pulled from * their registration. In the future I may add a UI for customized emails. * * @package Unconfirmed * @since 1.0 * * @uses wpmu_signup_blog_notification() to notify users who signed up with a blog * @uses wpmu_signup_user_notification() to notify users who signed up without a blog */ function resend_email() { global $wpdb; // Hubba hubba if (isset($_REQUEST['unconfirmed_bulk'])) { check_admin_referer('unconfirmed_bulk_action'); } else { check_admin_referer('unconfirmed_resend_email'); } // Get the user's activation key out of the URL params if (!isset($_REQUEST['unconfirmed_key'])) { $this->record_status('error_nokey'); return; } $resent_counts = get_site_option('unconfirmed_resent_counts'); $keys = $_REQUEST['unconfirmed_key']; foreach ((array) $keys as $key) { if ($this->is_multisite) { $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key)); } else { $user = $this->get_userdata_from_key($key); } if (!$user) { $this->record_status('error_nouser', $key); continue; } if ($this->is_multisite) { // We use a different email function depending on whether they registered with blog if (!empty($user->domain)) { wpmu_signup_blog_notification($user->domain, $user->path, $user->title, $user->user_login, $user->user_email, $user->activation_key, maybe_unserialize($user->meta)); } else { wpmu_signup_user_notification($user->user_login, $user->user_email, $user->activation_key, maybe_unserialize($user->meta)); } } else { // If you're running BP on a non-multisite instance of WP, use the // BP function to send the email if (function_exists('bp_core_signup_send_validation_email')) { bp_core_signup_send_validation_email($user->ID, $user->user_email, $key); } } if (isset($resent_counts[$key])) { $resent_counts[$key] = $resent_counts[$key] + 1; } else { $resent_counts[$key] = 1; } // I can't do a true/false check on whether the email was sent because of // the crappy way that WPMU and BP work together to send these messages // See bp_core_activation_signup_user_notification() $this->record_status('updated_resent', $key); } update_site_option('unconfirmed_resent_counts', $resent_counts); }
function bp_core_signup_user($user_login, $user_password, $user_email, $usermeta) { global $bp, $wpdb; // Multisite installs have their own install procedure if (is_multisite()) { wpmu_signup_user($user_login, $user_email, $usermeta); // On multisite, the user id is not created until the user activates the account // but we need to cast $user_id to pass to the filters $user_id = false; } else { $errors = new WP_Error(); $user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_password, 'display_name' => sanitize_title($user_login), 'user_email' => $user_email)); if (empty($user_id)) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress'), get_option('admin_email'))); return $errors; } // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id)); // Set any profile data if (bp_is_active('xprofile')) { if (!empty($usermeta['profile_field_ids'])) { $profile_field_ids = explode(',', $usermeta['profile_field_ids']); foreach ((array) $profile_field_ids as $field_id) { if (empty($usermeta["field_{$field_id}"])) { continue; } $current_field = $usermeta["field_{$field_id}"]; xprofile_set_field_data($field_id, $user_id, $current_field); } } } } $bp->signup->username = $user_login; /*** * Now generate an activation key and send an email to the user so they can activate their account * and validate their email address. Multisite installs send their own email, so this is only for single blog installs. * * To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false. */ if (apply_filters('bp_core_signup_send_activation_key', true)) { if (!is_multisite()) { $activation_key = wp_hash($user_id); update_user_meta($user_id, 'activation_key', $activation_key); bp_core_signup_send_validation_email($user_id, $user_email, $activation_key); } } do_action('bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta); return $user_id; }
/** * Process data submitted at user registration and convert to a signup object. * * @todo There appears to be a bug in the return value on success. * * @param string $user_login Login name requested by the user. * @param string $user_password Password requested by the user. * @param string $user_email Email address entered by the user. * @param array $usermeta Miscellaneous metadata about the user (blog-specific * signup data, xprofile data, etc). * @return bool|WP_Error True on success, WP_Error on failure. */ function bp_core_signup_user($user_login, $user_password, $user_email, $usermeta) { $bp = buddypress(); // We need to cast $user_id to pass to the filters $user_id = false; // Multisite installs have their own install procedure if (is_multisite()) { wpmu_signup_user($user_login, $user_email, $usermeta); } else { // Format data $user_login = preg_replace('/\\s+/', '', sanitize_user($user_login, true)); $user_email = sanitize_email($user_email); $activation_key = substr(md5(time() . rand() . $user_email), 0, 16); /** * WordPress's default behavior is to create user accounts * immediately at registration time. BuddyPress uses a system * borrowed from WordPress Multisite, where signups are stored * separately and accounts are only created at the time of * activation. For backward compatibility with plugins that may * be anticipating WP's default behavior, BP silently creates * accounts for registrations (though it does not use them). If * you know that you are not running any plugins dependent on * these pending accounts, you may want to save a little DB * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION * to true in your wp-config.php file. */ if (!defined('BP_SIGNUPS_SKIP_USER_CREATION') || !BP_SIGNUPS_SKIP_USER_CREATION) { $user_id = BP_Signup::add_backcompat($user_login, $user_password, $user_email, $usermeta); if (is_wp_error($user_id)) { return $user_id; } $activation_key = wp_hash($user_id); update_user_meta($user_id, 'activation_key', $activation_key); } $args = array('user_login' => $user_login, 'user_email' => $user_email, 'activation_key' => $activation_key, 'meta' => $usermeta); BP_Signup::add($args); if (apply_filters('bp_core_signup_send_activation_key', true, $user_id, $user_email, $activation_key, $usermeta)) { bp_core_signup_send_validation_email($user_id, $user_email, $activation_key); } } $bp->signup->username = $user_login; do_action('bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta); return $user_id; }