Esempio n. 1
0
 /**
  * Installs the blog
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param string $blog_title Blog title.
  * @param string $user_name User's username.
  * @param string $user_email User's email.
  * @param bool $public Whether blog is public.
  * @param null $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function nxt_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '')
 {
     global $nxt_rewrite;
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     nxt_check_mysql_version();
     nxt_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     $guessurl = nxt_guess_url();
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     // Create default user.  If the user already exists, the user tables are
     // being shared among blogs.  Just set the role in that case.
     $user_id = username_exists($user_name);
     $user_password = trim($user_password);
     $email_password = false;
     if (!$user_id && empty($user_password)) {
         $user_password = nxt_generate_password(12, false);
         $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
         $user_id = nxt_create_user($user_name, $user_password, $user_email);
         update_user_option($user_id, 'default_password_nag', true, true);
         $email_password = true;
     } else {
         if (!$user_id) {
             // Password has been provided
             $message = '<em>' . __('Your chosen password.') . '</em>';
             $user_id = nxt_create_user($user_name, $user_password, $user_email);
         } else {
             $message = __('User already exists. Password inherited.');
         }
     }
     $user = new nxt_User($user_id);
     $user->set_role('administrator');
     nxt_install_defaults($user_id);
     $nxt_rewrite->flush_rules();
     nxt_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.'));
     nxt_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
Esempio n. 2
0
/**
 * An alias of nxt_create_user().
 *
 * @since 2.0
 * @deprecated 2.0
 * @deprecated Use nxt_create_user()
 * @see nxt_create_user()
 *
 * @param string $username The user's username.
 * @param string $password The user's password.
 * @param string $email The user's email (optional).
 * @return int The new user's ID.
 */
