function bp_core_screen_signup()
{
    global $bp, $wpdb;
    if (!bp_is_current_component('register')) {
        return;
    }
    // Not a directory
    bp_update_is_directory(false, 'register');
    // If the user is logged in, redirect away from here
    if (is_user_logged_in()) {
        if (bp_is_component_front_page('register')) {
            $redirect_to = bp_get_root_domain() . '/' . bp_get_members_root_slug();
        } else {
            $redirect_to = bp_get_root_domain();
        }
        bp_core_redirect(apply_filters('bp_loggedin_register_page_redirect_to', $redirect_to));
        return;
    }
    $bp->signup->step = 'request-details';
    if (!bp_get_signup_allowed()) {
        $bp->signup->step = 'registration-disabled';
    } elseif (isset($_POST['signup_submit'])) {
        // Check the nonce
        check_admin_referer('bp_new_signup');
        // Check the base account details for problems
        $account_details = bp_core_validate_user_signup($_POST['signup_username'], $_POST['signup_email']);
        // If there are errors with account details, set them for display
        if (!empty($account_details['errors']->errors['user_name'])) {
            $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
        }
        if (!empty($account_details['errors']->errors['user_email'])) {
            $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
        }
        // Check that both password fields are filled in
        if (empty($_POST['signup_password']) || empty($_POST['signup_password_confirm'])) {
            $bp->signup->errors['signup_password'] = __('Please make sure you enter your password twice', 'buddypress');
        }
        // Check that the passwords match
        if (!empty($_POST['signup_password']) && !empty($_POST['signup_password_confirm']) && $_POST['signup_password'] != $_POST['signup_password_confirm']) {
            $bp->signup->errors['signup_password'] = __('The passwords you entered do not match.', 'buddypress');
        }
        $bp->signup->username = $_POST['signup_username'];
        $bp->signup->email = $_POST['signup_email'];
        // Now we've checked account details, we can check profile information
        if (bp_is_active('xprofile')) {
            // 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 (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                            $_POST['field_' . $field_id] = date('Y-m-d H:i:s', 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])) {
                        $bp->signup->errors['field_' . $field_id] = __('This is a required field', 'buddypress');
                    }
                }
                // This situation doesn't naturally occur so bounce to website root
            } else {
                bp_core_redirect(bp_get_root_domain());
            }
        }
        // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled
        if (isset($_POST['signup_with_blog'])) {
            $active_signup = $bp->site_options['registration'];
            if ('blog' == $active_signup || 'all' == $active_signup) {
                $blog_details = bp_core_validate_blog_signup($_POST['signup_blog_url'], $_POST['signup_blog_title']);
                // If there are errors with blog details, set them for display
                if (!empty($blog_details['errors']->errors['blogname'])) {
                    $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
                }
                if (!empty($blog_details['errors']->errors['blog_title'])) {
                    $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
                }
            }
        }
        do_action('bp_signup_validate');
        // Add any errors to the action for the field in the template for display.
        if (!empty($bp->signup->errors)) {
            foreach ((array) $bp->signup->errors as $fieldname => $error_message) {
                add_action('bp_' . $fieldname . '_errors', create_function('', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\\"error\\">' . $error_message . '</div>" );'));
            }
        } else {
            $bp->signup->step = 'save-details';
            // No errors! Let's register those deets.
            $active_signup = !empty($bp->site_options['registration']) ? $bp->site_options['registration'] : '';
            if ('none' != $active_signup) {
                // Let's compact any profile field info into usermeta
                $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
                // Loop through the posted fields formatting any datebox values then add to usermeta
                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] = date('Y-m-d H:i:s', strtotime($_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year']));
                        }
                    }
                    if (!empty($_POST['field_' . $field_id])) {
                        $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
                    }
                }
                // Store the profile field ID's in usermeta
                $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
                // Hash and store the password
                $usermeta['password'] = wp_hash_password($_POST['signup_password']);
                // If the user decided to create a blog, save those details to usermeta
                if ('blog' == $active_signup || 'all' == $active_signup) {
                    $usermeta['public'] = isset($_POST['signup_blog_privacy']) && 'public' == $_POST['signup_blog_privacy'] ? true : false;
                }
                $usermeta = apply_filters('bp_signup_usermeta', $usermeta);
                // Finally, sign up the user and/or blog
                if (isset($_POST['signup_with_blog']) && is_multisite()) {
                    bp_core_signup_blog($blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta);
                } else {
                    bp_core_signup_user($_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta);
                }
                $bp->signup->step = 'completed-confirmation';
            }
            do_action('bp_complete_signup');
        }
    }
    do_action('bp_core_screen_signup');
    bp_core_load_template(apply_filters('bp_core_template_register', 'registration/register'));
}
/**
 * Handle the loading of the signup screen.
 */
