function psu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta) { $activated = wpmu_activate_signup($key); if (is_array($activated) && $activated['blog_id'] && $activated['user_id']) { // successfully created blog update_blog_option($activated['blog_id'], 'stylesheet', 'pressrow'); update_blog_option($activated['blog_id'], 'template', 'pressrow'); // they're already CAS authenticated, // so set the WP authentication cookie for them wp_set_auth_cookie($activated['user_id']); ?> <h2>Yay! We made a blog for you</h2> <p>Click this link to access your dashboard:</p> <ul><li><a href="http://<?php echo $domain . $path; ?> wp-admin/"><?php echo $domain . $path; ?> wp-admin/</a></li></ul> <p>Go ahead and bookmark it once you get there, we hope you come back.</p><?php } else { // error will robinson ?> <h2>hrrm...</h2> <p>There seems to have been an error.</p> <p>You may already have a blog at this address: <a href="http://<?php echo $domain . $path; ?> " target="_blank"><?php echo $domain . $path; ?> </a>.</p> <p>Please call the <a href="http://url.path.to/your/helpdesk" target="_blank">Help Desk</a> with the following:</p> <p><pre><?php print_r($activated->errors); ?> </pre></p><?php } return FALSE; }
function aiowps_login_init() { if (strpos($_SERVER['REQUEST_URI'], 'wp-login') !== false) { $referer = wp_get_referer(); if ($referer && strpos($referer, 'wp-activate.php') !== false) { $parsed_referer = parse_url($referer); if ($parsed_referer && !empty($parsed_referer['query'])) { parse_str($parsed_referer['query'], $referer); if (!empty($parsed_referer['key'])) { $result = wpmu_activate_signup($parsed_referer['key']); //MS site creation if ($result && is_wp_error($result) && ($result->get_error_code() === 'already_active' || $result->get_error_code() === 'blog_taken')) { $aiowps_new_login_url = AIOWPSecurity_Process_Renamed_Login_Page::new_login_url(); wp_safe_redirect($aiowps_new_login_url . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')); die; } } } } AIOWPSecurity_Process_Renamed_Login_Page::aiowps_set_404(); } }
/** * Activates a user if it is necessary * * @wp-hook uf_activation * @return void */ function uf_perform_activation() { if (!isset($_POST['user_key'])) { wp_safe_redirect(home_url('/user-activation/?message=keynotvalid')); exit; } else { $key = $_POST['user_key']; $result = wpmu_activate_signup($key); if (is_wp_error($result)) { wp_safe_redirect(home_url('/user-activation/?message=keynotvalid')); exit; } else { $user = get_userdata($result['user_id']); $username = $user->user_login; $password = $result['password']; // set credentials $credentials = array('user_login' => $username, 'user_password' => $password); // signon user $user = wp_signon($credentials); wp_safe_redirect(home_url('/user-profile/?message=activated')); exit; } } }
/** * 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; }
/** * Creates user without email confirmation. * * @access public */ public function custom_createuser() { global $wpdb; check_admin_referer('create-user', '_wpnonce_create-user'); if (!current_user_can('create_users')) { wp_die(__('Cheatin’ uh?')); } if (!is_multisite()) { $user_id = edit_user(); if (is_wp_error($user_id)) { $add_user_errors = $user_id; } else { if (current_user_can('list_users')) { $redirect = 'users.php?update=add&id=' . $user_id; } else { $redirect = add_query_arg('update', 'add', 'user-new.php'); } wp_redirect($redirect); die; } } else { /* Check if user already exists in the network */ $user_details = get_user_by('login', $_REQUEST['user_login']); if (!$user_details) { // Adding a new user to this site $user_details = wpmu_validate_user_signup($_REQUEST['user_login'], $_REQUEST['email']); if (is_wp_error($user_details['errors']) && !empty($user_details['errors']->errors)) { $add_user_errors = $user_details['errors']; } else { $new_user_login = apply_filters('pre_user_login', sanitize_user(wp_unslash($_REQUEST['user_login']), true)); add_filter('wpmu_signup_user_notification', '__return_false'); // Disable confirmation email wpmu_signup_user($new_user_login, $_REQUEST['email'], array('add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'])); $key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST['email'])); wpmu_activate_signup($key); $redirect = add_query_arg(array('update' => 'addnoconfirmation'), 'user-new.php'); wp_redirect($redirect); die; } } else { //Add existing user to the blog. $new_user_email = $user_details->user_email; $redirect = 'user-new.php'; $username = $user_details->user_login; $user_id = $user_details->ID; add_existing_user_to_blog(array('user_id' => $user_id, 'role' => $_REQUEST['role'])); $redirect = add_query_arg(array('update' => 'addnoconfirmation'), 'user-new.php'); wp_redirect($redirect); die; } } }
function bp_core_activate_signup($key) { global $bp, $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']; // 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); } } } } } else { // Get the user_id based on the $key $user_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND meta_value = %s", $key)); if (empty($user_id)) { return new WP_Error('invalid_key', __('Invalid activation key', 'buddypress')); } // 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')); } // Notify the site admin of a new user registration wp_new_user_notification($user_id); // Remove the activation key meta delete_user_meta($user_id, 'activation_key'); } // Update the display_name wp_update_user(array('ID' => $user_id, 'display_name' => bp_core_get_user_displayname($user_id))); // Set the password on multisite installs if (is_multisite() && !empty($user['meta']['password'])) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id)); } // Delete the total member cache wp_cache_delete('bp_total_member_count', 'bp'); do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; }
/** * Activates a user * * Depending on the result, the admin will be redirected back to the main Unconfirmed panel, * with additional URL params that explain success/failure. * * @package Unconfirmed * @since 1.0 * * @uses wpmu_activate_signup() WP's core function for user activation on Multisite */ function activate_user() { global $wpdb; // Did you mean to do this? HMMM??? if (isset($_REQUEST['unconfirmed_bulk'])) { check_admin_referer('unconfirmed_bulk_action'); } else { check_admin_referer('unconfirmed_activate_user'); } // Get the activation key(s) out of the URL params if (!isset($_REQUEST['unconfirmed_key'])) { $this->record_status('error_nokey'); return; } $keys = $_REQUEST['unconfirmed_key']; foreach ((array) $keys as $key) { if ($this->is_multisite) { $result = wpmu_activate_signup($key); $user_id = !is_wp_error($result) && isset($result['user_id']) ? $result['user_id'] : 0; } else { $user = $this->get_userdata_from_key($key); if (empty($user->ID)) { $this->record_status('error_nouser'); return; } else { $user_id = $user->ID; } if (empty($user_id)) { return new WP_Error('invalid_key', __('Invalid activation key', 'unconfirmed')); } // Change the user's status so they become active if (!($result = $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', 'unconfirmed')); } } if (is_wp_error($result)) { $this->record_status('error_couldntactivate', $key); } else { do_action('unconfirmed_user_activated', $user_id, $key); $this->record_status('updated_activated', $key); } } }
* * @since 2.0.3 * * @param string $user_login The sanitized username. */ $new_user_login = apply_filters('pre_user_login', sanitize_user(wp_unslash($_REQUEST['user_login']), true)); if (isset($_POST['noconfirmation']) && current_user_can('manage_network_users')) { add_filter('wpmu_signup_user_notification', '__return_false'); // Disable confirmation email add_filter('wpmu_welcome_user_notification', '__return_false'); // Disable welcome email } wpmu_signup_user($new_user_login, $new_user_email, array('add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'])); if (isset($_POST['noconfirmation']) && current_user_can('manage_network_users')) { $key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email)); $new_user = wpmu_activate_signup($key); if (is_wp_error($new_user)) { $redirect = add_query_arg(array('update' => 'addnoconfirmation'), 'user-new.php'); } else { $redirect = add_query_arg(array('update' => 'addnoconfirmation', 'user_id' => $new_user['user_id']), 'user-new.php'); } } else { $redirect = add_query_arg(array('update' => 'newuserconfirmation'), 'user-new.php'); } wp_redirect($redirect); die; } } } $title = __('Add New User'); $parent_file = 'users.php';
public function signup_form_shortcode($atts, $content = NULL, $tag = '') { global $current_site; if (!is_multisite()) { return $content; } if (is_page()) { $this->signup_form_page = get_page_link(); // add_filter( 'wpmu_signup_user_notification_email', array( $this, 'wpmu_signup_user_notification_email' ), 10, 5 ); add_filter('site_url', array($this, 'site_url'), 10, 4); } $args = shortcode_atts(array('class' => 'member-signup', 'title' => sprintf(__('Get your own %s account in seconds'), $current_site->site_name), 'title_wrap' => 'h3', 'field_wrap' => 'div', 'field_wrap_class' => 'member-signup-field', 'logged_in_redirect' => false, 'logged_in_text' => __('You are logged in already. No need to register again!'), 'disabled_redirect' => false, 'disabled_text' => __('Registration has been disabled.')), $atts, $tag); $labels = apply_filters('gmember_signup_form_labels', array('user_name' => __('Username:'******'user_email' => __('Email Address:'), 'user_pass' => __('Password:'******'submit' => __('Submit')), $args); $descriptions = apply_filters('gmember_signup_form_descriptions', array('user_name' => __('(Must be at least 4 characters, letters and numbers only.)'), 'user_email' => __('We send your registration email to this address. (Double-check your email address before continuing.)')), $args); if (isset($_GET['key']) || isset($_POST['key'])) { $key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key']; $current = wpmu_activate_signup($key); if (is_wp_error($current)) { if ('already_active' == $current->get_error_code() || 'blog_taken' == $current->get_error_code()) { $signup = $current->get_error_data(); $activate = gPluginHTML::tag($args['title_wrap'], array('class' => 'member-signup-title member-signup-activate-title'), __('Your account is now active!')); $activate .= gPluginHTML::tag('p', array('class' => 'lead-in member-signup-activate-text'), '' == $signup->domain . $signup->path ? sprintf(__('Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.'), network_site_url('wp-login.php', 'login'), $signup->user_login, $signup->user_email, wp_lostpassword_url()) : sprintf(__('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, wp_lostpassword_url())); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class'] . ' member-signup-activate'), $activate); } else { $activate = gPluginHTML::tag($args['title_wrap'], array('class' => 'member-signup-title member-signup-activate-title member-signup-activate-error-title'), __('An error occurred during the activation')); $activate .= gPluginHTML::tag('p', array('class' => 'member-signup-activate-error-text'), $current->get_error_message()); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class'] . ' member-signup-activate-error'), $activate); } } else { $user = get_userdata((int) $current['user_id']); $activate = gPluginHTML::tag($args['title_wrap'], array('class' => 'member-signup-title member-signup-activate-title'), __('Your account is now active!')); $welcome = '<p>' . gPluginHTML::tag('span', array('class' => 'h3'), $labels['user_name']); $welcome .= gPluginHTML::tag('span', array(), $user->user_login) . '</p>'; $welcome .= '<p>' . gPluginHTML::tag('span', array('class' => 'h3'), $labels['user_pass']); $welcome .= gPluginHTML::tag('span', array(), $current['password']) . '</p>'; $activate .= gPluginHTML::tag('div', array('id' => 'signup-welcome', 'class' => 'member-signup-activate-welcome'), $welcome); $url = get_blogaddress_by_id((int) $current['blog_id']); $activate .= gPluginHTML::tag('p', array('class' => 'view member-signup-activate-text'), $url != network_home_url('', 'http') ? sprintf(__('Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>'), $url, $url . 'wp-login.php') : sprintf(__('Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.'), network_site_url('wp-login.php', 'login'), network_home_url())); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class'] . ' member-signup-activate'), $activate); } } if (is_user_logged_in()) { if ($args['logged_in_redirect']) { wp_redirect($args['logged_in_redirect']); die; } else { $logged_in = gPluginHTML::tag('p', array('class' => 'member-signup-logged-in'), $args['logged_in_text']); return gPluginHTML::tag('div', array('class' => $args['class']), $logged_in); } } $active_signup = apply_filters('wpmu_active_signup', get_site_option('registration', 'all')); // return "all", "none", "blog" or "user" if ($active_signup == 'none') { if ($args['disabled_redirect']) { wp_redirect($args['disabled_redirect']); die; } else { $disabled = gPluginHTML::tag('p', array('class' => 'member-signup-disabled'), $args['logged_disabled']); return gPluginHTML::tag('div', array('class' => $args['class']), $disabled); } } $current = array('stage' => isset($_POST['stage']) ? $_POST['stage'] : 'default', 'user_name' => isset($_POST['user_name']) ? $_POST['user_name'] : '', 'user_email' => isset($_POST['user_email']) ? $_POST['user_email'] : '', 'errors' => new WP_Error()); switch ($current['stage']) { case 'validate-user-signup': // removed beacause: the filter not checked wp nounce if its not on wp-signup.php and wp_die is not acceptable! remove_filter('wpmu_validate_user_signup', 'signup_nonce_check'); if (wp_create_nonce('member_signup_form_' . $_POST['member_signup_form_id']) != $_POST['_member_signup_form']) { $error = gPluginHTML::tag('p', array('class' => 'member-signup-error'), __('Please try again.')); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class']), $error); } $current = array_merge($current, wpmu_validate_user_signup($current['user_name'], $current['user_email'])); //$result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors); if (!$current['errors']->get_error_code()) { wpmu_signup_user($current['user_name'], $current['user_email'], apply_filters('add_signup_meta', array())); $confirm = gPluginHTML::tag($args['title_wrap'], array('class' => 'member-signup-title member-signup-title-confirm'), sprintf(__('%s is your new username'), $current['user_name'])); $confirm .= gPluginHTML::tag('p', array(), __('But, before you can start using your new username, <strong>you must activate it</strong>.')); $confirm .= gPluginHTML::tag('p', array(), sprintf(__('Check your inbox at <strong>%s</strong> and click the link given.'), $current['user_email'])); $confirm .= gPluginHTML::tag('p', array(), __('If you do not activate your username within two days, you will have to sign up again.')); ob_start(); do_action('signup_finished'); $confirm .= ob_get_clean(); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class'] . ' member-signup-confirm'), $confirm); } } $current = apply_filters('signup_user_init', $current); // allow definition of default variables ob_start(); do_action('preprocess_signup_form'); $pre = ob_get_clean(); $header = gPluginHTML::tag($args['title_wrap'], array('class' => 'member-signup-title'), $args['title']); $fields_hidden = gPluginHTML::tag('input', array('type' => 'hidden', 'name' => 'stage', 'value' => 'validate-user-signup'), false); remove_action('signup_hidden_fields', 'signup_nonce_fields'); $id_nonce = mt_rand(); $fields_hidden .= gPluginHTML::tag('input', array('type' => 'hidden', 'name' => 'member_signup_form_id', 'value' => $id_nonce), false); $fields_hidden .= wp_nonce_field('member_signup_form_' . $id_nonce, '_member_signup_form', false, false); ob_start(); do_action('signup_hidden_fields'); $fields_hidden .= ob_get_clean(); $field_user_name = gPluginHTML::tag('label', array('for' => 'user_name'), $labels['user_name']); if ($username_error = $current['errors']->get_error_message('user_name')) { $field_user_name .= gPluginHTML::tag('p', array('class' => 'error'), $username_error); } $field_user_name .= gPluginHTML::tag('input', array('name' => 'user_name', 'id' => 'user_name', 'class' => 'textInput', 'type' => 'text', 'value' => esc_attr($current['user_name']), 'maxlength' => '60'), false); if ($descriptions['user_name']) { $field_user_name .= gPluginHTML::tag('p', array('class' => 'description formHint'), $descriptions['user_name']); } $field_user_name = gPluginHTML::tag($args['field_wrap'], array('class' => $args['field_wrap_class'] . ' ctrlHolder'), $field_user_name); $field_user_email = gPluginHTML::tag('label', array('for' => 'user_email'), $labels['user_email']); if ($useremail_error = $current['errors']->get_error_message('user_email')) { $field_user_email .= gPluginHTML::tag('p', array('class' => 'error'), $useremail_error); } $field_user_email .= gPluginHTML::tag('input', array('name' => 'user_email', 'id' => 'user_email', 'class' => 'textInput', 'type' => 'text', 'value' => esc_attr($current['user_email']), 'maxlength' => '200'), false); if ($descriptions['user_email']) { $field_user_email .= gPluginHTML::tag('p', array('class' => 'description formHint'), $descriptions['user_email']); } $field_user_email = gPluginHTML::tag($args['field_wrap'], array('class' => $args['field_wrap_class'] . ' ctrlHolder'), $field_user_email); $user_email = gPluginHTML::tag('fieldset', array(), $field_user_name . $field_user_email); ob_start(); do_action('signup_extra_fields', $current['errors'], $args); $fields_extra = ob_get_clean(); $submit = gPluginHTML::tag('input', array('name' => 'submit', 'class' => 'primaryAction', 'type' => 'submit', 'value' => esc_attr($labels['submit'])), false); $submit = gPluginHTML::tag('p', array('class' => 'submit buttonHolder'), $submit); $form = gPluginHTML::tag('form', array('id' => 'member_signup_form', 'method' => 'post', 'class' => 'uniForm', 'action' => ''), $fields_hidden . $user_email . $fields_extra . $submit); defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', true); return gPluginHTML::tag('div', array('class' => $args['class']), $pre . $header . $form); }
public function wp_loaded() { global $pagenow; if (is_admin() && !is_user_logged_in() && !defined('DOING_AJAX')) { wp_die(__('You must log in to access the admin area.', 'rename-wp-login')); } $request = parse_url($_SERVER['REQUEST_URI']); if ($pagenow === 'wp-login.php' && $request['path'] !== $this->user_trailingslashit($request['path']) && get_option('permalink_structure')) { wp_safe_redirect($this->user_trailingslashit($this->new_login_url()) . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')); die; } elseif ($this->wp_login_php) { if (($referer = wp_get_referer()) && strpos($referer, 'wp-activate.php') !== false && ($referer = parse_url($referer)) && !empty($referer['query'])) { parse_str($referer['query'], $referer); if (!empty($referer['key']) && ($result = wpmu_activate_signup($referer['key'])) && is_wp_error($result) && ($result->get_error_code() === 'already_active' || $result->get_error_code() === 'blog_taken')) { wp_safe_redirect($this->new_login_url() . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')); die; } } $this->wp_template_loader(); } elseif ($pagenow === 'wp-login.php') { global $error, $interim_login, $action, $user_login; @(require_once ABSPATH . 'wp-login.php'); die; } }
/** * Activates User account on Multisite based on the given key * * */ public static function ms_activate_account($key) { //if doing ajax, return if (defined('DOING_AJAX')) { return false; } //mimic bp activation $bp = buddypress(); $signup = apply_filters('bp_core_activate_account', wpmu_activate_signup($key)); /* If there was errors, add a message and redirect */ if ($signup->errors) { bp_core_add_message(__('There was an error activating your account, please try again.', 'buddypress'), 'error'); bp_core_redirect($bp->root_domain . '/' . bp_get_activate_slug()); //send the activation mail in this case } $user_id = $signup['user_id']; //should we pass password as a param instead of the dependency here? $pass = $_POST['signup_password']; $ud = get_userdata($user_id); $data = array('user_login' => $ud->user_login, 'user_email' => $ud->user_email, 'user_pass' => $pass, 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname($user_id)); //update password if (is_multisite()) { wp_update_user($data); } self::update_profile_fields($user_id, $signup); do_action('bp_core_activated_user', $user_id, $key, $signup); //let bp handle the new user registerd activity //do_action( 'bp_core_account_activated', &$signup, $_GET['key'] ); bp_core_add_message(__('Your account is now active!')); $bp->activation_complete = true; self::login_redirect($ud->user_login, $pass); }
public function rpr_preprocess_signup_form() { global $active_signup, $stage; switch ($stage) { case 'user-signup': if ($active_signup == 'all' || $_POST['signup_for'] == 'blog' && $active_signup == 'blog' || $_POST['signup_for'] == 'user' && $active_signup == 'user') { /* begin validate_user_signup stage */ // validate signup form, do wpmu_validate_user_signup action $result = wpmu_validate_user_signup(isset($_POST['user_name']) ? (string) $_POST['user_name'] : "", isset($_POST['user_email']) ? (string) $_POST['user_email'] : ""); extract($result); if ($errors->get_error_code()) { echo "signup_user"; signup_user($user_name, $user_email, $errors); do_action('after_signup_form'); get_footer(); exit; } if ('blog' === $_POST['signup_for']) { echo "signup_blog"; signup_blog($user_name, $user_email); do_action('after_signup_form'); get_footer(); exit; } // collect meta, commit user to database, send email wpmu_signup_user($user_name, $user_email, apply_filters('add_signup_meta', array())); // previously, displayed confirm_user_signup message before signup_finished action do_action('signup_finished'); /* end validate_user_signup stage */ } else { _e('User registration has been disabled.'); ?> </div> </div> <?php do_action('after_signup_form'); get_footer(); exit; } break; case 'blog-signup': if ($active_signup == 'all' || $active_signup == 'blog') { /* begin validate_blog_signup stage */ $result = wpmu_validate_user_signup(isset($_POST['user_name']) ? (string) $_POST['user_name'] : "", isset($_POST['user_email']) ? (string) $_POST['user_email'] : ""); extract($result); if ($errors->get_error_code()) { echo "signup_user"; signup_user($user_name, $user_email, $errors); do_action('after_signup_form'); get_footer(); exit; } $result = wpmu_validate_blog_signup(isset($_POST['blogname']) ? (string) $_POST['blogname'] : "", isset($_POST['blog_title']) ? (string) $_POST['blog_title'] : ""); extract($result); if ($errors->get_error_code()) { signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); do_action('after_signup_form'); get_footer(); exit; } // collect meta, commit user to database, send email $meta = array('lang_id' => 1, 'public' => (int) $_POST['blog_public']); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, apply_filters('add_signup_meta', $meta)); // previously, displayed confirm_blog_signup message before signup_finished action do_action('signup_finished'); /* end validate_blog_signup stage */ } else { _e('Site registration has been disabled.'); ?> </div> </div> <?php do_action('after_signup_form'); get_footer(); exit; } break; default: return; } /* begin wp-activate page */ $key = (string) $_REQUEST['key']; // wpmu_create_user, wpmu_welcome_user_notification, add_new_user_to_blog, do wpmu_activate_user action $result = wpmu_activate_signup($key); if (is_wp_error($result)) { if ('already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code()) { $signup = $result->get_error_data(); ?> <h2><?php _e('Your account is now active!'); ?> </h2> <?php echo '<p class="lead-in">'; if ($signup->domain . $signup->path == '') { printf(__('Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.'), network_site_url('wp-login.php', 'login'), $signup->user_login, $signup->user_email, wp_lostpassword_url()); } else { printf(__('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, wp_lostpassword_url()); } echo '</p>'; } else { ?> <h2><?php _e('An error occurred during the activation'); ?> </h2> <?php echo '<p>' . $result->get_error_message() . '</p>'; } } else { //TODO: Why not reference $result->blog_id? extract($result); if (isset($blog_id)) { $url = get_blogaddress_by_id((int) $blog_id); } $user = get_userdata((int) $user_id); ?> <h2><?php _e('Your account is now active!'); ?> </h2> <div id="signup-welcome"> <p><span class="h3"><?php _e('Username:'******'Password:'******'', 'http')) { ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>'), $url, $url . 'wp-login.php'); ?> </p> <?php } else { ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.'), network_site_url('wp-login.php', 'login'), network_home_url()); ?> </p> <?php } } ?> </div> <script type="text/javascript"> var key_input = document.getElementById('key'); key_input && key_input.focus(); </script> <?php get_footer(); ?> <?php exit; }
function bp_core_activation_do_activation() { global $current_site, $blog_id, $user_id; ?> <?php if (empty($_GET['key']) && empty($_POST['key'])) { ?> <h3><?php _e('Activation Key Required', 'buddypress'); ?> </h3> <p id="intro-text"><?php _e('This is the key contained in the email you were sent after registering for this site.', 'buddypress'); ?> </p> <div class="field-box"> <form name="activateform" id="activateform" method="post" action="<?php echo 'http://' . $current_site->domain . $current_site->path; ?> wp-activate.php"> <p> <label for="key"><?php _e('Activation Key:', 'buddypress'); ?> </label> <br /><input type="text" name="key" id="key" value="" size="50" /> </p> <p class="submit"> <input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Activate »', 'buddypress'); ?> "/> </p> </form> </div> <?php } else { $key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key']; $result = wpmu_activate_signup($key); if (is_wp_error($result)) { if ('already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code()) { $signup = $result->get_error_data(); ?> <h3><?php _e('Your account is now active!', 'buddypress'); ?> </h3> <?php _e('Your account has already been activated. You can now log in with the account details that were emailed to you.'); } else { ?> <h2><?php _e('An error occurred during the activation', 'buddypress'); ?> </h2> <?php echo '<p>' . $result->get_error_message() . '</p>'; } } else { extract($result); $user = new WP_User((int) $user_id); ?> <h3><?php _e('Your account is now active!', 'buddypress'); ?> </h3> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">Login</a> or go back to the <a href="%2$s">homepage</a>.', 'buddypress'), site_url('wp-login.php?redirect_to=' . site_url()), site_url()); ?> </p> <div class="field-box" id="signup-welcome"> <p><span class="label"><?php _e('Username:'******'buddypress'); ?> </span> <?php echo $user->user_login; ?> </p> <p><span class="label"><?php _e('Password:'******'buddypress'); ?> </span> <?php echo $password; ?> </p> </div> <?php do_action('bp_activation_extras', $user_id, $meta); } } }
function bp_core_activate_signup( $key ) { global $bp, $wpdb; $user = false; /* Multisite installs have their own activation routine */ if ( bp_core_is_multisite() ) { $user = wpmu_activate_signup( $key ); /* If there was errors, add a message and redirect */ if ( $user->errors ) { bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' ); bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG ); } $user_id = $user['user_id']; /* Set any profile data */ if ( function_exists( 'xprofile_set_field_data' ) ) { 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 = $user['meta']["field_{$field_id}"]; if ( !empty( $current_field ) ) xprofile_set_field_data( $field_id, $user_id, $current_field ); } } } } else { /* Get the user_id based on the $key */ $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) ); if ( empty( $user_id ) ) return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); /* 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' ) ); /* Notify the site admin of a new user registration */ wp_new_user_notification( $user_id ); /* Remove the activation key meta */ delete_user_meta( $user_id, 'activation_key' ); } /* Update the user_url and display_name */ wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) ); /* Add a last active entry */ update_user_meta( $user_id, 'last_activity', bp_core_current_time() ); /* Set the password on multisite installs */ if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) ) $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); /* Delete the total member cache */ wp_cache_delete( 'bp_total_member_count', 'bp' ); do_action( 'bp_core_activated_user', $user_id, $key, $user ); return $user_id; }
public static function activate_blog($data, $trial = false, $period = 1, $level = 1, $expire = false) { global $psts, $wpdb; $user_pass = false; if (!is_array($data)) { $key = $data; } else { $key = isset($data['activation_key']) ? $data['activation_key'] : false; $user_pass = isset($data['new_blog_details']['user_pass']) ? $data['new_blog_details']['user_pass'] : false; } if (empty($key)) { return false; } // In case we're in session $session_data['new_blog_details'] = ProSites_Helper_Session::session('new_blog_details'); $user_pass = empty($user_pass) && isset($session_data['new_blog_details']['user_pass']) ? $session_data['new_blog_details']['user_pass'] : $user_pass; if (!empty($user_pass)) { self::$temp_pass = $user_pass; add_filter('update_welcome_email', array('ProSites_Helper_Registration', 'update_welcome_email'), 10, 6); } // Activate the user signup $result = wpmu_activate_signup($key); $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key)); // If the blog has already been activated, we still need some information from the signup table if (is_wp_error($result)) { $result = array(); if (empty($signup)) { return 0; } $user_id = username_exists($signup->user_login); $blog_id = domain_exists($signup->domain, $signup->path, $wpdb->siteid); // As a fallback, try the site domain if (empty($blog_id)) { $domain = $wpdb->get_var($wpdb->prepare("SELECT domain FROM {$wpdb->site} WHERE id = %d", $wpdb->siteid)); $blog_id = domain_exists($domain, $signup->path, $wpdb->siteid); } $result['user_id'] = $user_id; $result['blog_id'] = (int) $blog_id; } /** * Update coupon information */ if (!empty($signup)) { // $blog_id = $result['blog_id']; // $signup_meta = maybe_unserialize( $signup->meta ); // // // Unlikely that this will have a coupon, but make sure // $used = (array) get_blog_option( $blog_id, 'psts_used_coupons' ); // // // Is there a coupon stored in the signup_meta? // if( isset( $signup_meta['psts_used_coupons'] ) && ! empty( $signup_meta['psts_used_coupons'] ) && is_array( $signup_meta['psts_used_coupons'] ) ) { // // Merge and make sure we don't record the same coupon twice // $used = array_merge( $used, $signup_meta['psts_used_coupons'] ); // $used = array_unique( $used ); // // Remove from signup meta // unset( $signup_meta['psts_used_coupons'] ); // $psts->update_signup_meta( $signup_meta, $key ); // } // if( ! empty( $used ) ) { // // Add to blog options // update_blog_option( $blog_id, 'psts_used_coupons', $used ); // } } /** * @todo: Make sure we dont over extend */ //Set Trial if ($trial) { $trial_days = $psts->get_setting('trial_days', 0); // Set to first level for $trial_days $psts->extend($result['blog_id'], $period, 'Trial', $level, '', strtotime('+ ' . $trial_days . ' days')); //Redirect to checkout on next signup /** * @todo May not be needed here anymore */ //update_blog_option( $result['blog_id'], 'psts_signed_up', 1 ); } if (!empty($user_pass)) { $result['password'] = $user_pass; } // Contains $result['password'] for new users return $result; }
/** * Activates the user blog if a domain is specified and if the blog is not already active * * @param bool $domain * @param bool $trial * @param bool $period * @param bool $level * * @return bool */ function activate_user_blog( $domain = false, $trial = true, $period = false, $level = false ) { global $wpdb, $path; $trial_days = $this->get_setting( 'trial_days', 0 ); if ( ! $domain ) { return false; } //Get activation key from db $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s", $domain ) ); $activation_key = ! empty( $signup->activation_key ) ? $signup->activation_key : ''; if ( ! $activation_key || $signup->active ) { //get blog id $fields = array( 'domain' => $domain, 'path' => '/' ); $blog = get_blog_details( $fields ); return ! empty( $blog->blog_id ) ? $blog->blog_id : false; } $result = wpmu_activate_signup( $activation_key ); if ( empty( $result['user_id'] ) ) { return false; } //Get user login by user id $user = get_user_by( 'id', $result['user_id'] ); if ( empty( $user ) || is_wp_error( $user ) ) { return false; } //Login user to follow up the rest of Pro Site process $creds = array( 'user_login' => $user->user_login, 'user_password' => $result['password'] ); $user = wp_signon( $creds, true ); wp_set_current_user( $user->ID ); //Set Trial if ( $trial ) { $this->extend( $result['blog_id'], $period, 'Trial', $level, '', strtotime( '+ ' . $trial_days . ' days' ) ); //Redirect to checkout on next signup update_blog_option( $result['blog_id'], 'psts_signed_up', 1 ); } // Unset Domain name from session if its still there ProSites_Helper_Session::unset_session( 'domain' ); if ( isset( $result['blog_id'] ) ) { return $result['blog_id']; } else { return false; } }
?> </label> <br /><input type="text" name="key" id="key" value="" size="50" /> </p> <p class="submit"> <input id="submit" type="submit" name="Submit" class="submit" value="<?php esc_attr_e('Activate'); ?> " /> </p> </form> <?php } else { $key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key']; $result = wpmu_activate_signup($key); if (is_wp_error($result)) { if ('already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code()) { $signup = $result->get_error_data(); ?> <h2><?php _e('Your account is now active!'); ?> </h2> <?php echo '<p class="lead-in">'; if ($signup->domain . $signup->path == '') { printf(__('Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.'), network_site_url('wp-login.php', 'login'), $signup->user_login, $signup->user_email, wp_lostpassword_url()); } else { printf(__('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, wp_lostpassword_url()); }
/** * Outputs the activation page * * @since 6.1 * @access public * * @param object $template Theme_My_Login_Template object */ public function tml_display_activate(&$template) { global $blog_id; echo '<div class="login" id="theme-my-login' . esc_attr($template->get_option('instance')) . '">'; if (empty($_GET['key']) && empty($_POST['key'])) { ?> <h2><?php _e('Activation Key Required', 'theme-my-login'); ?> </h2> <form name="activateform" id="activateform" method="post" action="<?php $template->the_action_url('activate'); ?> "> <p> <label for="key<?php $template->the_instance(); ?> "><?php _e('Activation Key:', 'theme-my-login'); ?> </label> <br /><input type="text" name="key<?php $template->the_instance(); ?> " id="key" value="" size="50" /> </p> <p class="submit"> <input id="submit<?php $template->the_instance(); ?> " type="submit" name="Submit" class="submit" value="<?php esc_attr_e('Activate', 'theme-my-login'); ?> " /> </p> </form> <?php } else { $key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key']; $result = wpmu_activate_signup($key); if (is_wp_error($result)) { if ('already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code()) { $signup = $result->get_error_data(); ?> <h2><?php _e('Your account is now active!', 'theme-my-login'); ?> </h2> <?php echo '<p class="lead-in">'; if ($signup->domain . $signup->path == '') { printf(__('Your account has been activated. You may now <a href="%1$s">login</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.', 'theme-my-login'), network_site_url('wp-login.php', 'login'), $signup->user_login, $signup->user_email, network_site_url('wp-login.php?action=lostpassword', 'login')); } else { printf(__('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.', 'theme-my-login'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, network_site_url('wp-login.php?action=lostpassword')); } echo '</p>'; } else { ?> <h2><?php _e('An error occurred during the activation', 'theme-my-login'); ?> </h2> <?php echo '<p>' . $result->get_error_message() . '</p>'; } } else { extract($result); $url = get_blogaddress_by_id((int) $blog_id); $user = new WP_User((int) $user_id); ?> <h2><?php _e('Your account is now active!', 'theme-my-login'); ?> </h2> <div id="signup-welcome"> <p><span class="h3"><?php _e('Username:'******'theme-my-login'); ?> </span> <?php echo $user->user_login; ?> </p> <p><span class="h3"><?php _e('Password:'******'theme-my-login'); ?> </span> <?php echo $password; ?> </p> </div> <?php if ($url != network_home_url('', 'http')) { switch_to_blog((int) $blog_id); ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Login</a>', 'theme-my-login'), $url, wp_login_url()); ?> </p> <?php restore_current_blog(); } else { ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">Login</a> or go back to the <a href="%2$s">homepage</a>.', 'theme-my-login'), network_site_url('wp-login.php', 'login'), network_home_url()); ?> </p> <?php } } } echo '</div>'; }
/** * Filter the user_login, also known as the username, before it is added to the site. * * @since 2.0.3 * * @param string $user_login The sanitized username. */ $new_user_login = apply_filters('pre_user_login', sanitize_user(wp_unslash($_REQUEST['user_login']), true)); if (isset($_POST['noconfirmation']) && is_super_admin()) { add_filter('wpmu_signup_user_notification', '__return_false'); // Disable confirmation email } wpmu_signup_user($new_user_login, $_REQUEST['email'], array('add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'])); if (isset($_POST['noconfirmation']) && is_super_admin()) { $key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST['email'])); wpmu_activate_signup($key); $redirect = add_query_arg(array('update' => 'addnoconfirmation'), 'user-new.php'); } else { $redirect = add_query_arg(array('update' => 'newuserconfirmation'), 'user-new.php'); } wp_redirect($redirect); die; } } } $title = __('Add New User'); $parent_file = 'users.php'; $do_both = false; if (is_multisite() && current_user_can('promote_users') && current_user_can('create_users')) { $do_both = true; }
/** * Activate a signup, as identified by an activation key. * * @param string $key Activation key. * @return int|bool User ID on success, false on failure. */ function bp_core_activate_signup($key) { global $wpdb; $user = false; // Multisite installs have their own activation routine. if (is_multisite()) { $user = wpmu_activate_signup($key); // If there were errors, add a message and redirect. if (!empty($user->errors)) { return $user; } $user_id = $user['user_id']; } else { $signups = BP_Signup::get(array('activation_key' => $key)); if (empty($signups['signups'])) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } $signup = $signups['signups'][0]; if ($signup->active) { if (empty($signup->domain)) { return new WP_Error('already_active', __('The user is already active.', 'buddypress'), $signup); } else { return new WP_Error('already_active', __('The site is already active.', 'buddypress'), $signup); } } // Password is hashed again in wp_insert_user. $password = wp_generate_password(12, false); $user_id = username_exists($signup->user_login); // Create the user. if (!$user_id) { $user_id = wp_create_user($signup->user_login, $password, $signup->user_email); // If a user ID is found, this may be a legacy signup, or one // created locally for backward compatibility. Process it. } elseif ($key == wp_hash($user_id)) { // Change the user's status so they become active. if (!$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id))) { return new WP_Error('invalid_key', __('Invalid activation key.', 'buddypress')); } bp_delete_user_meta($user_id, 'activation_key'); $member = get_userdata($user_id); $member->set_role(get_option('default_role')); $user_already_created = true; } else { $user_already_exists = true; } if (!$user_id) { return new WP_Error('create_user', __('Could not create user', 'buddypress'), $signup); } // Fetch the signup so we have the data later on. $signups = BP_Signup::get(array('activation_key' => $key)); $signup = isset($signups['signups']) && !empty($signups['signups'][0]) ? $signups['signups'][0] : false; // Activate the signup. BP_Signup::validate($key); if (isset($user_already_exists)) { return new WP_Error('user_already_exists', __('That username is already activated.', 'buddypress'), $signup); } // Set up data to pass to the legacy filter. $user = array('user_id' => $user_id, 'password' => $signup->meta['password'], 'meta' => $signup->meta); // Notify the site admin of a new user registration. wp_new_user_notification($user_id); if (isset($user_already_created)) { /** * Fires if the user has already been created. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; } } // Set any profile data. if (bp_is_active('xprofile')) { if (!empty($user['meta']['profile_field_ids'])) { $profile_field_ids = explode(',', $user['meta']['profile_field_ids']); foreach ((array) $profile_field_ids as $field_id) { $current_field = isset($user['meta']["field_{$field_id}"]) ? $user['meta']["field_{$field_id}"] : false; if (!empty($current_field)) { xprofile_set_field_data($field_id, $user_id, $current_field); } // Save the visibility level. $visibility_level = !empty($user['meta']['field_' . $field_id . '_visibility']) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level); } } } // Update the display_name. wp_update_user(array('ID' => $user_id, 'display_name' => bp_core_get_user_displayname($user_id))); // Set the password on multisite installs. if (!empty($user['meta']['password'])) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id)); } /** * Fires at the end of the user activation process. * * @since 1.2.2 * * @param int $user_id ID of the user being checked. * @param string $key Activation key. * @param array $user Array of user data. */ do_action('bp_core_activated_user', $user_id, $key, $user); return $user_id; }