function create_user($username, $password, $email)
{
    _deprecated_function(__FUNCTION__, '2.0', 'nxt_create_user()');
    return nxt_create_user($username, $password, $email);
}
 function do_subscription_shortcode($atts, $content = null, $code = "")
 {
     global $nxt_query;
     $error = array();
     $page = addslashes($_REQUEST['action']);
     $M_options = get_option('membership_options', array());
     switch ($page) {
         case 'validatepage1':
             // Page 1 of the form has been submitted - validate
             include_once ABSPATH . nxtINC . '/registration.php';
             $required = array('user_login' => __('Username', 'membership'), 'user_email' => __('Email address', 'membership'), 'user_email2' => __('Email address confirmation', 'membership'), 'password' => __('Password', 'membership'), 'password2' => __('Password confirmation', 'membership'));
             $error = array();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership');
                 }
             }
             if ($_POST['user_email'] != $_POST['user_email2']) {
                 $error[] = __('Please ensure the email addresses match.', 'membership');
             }
             if ($_POST['password'] != $_POST['password2']) {
                 $error[] = __('Please ensure the passwords match.', 'membership');
             }
             if (username_exists(sanitize_user($_POST['user_login']))) {
                 $error[] = __('That username is already taken, sorry.', 'membership');
             }
             if (email_exists($_POST['user_email'])) {
                 $error[] = __('That email address is already taken, sorry.', 'membership');
             }
             if (function_exists('get_site_option')) {
                 $terms = get_site_option('signup_tos_data');
             } else {
                 $terms = '';
             }
             if (!empty($terms)) {
                 if (empty($_POST['tosagree'])) {
                     $error[] = __('You need to agree to the terms of service to register.', 'membership');
                 }
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             if (empty($error)) {
                 // Pre - error reporting check for final add user
                 $user_id = nxt_create_user(sanitize_user($_POST['user_login']), $_POST['password'], $_POST['user_email']);
                 if (is_nxt_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error[] = $userid->get_error_message();
                 } else {
                     $member = new M_Membership($user_id);
                     if (empty($M_options['enableincompletesignups']) || $M_options['enableincompletesignups'] != 'yes') {
                         $member->deactivate();
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']);
                     } else {
                         nxt_new_user_notification($user_id, $_POST['password']);
                     }
                 }
             }
             do_action('membership_subscription_form_registration_process', $error, $user_id);
             if (!empty($error)) {
                 $content .= "<div class='error'>";
                 $content .= implode('<br/>', $error);
                 $content .= "</div>";
                 $content .= $this->show_subpage_one(true);
             } else {
                 // everything seems fine (so far), so we have our queued user so let's
                 // look at picking a subscription.
                 $content .= $this->show_subpage_two($user_id);
             }
             break;
         case 'validatepage1bp':
             global $bp;
             include_once ABSPATH . nxtINC . '/registration.php';
             $required = array('signup_username' => __('Username', 'membership'), 'signup_email' => __('Email address', 'membership'), 'signup_password' => __('Password', 'membership'), 'signup_password_confirm' => __('Password confirmation', 'membership'));
             $error = array();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership');
                 }
             }
             if ($_POST['signup_password'] != $_POST['signup_password_confirm']) {
                 $error[] = __('Please ensure the passwords match.', 'membership');
             }
             if (username_exists(sanitize_user($_POST['signup_username']))) {
                 $error[] = __('That username is already taken, sorry.', 'membership');
             }
             if (email_exists($_POST['signup_email'])) {
                 $error[] = __('That email address is already taken, sorry.', 'membership');
             }
             $meta_array = array();
             // xprofile required fields
             /* Now we've checked account details, we can check profile information */
             if (function_exists('xprofile_check_is_required_field')) {
                 /* Make sure hidden field is passed and populated */
                 if (isset($_POST['signup_profile_field_ids']) && !empty($_POST['signup_profile_field_ids'])) {
                     /* Let's compact any profile field info into an array */
                     $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
                     /* Loop through the posted fields formatting any datebox values then validate the field */
                     foreach ((array) $profile_field_ids as $field_id) {
                         if (!isset($_POST['field_' . $field_id])) {
                             if (isset($_POST['field_' . $field_id . '_day'])) {
                                 $_POST['field_' . $field_id] = strtotime($_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year']);
                             }
                         }
                         /* Create errors for required fields without values */
                         if (xprofile_check_is_required_field($field_id) && empty($_POST['field_' . $field_id])) {
                             $field = new BP_Xprofile_Field($field_id);
                             $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $field->name . "</strong>" . __(' information is completed.', 'membership');
                         }
                         $meta_array[$field_id] = $_POST['field_' . $field_id];
                     }
                 }
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             if (empty($error)) {
                 // Pre - error reporting check for final add user
                 $user_id = nxt_create_user(sanitize_user($_POST['signup_username']), $_POST['signup_password'], $_POST['signup_email']);
                 if (is_nxt_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error[] = $userid->get_error_message();
                 } else {
                     $member = new M_Membership($user_id);
                     if (empty($M_options['enableincompletesignups']) || $M_options['enableincompletesignups'] != 'yes') {
                         $member->deactivate();
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']);
                     } else {
                         nxt_new_user_notification($user_id, $_POST['signup_password']);
                     }
                     foreach ((array) $meta_array as $field_id => $field_content) {
                         if (function_exists('xprofile_set_field_data')) {
                             xprofile_set_field_data($field_id, $user_id, $field_content);
                         }
                     }
                 }
             }
             do_action('membership_subscription_form_registration_process', $error, $user_id);
             if (!empty($error)) {
                 $content .= "<div class='error'>";
                 $content .= implode('<br/>', $error);
                 $content .= "</div>";
                 $content .= $this->show_subpage_one(true);
             } else {
                 // everything seems fine (so far), so we have our queued user so let's
                 // look at picking a subscription.
                 $content .= $this->show_subpage_two($user_id);
             }
             break;
         case 'validatepage2':
             $content = apply_filters('membership_subscription_form_subscription_process', $content, $error);
             break;
         case 'page2':
         case 'page1':
         default:
             if (!is_user_logged_in()) {
                 $content .= $this->show_subpage_one();
             } else {
                 // logged in check for sub
                 $user = nxt_get_current_user();
                 $member = new M_Membership($user->ID);
                 if ($member->is_member()) {
                     // This person is a member - display already registered stuff
                     $content .= $this->show_subpage_member();
                 } else {
                     // Show page two;
                     $content .= $this->show_subpage_two($user->ID);
                 }
             }
             break;
     }
     $content = apply_filters('membership_subscription_form', $content);
     return $content;
 }