function bp_core_screen_signup()
{
    global $bp;
    if (!bp_is_current_component('register') || bp_current_action()) {
        return;
    }
    // Not a directory
    bp_update_is_directory(false, 'register');
    // If the user is logged in, redirect away from here
    if (is_user_logged_in()) {
        if (bp_is_component_front_page('register')) {
            $redirect_to = trailingslashit(bp_get_root_domain() . '/' . bp_get_members_root_slug());
        } else {
            $redirect_to = bp_get_root_domain();
        }
        /**
         * Filters the URL to redirect logged in users to when visiting registration page.
         *
         * @since BuddyPress (1.5.1)
         *
         * @param string $redirect_to URL to redirect user to.
         */
        bp_core_redirect(apply_filters('bp_loggedin_register_page_redirect_to', $redirect_to));
        return;
    }
    $bp->signup->step = 'request-details';
    if (!bp_get_signup_allowed()) {
        $bp->signup->step = 'registration-disabled';
        // If the signup page is submitted, validate and save
    } elseif (isset($_POST['signup_submit']) && bp_verify_nonce_request('bp_new_signup')) {
        /**
         * Fires before the validation of a new signup.
         *
         * @since BuddyPress (2.0.0)
         */
        do_action('bp_signup_pre_validate');
        // Check the base account details for problems
        $account_details = bp_core_validate_user_signup($_POST['signup_username'], $_POST['signup_email']);
        // If there are errors with account details, set them for display
        if (!empty($account_details['errors']->errors['user_name'])) {
            $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
        }
        if (!empty($account_details['errors']->errors['user_email'])) {
            $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
        }
        // Check that both password fields are filled in
        if (empty($_POST['signup_password']) || empty($_POST['signup_password_confirm'])) {
            $bp->signup->errors['signup_password'] = __('Please make sure you enter your password twice', 'buddypress');
        }
        // Check that the passwords match
        if (!empty($_POST['signup_password']) && !empty($_POST['signup_password_confirm']) && $_POST['signup_password'] != $_POST['signup_password_confirm']) {
            $bp->signup->errors['signup_password'] = __('The passwords you entered do not match.', 'buddypress');
        }
        $bp->signup->username = $_POST['signup_username'];
        $bp->signup->email = $_POST['signup_email'];
        // Now we've checked account details, we can check profile information
        if (bp_is_active('xprofile')) {
            // 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 (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                            $_POST['field_' . $field_id] = date('Y-m-d H:i:s', 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])) {
                        $bp->signup->errors['field_' . $field_id] = __('This is a required field', 'buddypress');
                    }
                }
                // This situation doesn't naturally occur so bounce to website root
            } else {
                bp_core_redirect(bp_get_root_domain());
            }
        }
        // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled
        if (isset($_POST['signup_with_blog'])) {
            $active_signup = $bp->site_options['registration'];
            if ('blog' == $active_signup || 'all' == $active_signup) {
                $blog_details = bp_core_validate_blog_signup($_POST['signup_blog_url'], $_POST['signup_blog_title']);
                // If there are errors with blog details, set them for display
                if (!empty($blog_details['errors']->errors['blogname'])) {
                    $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
                }
                if (!empty($blog_details['errors']->errors['blog_title'])) {
                    $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
                }
            }
        }
        /**
         * Fires after the validation of a new signup.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_signup_validate');
        // Add any errors to the action for the field in the template for display.
        if (!empty($bp->signup->errors)) {
            foreach ((array) $bp->signup->errors as $fieldname => $error_message) {
                // addslashes() and stripslashes() to avoid create_function()
                // syntax errors when the $error_message contains quotes
                /**
                 * Filters the error message in the loop.
                 *
                 * @since BuddyPress (1.5.0)
                 *
                 * @param string $value Error message wrapped in html.
                 */
                add_action('bp_' . $fieldname . '_errors', create_function('', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\\"error\\">" . stripslashes( \'' . addslashes($error_message) . '\' ) . "</div>" );'));
            }
        } else {
            $bp->signup->step = 'save-details';
            // No errors! Let's register those deets.
            $active_signup = !empty($bp->site_options['registration']) ? $bp->site_options['registration'] : '';
            if ('none' != $active_signup) {
                // Make sure the extended profiles module is enabled
                if (bp_is_active('xprofile')) {
                    // Let's compact any profile field info into usermeta
                    $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
                    // Loop through the posted fields formatting any datebox values then add to usermeta - @todo This logic should be shared with the same in xprofile_screen_edit_profile()
                    foreach ((array) $profile_field_ids as $field_id) {
                        if (!isset($_POST['field_' . $field_id])) {
                            if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                                // Concatenate the values
                                $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                                // Turn the concatenated value into a timestamp
                                $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                            }
                        }
                        if (!empty($_POST['field_' . $field_id])) {
                            $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
                        }
                        if (!empty($_POST['field_' . $field_id . '_visibility'])) {
                            $usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility'];
                        }
                    }
                    // Store the profile field ID's in usermeta
                    $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
                }
                // Hash and store the password
                $usermeta['password'] = wp_hash_password($_POST['signup_password']);
                // If the user decided to create a blog, save those details to usermeta
                if ('blog' == $active_signup || 'all' == $active_signup) {
                    $usermeta['public'] = isset($_POST['signup_blog_privacy']) && 'public' == $_POST['signup_blog_privacy'] ? true : false;
                }
                /**
                 * Filters the user meta used for signup.
                 *
                 * @since BuddyPress (1.1.0)
                 *
                 * @param array $usermeta Array of user meta to add to signup.
                 */
                $usermeta = apply_filters('bp_signup_usermeta', $usermeta);
                // Finally, sign up the user and/or blog
                if (isset($_POST['signup_with_blog']) && is_multisite()) {
                    $wp_user_id = bp_core_signup_blog($blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta);
                } else {
                    $wp_user_id = bp_core_signup_user($_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta);
                }
                if (is_wp_error($wp_user_id)) {
                    $bp->signup->step = 'request-details';
                    bp_core_add_message($wp_user_id->get_error_message(), 'error');
                } else {
                    $bp->signup->step = 'completed-confirmation';
                }
            }
            /**
             * Fires after the completion of a new signup.
             *
             * @since BuddyPress (1.1.0)
             */
            do_action('bp_complete_signup');
        }
    }
    /**
     * Fires right before the loading of the Member registration screen template file.
     *
     * @since BuddyPress (1.5.0)
     */
    do_action('bp_core_screen_signup');
    /**
     * Filters the template to load for the Member registration page screen.
     *
     * @since BuddyPress (1.5.0)
     *
     * @param string $value Path to the Member registration template to load.
     */
    bp_core_load_template(apply_filters('bp_core_template_register', array('register', 'registration/register')));
}
 /**
  * Checks post data and registers user, then exits
  *
  * @return string
  */
 public static function register($userData = NULL)
 {
     global $wpdb;
     $fieldList = self::getUserFieldList(-1);
     $fieldListWP = array();
     $fieldListBP = array();
     $return = array();
     $isFromExel = false;
     if (is_null($userData) || empty($userData)) {
         $userData = parse_str($_POST['userData'], $fieldsData);
     } else {
         $isFromExel = true;
         $fieldsData = $userData;
     }
     // break if two password fieldes are not equal
     /*
      * if ($fieldsData ['password_confirmation'] != $fieldsData ['user_pass']) {
      * $return ['result'] = false;
      * $return ['error'] = __ ( 'Password not confirmed.', 'login' );
      * $return ['msg'] = $fieldsData ['user_pass'];
      * $return ['$pass_conf'] = $fieldsData ['password_confirmation'];
      * echo json_encode ( $return );
      * if (! $isFromExel) {
      * wp_die ();
      * }
      * }
      */
     $fieldListWP['user_pass'] = wp_generate_password();
     foreach ($fieldList as $key => $val) {
         if ($fieldList[$key]['type'] == "wp") {
             $fieldListWP[$key] = $fieldsData[$key] ? $fieldsData[$key] : $fieldList[$key]['val'];
         } else {
             $fieldListBP[$key] = $fieldsData[$key] ? $fieldsData[$key] : $fieldList[$key]['val'];
         }
     }
     $fieldListWP['user_login'] = $fieldListWP['user_email'];
     // $fieldListWP ['display_name'] = empty ( $fieldListWP ['first_name'] ) ? $fieldListWP ['user_login'] : $fieldListWP ['first_name'];
     if (get_option('users_can_register')) {
         if (!function_exists('register_new_user')) {
             // in ajax we don't have access to this function, so include our own copy of the function
             include_once 'registration.php';
         }
         // if it's not error - this is user id
         $fieldListWP['user_email'] = sanitize_email($fieldListWP['user_email']);
         if (empty($fieldListWP['user_email'])) {
             $return['result'] = false;
             $return['error'] = __('<strong>ERROR</strong>: The email address isn&#8217;t correct.');
             echo json_encode($return);
             wp_die();
         }
         $userByEmail = get_user_by_email($fieldListWP['user_email']);
         if ($userByEmail) {
             $return['result'] = false;
             $return['error'] = __('Sorry, that email address is already used!');
             if (!$isFromExel) {
                 echo json_encode($return);
                 wp_die();
             } else {
                 echo '+';
                 return;
             }
         }
         $fieldList = array(fieldListWP => $fieldListWP, fieldListBP => $fieldListBP);
         if (is_numeric($fieldsData['enrollToCourse'])) {
             $fieldList['enrollToCourse'] = $fieldsData['enrollToCourse'];
         }
         $registerResult = bp_core_signup_user($fieldListWP['user_login'], $fieldListWP['user_pass'], $fieldListWP['user_email'], $fieldList);
         if (!is_wp_error($registerResult)) {
             // Success
             $return['result'] = true;
             $return['userId'] = $registerResult;
             $return['message'] = array('title' => __('Registration, check you mail. Title', 'qode'), 'content' => __('Registration, check you mail. Content', 'qode'));
             $return['buttons'] = array('toHome' => array('text' => __('Go to home page'), 'url' => get_site_url()));
         } else {
             // Something's wrong
             $return['result'] = false;
             $return['error'] = $registerResult == false ? __('An error occurred. Please try again later.') : $registerResult->get_error_message();
         }
         $return['action'] = 'register';
     } else {
         $return['result'] = false;
         $return['error'] = __('User registration has been disabled.');
     }
     echo json_encode($return);
     if (!$isFromExel) {
         wp_die();
     }
 }
function bp_ajax_submit_register_form()
{
    global $bp;
    // Check the nonce
    check_admin_referer('bp_new_signup');
    // Check the base account details for problems
    $account_details = bp_core_validate_user_signup($_POST['signup_username'], $_POST['signup_email']);
    // If there are errors with account details, set them for display
    if (!empty($account_details['errors']->errors['user_name'])) {
        $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
    }
    if (!empty($account_details['errors']->errors['user_email'])) {
        $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
    }
    // Check that both password fields are filled in
    if (empty($_POST['signup_password']) || empty($_POST['signup_password_confirm'])) {
        $bp->signup->errors['signup_password'] = __('Please make sure you enter your password twice', 'buddypress');
    }
    // Check that the passwords match
    if (!empty($_POST['signup_password']) && !empty($_POST['signup_password_confirm']) && $_POST['signup_password'] != $_POST['signup_password_confirm']) {
        $bp->signup->errors['signup_password'] = __('The passwords you entered do not match.', 'buddypress');
    }
    $bp->signup->username = $_POST['signup_username'];
    $bp->signup->email = $_POST['signup_email'];
    // Now we've checked account details, we can check profile information
    if (bp_is_active('xprofile')) {
        // 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 (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                        $_POST['field_' . $field_id] = date('Y-m-d H:i:s', 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])) {
                    $bp->signup->errors['field_' . $field_id] = __('This is a required field', 'buddypress');
                }
            }
            // This situation doesn't naturally occur so bounce to website root
        } else {
            bp_core_redirect(bp_get_root_domain());
        }
    }
    // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled
    if (isset($_POST['signup_with_blog'])) {
        $active_signup = $bp->site_options['registration'];
        if ('blog' == $active_signup || 'all' == $active_signup) {
            $blog_details = bp_core_validate_blog_signup($_POST['signup_blog_url'], $_POST['signup_blog_title']);
            // If there are errors with blog details, set them for display
            if (!empty($blog_details['errors']->errors['blogname'])) {
                $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
            }
            if (!empty($blog_details['errors']->errors['blog_title'])) {
                $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
            }
        }
    }
    do_action('bp_signup_validate');
    // Add any errors to the action for the field in the template for display.
    if (!empty($bp->signup->errors)) {
        $response['status'] = 'error';
        $response['errors'] = $bp->signup->errors;
        echo json_encode($response);
        exit;
        /*foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) {
        			// addslashes() and stripslashes() to avoid create_function()
        			// syntax errors when the $error_message contains quotes
        			add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\"error\">" . stripslashes( \'' . addslashes( $error_message ) . '\' ) . "</div>" );' ) );
        		}*/
    } else {
        $bp->signup->step = 'save-details';
        // No errors! Let's register those deets.
        $active_signup = !empty($bp->site_options['registration']) ? $bp->site_options['registration'] : '';
        if ('none' != $active_signup) {
            // Let's compact any profile field info into usermeta
            $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
            // Loop through the posted fields formatting any datebox values then add to usermeta
            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] = date('Y-m-d H:i:s', strtotime($_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year']));
                    }
                }
                if (!empty($_POST['field_' . $field_id])) {
                    $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
                }
            }
            // Store the profile field ID's in usermeta
            $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
            // Hash and store the password
            $usermeta['password'] = wp_hash_password($_POST['signup_password']);
            // If the user decided to create a blog, save those details to usermeta
            if ('blog' == $active_signup || 'all' == $active_signup) {
                $usermeta['public'] = isset($_POST['signup_blog_privacy']) && 'public' == $_POST['signup_blog_privacy'] ? true : false;
            }
            $usermeta = apply_filters('bp_signup_usermeta', $usermeta);
            // Finally, sign up the user and/or blog
            if (isset($_POST['signup_with_blog']) && is_multisite()) {
                $wp_user_id = bp_core_signup_blog($blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta);
            } else {
                $wp_user_id = bp_core_signup_user($_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta);
            }
            if (is_wp_error($wp_user_id)) {
                $bp->signup->step = 'request-details';
                bp_core_add_message(strip_tags($wp_user_id->get_error_message()), 'error');
                $response['status'] = 'user-error';
                $response['error-msg'] = strip_tags($wp_user_id->get_error_message());
                echo json_encode($response);
                exit;
            } else {
                $bp->signup->step = 'completed-confirmation';
                $response['status'] = 'success';
                echo json_encode($response);
                exit;
            }
        }
        do_action('bp_complete_signup');
    }
    echo 'form is submitted successfully.';
    exit;
}
 protected function add_user($user_data)
 {
     if (!$user_data) {
         return 0;
     }
     if (isset($user_data->email) && !empty($user_data->email)) {
         // Check user has exists in system
         $user = get_user_by('email', $user_data->email);
         if ($user) {
             return $user->ID;
         }
         // Process username
         $username = sanitize_user($user_data->first_name, true);
         $i = '';
         while (username_exists($username . $i)) {
             $i = absint($i);
             $i++;
         }
         $username = $username . $i;
         $password = wp_generate_password();
         if (function_exists('bp_core_signup_user')) {
             $user_login = '';
             $new_user = bp_core_signup_user($username, $password, $user_data->email, array());
             $data = array('ID' => $new_user, 'user_nicename' => $username, 'user_email' => $user_data->email, 'display_name' => $user_data->name, 'nickname' => $username, 'first_name' => $user_data->first_name, 'last_name' => $user_data->last_name, 'role' => 'subscriber');
             wp_update_user($data);
             if ($new_user) {
                 update_user_meta($new_user, 'fb_uid', $user_data->id);
                 update_user_meta($new_user, 'link', $user_data->link);
                 update_user_meta($new_user, 'updated_time', $user_data->updated_time);
                 update_user_meta($new_user, 'fb_access_token', $user_data->access_token);
             }
         } else {
             $data = array('user_pass' => $password, 'user_login' => $username, 'user_nicename' => $username, 'user_email' => $user_data->email, 'display_name' => $user_data->name, 'nickname' => $username, 'first_name' => $user_data->first_name, 'last_name' => $user_data->last_name, 'role' => 'subscriber', 'user_status' => '2');
             $new_user = absint(wp_insert_user($data));
             if ($new_user) {
                 update_user_meta($new_user, 'fb_uid', $user_data->id);
                 update_user_meta($new_user, 'link', $user_data->link);
                 update_user_meta($new_user, 'updated_time', $user_data->updated_time);
                 update_user_meta($new_user, 'fb_access_token', $user_data->access_token);
             }
         }
         return $new_user;
     }
     return 0;
 }