Esempio n. 4
0
/**
 * Create a user.
 *
 * This function runs when a user self-registers as well as when
 * a Super Admin creates a new user. Hook to 'nxtmu_new_user' for events
 * that should affect all new users, but only on Multisite (otherwise
 * use 'user_register').
 *
 * @since MU
 * @uses nxt_create_user()
 *
 * @param string $user_name The new user's login name.
 * @param string $password The new user's password.
 * @param string $email The new user's email address.
 * @return mixed Returns false on failure, or int $user_id on success
 */
function nxtmu_create_user($user_name, $password, $email)
{
    $user_name = preg_replace('/\\s+/', '', sanitize_user($user_name, true));
    $user_id = nxt_create_user($user_name, $password, $email);
    if (is_nxt_error($user_id)) {
        return false;
    }
    // Newly created users have no roles or caps until they are added to a blog.
    delete_user_option($user_id, 'capabilities');
    delete_user_option($user_id, 'user_level');
    do_action('nxtmu_new_user', $user_id);
    return $user_id;
}
Esempio n. 5
0
 /**
  * Map old author logins to local user IDs based on decisions made
  * in import options form. Can map to an existing user, create a new user
  * or falls back to the current user in case of error with either of the previous
  */
 function get_author_mapping()
 {
     if (!isset($_POST['imported_authors'])) {
         return;
     }
     $create_users = $this->allow_create_users();
     foreach ((array) $_POST['imported_authors'] as $i => $old_login) {
         // Multsite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
         $santized_old_login = sanitize_user($old_login, true);
         $old_id = isset($this->authors[$old_login]['author_id']) ? intval($this->authors[$old_login]['author_id']) : false;
         if (!empty($_POST['user_map'][$i])) {
             $user = get_userdata(intval($_POST['user_map'][$i]));
             if (isset($user->ID)) {
                 if ($old_id) {
                     $this->processed_authors[$old_id] = $user->ID;
                 }
                 $this->author_mapping[$santized_old_login] = $user->ID;
             }
         } else {
             if ($create_users) {
                 if (!empty($_POST['user_new'][$i])) {
                     $user_id = nxt_create_user($_POST['user_new'][$i], nxt_generate_password());
                 } else {
                     if ($this->version != '1.0') {
                         $user_data = array('user_login' => $old_login, 'user_pass' => nxt_generate_password(), 'user_email' => isset($this->authors[$old_login]['author_email']) ? $this->authors[$old_login]['author_email'] : '', 'display_name' => $this->authors[$old_login]['author_display_name'], 'first_name' => isset($this->authors[$old_login]['author_first_name']) ? $this->authors[$old_login]['author_first_name'] : '', 'last_name' => isset($this->authors[$old_login]['author_last_name']) ? $this->authors[$old_login]['author_last_name'] : '');
                         $user_id = nxt_insert_user($user_data);
                     }
                 }
                 if (!is_nxt_error($user_id)) {
                     if ($old_id) {
                         $this->processed_authors[$old_id] = $user_id;
                     }
                     $this->author_mapping[$santized_old_login] = $user_id;
                 } else {
                     printf(__('Failed to create new user for %s. Their posts will be attributed to the current user.', 'nxtclass-importer'), esc_html($this->authors[$old_login]['author_display_name']));
                     if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                         echo ' ' . $user_id->get_error_message();
                     }
                     echo '<br />';
                 }
             }
         }
         // failsafe: if the user_id was invalid, default to the current user
         if (!isset($this->author_mapping[$santized_old_login])) {
             if ($old_id) {
                 $this->processed_authors[$old_id] = (int) get_current_user_id();
             }
             $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
         }
     }
 }