Exemple #6
0
function bp_core_screen_signup() {
	global $bp, $wpdb;

	if ( $bp->current_component != BP_REGISTER_SLUG )
		return false;

	/* If the user is logged in, redirect away from here */
	if ( is_user_logged_in() )
		bp_core_redirect( $bp->root_domain );

	/* If signups are disabled, just re-direct */
	if ( !bp_get_signup_allowed() )
		bp_core_redirect( $bp->root_domain );

	$bp->signup->step = 'request-details';

	/* If the signup page is submitted, validate and save */
	if ( isset( $_POST['signup_submit'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_new_signup' );

		require_once( ABSPATH . WPINC . '/registration.php' );

		/* Check the base account details for problems */
		$account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );

		/* If there are errors with account details, set them for display */
		if ( !empty( $account_details['errors']->errors['user_name'] ) )
			$bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];

		if ( !empty( $account_details['errors']->errors['user_email'] ) )
			$bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];

		/* Check that both password fields are filled in */
		if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
			$bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );

		/* Check that the passwords match */
		if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
			$bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );

		$bp->signup->username = $_POST['signup_username'];
		$bp->signup->email = $_POST['signup_email'];

		/* 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] ) )
						$bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
				}

			/* This situation doesn't naturally occur so bounce to website root */
			} else {
				bp_core_redirect( $bp->root_domain );
			}
		}

		/* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
		if ( isset( $_POST['signup_with_blog'] ) ) {
			$active_signup = $bp->site_options['registration'];

			if ( 'blog' == $active_signup || 'all' == $active_signup ) {
				$blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );

				/* If there are errors with blog details, set them for display */
				if ( !empty( $blog_details['errors']->errors['blogname'] ) )
					$bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];

				if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
					$bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
			}
		}

		do_action( 'bp_signup_validate' );

		/* Add any errors to the action for the field in the template for display. */
		if ( !empty( $bp->signup->errors ) ) {
			foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
				add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
		} else {
			$bp->signup->step = 'save-details';

			/* No errors! Let's register those deets. */
			$active_signup = $bp->site_options['registration'];

			if ( 'none' != $active_signup ) {

				/* Let's compact any profile field info into usermeta */
				$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );

				/* Loop through the posted fields formatting any datebox values then add to usermeta */
				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'] );
					}

					if ( !empty( $_POST['field_' . $field_id] ) )
						$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
				}

				/* Store the profile field ID's in usermeta */
				$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];

				/* Hash and store the password */
				$usermeta['password'] = wp_hash_password( $_POST['signup_password'] );

				/* If the user decided to create a blog, save those details to usermeta */
				if ( 'blog' == $active_signup || 'all' == $active_signup ) {
					$usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
				}

				$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );

				/* Finally, sign up the user and/or blog */
				if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
					bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
				else {
					bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
				}

				$bp->signup->step = 'completed-confirmation';
			}

			do_action( 'bp_complete_signup' );
		}

	}

	$bp->avatar_admin->step = 'upload-image';

	/* If user has uploaded a new avatar */
	if ( !empty( $_FILES ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_avatar_upload' );

		$bp->signup->step = 'completed-confirmation';

		if ( bp_core_is_multisite() ) {
			/* Get the activation key */
			if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
				bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
			} else {
				/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
				$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
			}
		} else {
			$user_id = bp_core_get_userid( $_POST['signup_username'] );
			$bp->signup->avatar_dir = wp_hash( $user_id );
		}

		/* Pass the file to the avatar upload handler */
		if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
			$bp->avatar_admin->step = 'crop-image';

			/* Make sure we include the jQuery jCrop file for image cropping */
			add_action( 'wp', 'bp_core_add_jquery_cropper' );
		}
	}

	/* If the image cropping is done, crop the image and save a full/thumb version */
	if ( isset( $_POST['avatar-crop-submit'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_avatar_cropstore' );

		/* Reset the avatar step so we can show the upload form again if needed */
		$bp->signup->step = 'completed-confirmation';
		$bp->avatar_admin->step = 'upload-image';

		if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
			bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
		else
			bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
	}
	bp_core_load_template( 'registration/register' );
}
 /**
  * generated random data
  */
 function test_data()
 {
     set_time_limit(0);
     global $wpdb;
     $users = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1");
     if (is_multisite()) {
         $wpdb->query("DELETE FROM {$wpdb->signups}");
     }
     foreach ($users as $id) {
         bp_core_delete_account($id);
     }
     $ngu = 2;
     #how much only good users
     $ngbu = 2;
     #how much not only good or only bad users
     $nbu = 2;
     #how much only bad users
     $content_types = array('A', 'B', 'C', 'D');
     $bpmod =& bpModeration::get_istance();
     $statuses = array_keys($bpmod->content_stati);
     $n_contents = 20;
     $flags_per_cont = 20;
     # +/- 30%
     $goodusers = array();
     $badusers = array();
     for ($i = 1; $i <= $ngu + $ngbu + $nbu; $i++) {
         $uid = bp_core_signup_user('user' . $i, 'pass', $i . '@foo.bar', array());
         if (is_multisite()) {
             global $wpdb;
             $key_sql = "SELECT activation_key FROM {$wpdb->signups} WHERE user_email = '" . $i . "@foo.bar'";
             $key = $wpdb->get_var($key_sql);
         } else {
             $key = get_user_meta($uid, 'activation_key');
         }
         $uid = bp_core_activate_signup($key);
         is_multisite() and wp_set_password('pass', $uid);
         if ($i <= $ngu + $ngbu) {
             $goodusers[] = $uid;
         }
         if ($i > $ngu) {
             $badusers[] = $uid;
         }
     }
     bpModLoader::load_class('bpModObjContent');
     bpModLoader::load_class('bpModObjFlag');
     for ($i = 1; $i <= $n_contents; $i++) {
         $badu = $badusers[mt_rand(0, count($badusers) - 1)];
         $cont = new bpModObjContent();
         $cont->item_type = $content_types[mt_rand(0, count($content_types) - 1)];
         $cont->item_id = mt_rand(1, 1000000);
         $cont->item_author = $badu;
         $cont->item_date = gmdate("Y-m-d H:i:s", time() - mt_rand(1000000, 2000000));
         $cont->status = $statuses[mt_rand(0, count($statuses) - 1)];
         $cont->save();
         $flags = mt_rand($flags_per_cont * 0.7, $flags_per_cont * 1.3);
         for ($j = 1; $j <= $flags; $j++) {
             while ($badu == ($goodu = $goodusers[mt_rand(0, count($goodusers) - 1)])) {
             }
             $f = new bpModObjFlag();
             $f->content_id = $cont->content_id;
             $f->reporter_id = $goodu;
             $f->date = gmdate("Y-m-d H:i:s", time() - mt_rand(0, 1000000));
             $f->save();
         }
     }
     update_site_option('bp_moderation_test_data_check', 'success');
 }