Example #1
0
    echo "Error!\n";
    echo "Missing mandatory field. Referee email and Referrer email must be present!\n";
    eMember_log_debug('Missing mandatory field. Referee email and Referrer email must be present...', false);
    exit;
}
//Account check for members or the level specified in the shortcode
$referrer_email = $_REQUEST['ref_email'];
$referrer_id = emember_email_exists($referrer_email);
if (!$referrer_id || !emember_registered_email_exists($referrer_email)) {
    echo "Error!\n";
    echo "Referrer email does not exist or must be registered!\n";
    eMember_log_debug('Referrer email does not exist or must be registered...', false);
    exit;
}
$referee_email = $_REQUEST['email'];
$referee_id = emember_email_exists($referee_email);
if (!$referee_id || !emember_registered_email_exists($referee_email)) {
    echo "Error!\n";
    echo "Referee email does not exist or must be registered!\n";
    eMember_log_debug('Referee email does not exist or must be registered...', false);
    exit;
}
// Update the Referee Member
$referee_custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=\'' . $referee_id . '\' AND meta_key=\'custom_field\'');
$referee_data = array();
if ($referee_custom_fields) {
    $referee_data = unserialize($referee_custom_fields->meta_value);
    $referee_data['Good_Karma_Referrer'] = $referrer_email;
    //reference to Good Karma Referrer
    $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . serialize($referee_data) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $referee_id);
    eMember_log_debug('Referee Member data has been updated', true);
Example #2
0
function wp_eMember_add_memebers()
{
    $emember_config = Emember_Config::getInstance();
    global $wpdb;
    $d = WP_EMEMBER_URL . '/images/default_image.gif';
    //If being edited, grab current info
    if (isset($_GET['editrecord']) && $_GET['editrecord'] != '') {
        $theid = $_GET['editrecord'];
        $editingrecord = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $theid);
        $edit_custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=' . $theid . ' AND meta_key="custom_field"');
        $edit_custom_fields = isset($edit_custom_fields->meta_value) ? unserialize($edit_custom_fields->meta_value) : array();
        $editingrecord->more_membership_levels = explode(',', $editingrecord->more_membership_levels);
        $editingrecord = (array) $editingrecord;
        $image_url = null;
        $image_path = null;
        $upload_dir = wp_upload_dir();
        $upload_url = $upload_dir['baseurl'] . '/emember/';
        $upload_path = $upload_dir['basedir'] . '/emember/';
        $use_gravatar = $emember_config->getValue('eMember_use_gravatar');
        if ($use_gravatar) {
            $image_url = WP_EMEMBER_GRAVATAR_URL . "/" . md5(strtolower($editingrecord['email'])) . "?d=" . urlencode($d) . "&s=" . 96;
        } else {
            if (!empty($editingrecord['profile_image'])) {
                $image_url = $upload_url . $editingrecord['profile_image'];
                $image_path = $theid;
            } else {
                $image_path = "";
                $image_url = WP_EMEMBER_URL . '/images/default_image.gif';
            }
        }
    }
    if (isset($_POST['Submit'])) {
        global $wpdb;
        include_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash(8, TRUE);
        $post_editedrecord = esc_sql(isset($_POST['editedrecord']) ? $_POST['editedrecord'] : "");
        $fields = array();
        $fields['flags'] = 0;
        if ($emember_config->getValue('eMember_enable_secondary_membership')) {
            $fields['more_membership_levels'] = implode(',', empty($_POST['more_membership_levels']) ? array() : $_POST['more_membership_levels']);
        }
        $fields["user_name"] = $_POST["user_name"];
        $fields["first_name"] = $_POST["first_name"];
        $fields["last_name"] = $_POST["last_name"];
        $fields["company_name"] = $_POST["company_name"];
        $fields["member_since"] = $_POST["member_since"];
        $fields["membership_level"] = $_POST["membership_level"];
        $fields["account_state"] = $_POST["account_state"];
        $fields["email"] = $_POST["email"];
        $fields["phone"] = $_POST["phone"];
        $fields["address_street"] = $_POST["address_street"];
        $fields["address_city"] = $_POST["address_city"];
        $fields["address_state"] = $_POST["address_state"];
        $fields["address_zipcode"] = $_POST["address_zipcode"];
        $fields["home_page"] = $_POST["home_page"];
        $fields["country"] = $_POST["country"];
        $fields["gender"] = $_POST["gender"];
        $fields["referrer"] = $_POST["referrer"];
        $fields["subscription_starts"] = $_POST["subscription_starts"];
        $fields['last_accessed_from_ip'] = get_real_ip_addr();
        $fields["notes"] = $_POST['notes'];
        $wp_user_info = array();
        $wp_user_info['user_nicename'] = implode('-', explode(' ', $_POST['user_name']));
        $wp_user_info['display_name'] = $_POST['user_name'];
        $wp_user_info['user_email'] = $_POST['email'];
        $wp_user_info['nickname'] = $_POST['user_name'];
        $wp_user_info['first_name'] = $_POST['first_name'];
        $wp_user_info['last_name'] = $_POST['last_name'];
        if ($post_editedrecord == '') {
            $fields['user_name'] = esc_sql($_POST['user_name']);
            $wp_user_info['user_login'] = $_POST['user_name'];
            // Add the record to the DB
            include_once 'emember_validator.php';
            $validator = new Emember_Validator();
            $validator->add(array('value' => $fields['user_name'], 'label' => 'User Name', 'rules' => array('user_required', 'user_name', 'user_unavail', 'user_minlength')));
            $validator->add(array('value' => $_POST['password'], 'repeat' => $_POST['retype_password'], 'label' => 'Password', 'rules' => array('pass_required', 'pass_mismatch')));
            $validator->add(array('value' => $fields['email'], 'label' => 'Email', 'rules' => array('email_required', 'email_unavail')));
            $messages = $validator->validate();
            if (count($messages) > 0) {
                echo '<span class="emember_error">' . implode('<br/>', $messages) . '</span>';
                $editingrecord = $_POST;
            } else {
                $password = $wp_hasher->HashPassword($_POST['password']);
                $fields['password'] = esc_sql($password);
                $ret = dbAccess::insert(WP_EMEMBER_MEMBERS_TABLE_NAME, $fields);
                $lastid = $wpdb->insert_id;
                $should_create_wp_user = $emember_config->getValue('eMember_create_wp_user');
                if ($should_create_wp_user) {
                    $role_names = array(1 => 'Administrator', 2 => 'Editor', 3 => 'Author', 4 => 'Contributor', 5 => 'Subscriber');
                    $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $fields['membership_level'] . "'");
                    $wp_user_info['role'] = $membership_level_resultset->role;
                    $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
                    //$wp_user_id = wp_create_user($_POST['user_name'], $_POST['password'], $_POST['email']);
                    $wp_user_id = eMember_wp_create_user($_POST['user_name'], $_POST['password'], $_POST['email'], $wp_user_info);
                    //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
                }
                ///custom field insert
                if (isset($_POST['emember_custom'])) {
                    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $lastid . ',"custom_field",' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\')');
                }
                if ($ret === false) {
                    $_SESSION['flash_message'] = '<div id="message" style = "color:red;" class="updated fade"><p>Couldn\'t create new member.</p></div>';
                } else {
                    if (isset($_POST['uploaded_profile_img'])) {
                        $upload_dir = wp_upload_dir();
                        $upload_path = $upload_dir['basedir'];
                        $upload_path .= '/emember/';
                        $ext = explode('.', $_POST['uploaded_profile_img']);
                        rename($upload_path . $_POST['uploaded_profile_img'], $upload_path . $lastid . '.' . $ext[1]);
                    }
                    $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>Member &quot;' . $fields['user_name'] . '&quot; created.</p></div>';
                    //Notify the newly created member if specified in the settings
                    if ($emember_config->getValue('eMember_email_notification_for_manual_member_add')) {
                        $login_link = $emember_config->getValue('login_page_url');
                        $member_email_address = $_POST['email'];
                        $subject_rego_complete = $emember_config->getValue('eMember_email_subject_rego_complete');
                        $body_rego_complete = $emember_config->getValue('eMember_email_body_rego_complete');
                        $from_address = $emember_config->getValue('senders_email_address');
                        $headers = 'From: ' . $from_address . "\r\n";
                        $curr_member_id = $lastid;
                        $additional_params = array('password' => $_POST['password'], 'login_link' => $login_link);
                        $email_body1 = emember_dynamically_replace_member_details_in_message($curr_member_id, $body_rego_complete, $additional_params);
                        wp_mail($member_email_address, $subject_rego_complete, $email_body1, $headers);
                    }
                    //Create the corresponding affliate account if specified in the settings
                    if ($emember_config->getValue('eMember_auto_affiliate_account')) {
                        eMember_handle_affiliate_signup($_POST['user_name'], $_POST['password'], $_POST['first_name'], $_POST['last_name'], $_POST['email'], '');
                    }
                    /*                         * * Signup the member to Autoresponder List (Autoresponder integration) ** */
                    eMember_log_debug("===> Performing autoresponder signup if needed (member was added via admin dashboard) <===", true);
                    $membership_level_id = $_POST["membership_level"];
                    $firstname = $_POST['first_name'];
                    $lastname = $_POST['last_name'];
                    $emailaddress = $_POST['email'];
                    eMember_level_specific_autoresponder_signup($membership_level_id, $firstname, $lastname, $emailaddress);
                    eMember_global_autoresponder_signup($firstname, $lastname, $emailaddress);
                    /*                         * * end of autoresponder integration ** */
                    echo '<script type="text/javascript">window.location = "admin.php?page=wp_eMember_manage";</script>';
                }
            }
        } else {
            if (isset($_POST['emember_custom'])) {
                $custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=' . $post_editedrecord . ' AND meta_key=\'custom_field\'');
                if ($custom_fields) {
                    $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $post_editedrecord);
                } else {
                    $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $post_editedrecord . ',"custom_field",' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\')');
                }
            } else {
                $wpdb->query('DELETE FROM ' . WP_EMEMBER_MEMBERS_META_TABLE . '  WHERE meta_key = \'custom_field\' AND  user_id=' . $post_editedrecord);
            }
            $editingrecord = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $post_editedrecord);
            // Update the member info
            $member_id = esc_sql($_POST['editedrecord']);
            $wp_user_id = username_exists($fields['user_name']);
            $wp_email_owner = email_exists($fields['email']);
            $emember_email_owner = emember_email_exists($fields['email']);
            if (empty($fields['user_name']) || $fields['user_name'] != $editingrecord->user_name) {
                echo '<div id="message" class="updated fade"><p>User Name Cannot Be Changed!</p></div>';
            } else {
                if (empty($fields['email'])) {
                    echo '<div id="message" class="updated fade"><p>Email Field is Empty!</p></div>';
                } else {
                    if ($wp_email_owner && $wp_user_id != $wp_email_owner || $emember_email_owner && $member_id != $emember_email_owner) {
                        echo '<div id="message" class="updated fade"><p>Email ID &quot;' . $fields['email'] . '&quot; is already registered to a user!</p></div>';
                    } else {
                        $update_possible = true;
                        if (!empty($_POST['password'])) {
                            if ($_POST['password'] === $_POST['retype_password']) {
                                $password = $wp_hasher->HashPassword($_POST['password']);
                                $fields['password'] = esc_sql($password);
                                $wp_user_info['user_pass'] = $_POST['password'];
                            } else {
                                $update_possible = false;
                                echo '<div id="message" class="updated fade"><p>Password does\'t match!</p></div>';
                            }
                        }
                        if ($update_possible) {
                            $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id = ' . $member_id, $fields);
                            if ($fields["membership_level"] != $editingrecord->membership_level) {
                                do_action('emember_membership_changed', array('member_id' => $editingrecord->member_id, 'from_level' => $editingrecord->membership_level, 'to_level' => $fields["membership_level"]));
                            }
                            if ($wp_user_id && !is_wp_error($wp_user_id)) {
                                $wp_user_info['ID'] = $wp_user_id;
                                wp_update_user($wp_user_info);
                                if (($editingrecord->flags & 1) != 1) {
                                    $cond = " id='" . $fields['membership_level'] . "'";
                                    $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, $cond);
                                    update_wp_user_Role($wp_user_id, $membership_level_resultset->role);
                                    //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
                                }
                            }
                            if ($ret === false) {
                                $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>' . __('Member', 'wp_eMember') . ' &quot;' . $fields['user_name'] . '&quot; ' . __('Update Failed.', 'wp_eMember') . '</p></div>';
                            } else {
                                $_SESSION['flash_message'] = '<div id="message" class="updated fade"><p>' . __('Member', 'wp_eMember') . ' &quot;' . $fields['user_name'] . '&quot; ' . __('updated.', 'wp_eMember') . '</p></div>';
                                if (isset($_POST['account_status_change'])) {
                                    $from_address = $emember_config->getValue('senders_email_address');
                                    $headers = 'From: ' . $from_address . "\r\n";
                                    $subject = $_POST['notificationmailhead'];
                                    $member_email_address = $_POST['email'];
                                    $login_link = $emember_config->getValue('login_page_url');
                                    $additional_params = array('password' => $_POST['password'], 'login_link' => $login_link);
                                    $curr_member_id = $post_editedrecord;
                                    $email_body = emember_dynamically_replace_member_details_in_message($curr_member_id, $_POST['notificationmailbody'], $additional_params);
                                    wp_mail($member_email_address, $subject, $email_body, $headers);
                                    $emember_config->setValue('eMember_status_change_email_body', $_POST['notificationmailbody']);
                                    $emember_config->setValue('eMember_status_change_email_subject', $_POST['notificationmailhead']);
                                    $emember_config->saveConfig();
                                }
                                echo '<script type="text/javascript">window.location = "admin.php?page=wp_eMember_manage";</script>';
                            }
                        }
                    }
                }
            }
            $editingrecord = (array) $editingrecord;
        }
    }
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    include_once 'views/add_member_view.php';
}
Example #3
0
}
if (isset($_REQUEST['gender'])) {
    $fields['gender'] = strip_tags($_REQUEST['gender']);
}
if (isset($_REQUEST['company_name'])) {
    $fields['company_name'] = strip_tags($_REQUEST['company_name']);
}
if (!empty($_REQUEST['password'])) {
    $password = $wp_hasher->HashPassword(strip_tags($_REQUEST['password']));
    $fields['password'] = $password;
}
//Level ID to change (if any)
$membership_level_id = strip_tags(isset($_REQUEST['membership_level_id']) ? $_REQUEST['membership_level_id'] : "");
if (!empty($fields['email'])) {
    //Check to make sure the new email is not taken already or blocked
    if (emember_wp_email_exists($fields['email']) || emember_email_exists($fields['email'])) {
        echo "Error!\n";
        echo "Email address already exists.";
        eMember_log_debug('Email address already used...', false);
        exit;
    }
    if (is_blocked_email($fields['email'])) {
        echo "Error!\n";
        echo "Email address entered is blocked.";
        eMember_log_debug("Blocked email address used. This request will fail.", false);
        exit;
    }
}
//Update the corresponding WP User object if needed
$resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . $member_id);
$wp_user_id = username_exists($resultset->user_name);
Example #4
0
function emember_update_profile_init()
{
    if (isset($_POST['eMember_update_profile'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'emember-update-profile-nonce')) {
            eMember_log_debug("Profile update nonce check failed ", true);
            die("Security check failed on profile update");
        }
        global $wpdb;
        $emember_config = Emember_Config::getInstance();
        include_once ABSPATH . WPINC . '/class-phpass.php';
        $resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . esc_sql($_POST['member_id']));
        $wp_user_id = username_exists($resultset->user_name);
        $updatable = true;
        if (isset($_POST['wp_emember_email'])) {
            $emmber_email_owner = emember_email_exists($_POST['wp_emember_email']);
            $wp_email_owner = email_exists($_POST['wp_emember_email']);
            if (!is_email($_POST['wp_emember_email'])) {
                $_POST['eMember_profile_update_result'] = EMEMBER_EMAIL_INVALID;
                $updatable = false;
            } else {
                if ($wp_email_owner && $wp_email_owner != $wp_user_id || $emmber_email_owner && $emmber_email_owner != $_POST['member_id']) {
                    $_POST['eMember_profile_update_result'] = '<span class="emember_error">' . EMEMBER_EMAIL_UNAVAIL . ' </span>';
                    $updatable = false;
                }
            }
        }
        if ($_POST['wp_emember_pwd'] != $_POST['wp_emember_pwd_r']) {
            $_POST['eMember_profile_update_result'] = '<span class="emember_error">' . EMEMBER_PASSWORD_MISMATCH . '</span>';
            $updatable = false;
        }
        if ($updatable) {
            $wp_hasher = new PasswordHash(8, TRUE);
            $fields = array();
            if (isset($_POST['wp_emember_title'])) {
                $fields['title'] = strip_tags($_POST['wp_emember_title']);
            }
            if (isset($_POST['wp_emember_firstname'])) {
                $fields['first_name'] = strip_tags($_POST['wp_emember_firstname']);
            }
            if (isset($_POST['wp_emember_lastname'])) {
                $fields['last_name'] = strip_tags($_POST['wp_emember_lastname']);
            }
            if (isset($_POST['wp_emember_email'])) {
                $fields['email'] = strip_tags($_POST['wp_emember_email']);
            }
            if (isset($_POST['wp_emember_phone'])) {
                $fields['phone'] = strip_tags($_POST['wp_emember_phone']);
            }
            if (isset($_POST['wp_emember_street'])) {
                $fields['address_street'] = strip_tags($_POST['wp_emember_street']);
            }
            if (isset($_POST['wp_emember_city'])) {
                $fields['address_city'] = strip_tags($_POST['wp_emember_city']);
            }
            if (isset($_POST['wp_emember_state'])) {
                $fields['address_state'] = strip_tags($_POST['wp_emember_state']);
            }
            if (isset($_POST['wp_emember_zipcode'])) {
                $fields['address_zipcode'] = strip_tags($_POST['wp_emember_zipcode']);
            }
            if (isset($_POST['wp_emember_country'])) {
                $fields['country'] = strip_tags($_POST['wp_emember_country']);
            }
            if (isset($_POST['wp_emember_gender'])) {
                $fields['gender'] = strip_tags($_POST['wp_emember_gender']);
            }
            if (isset($_POST['wp_emember_company_name'])) {
                $fields['company_name'] = strip_tags($_POST['wp_emember_company_name']);
            }
            if (!empty($_POST['wp_emember_pwd'])) {
                $password = $wp_hasher->HashPassword(strip_tags($_POST['wp_emember_pwd']));
                $fields['password'] = $password;
            }
            if ($wp_user_id) {
                $wp_user_info = array();
                $wp_user_info['first_name'] = strip_tags(isset($_POST['wp_emember_firstname']) ? $_POST['wp_emember_firstname'] : "");
                $wp_user_info['last_name'] = strip_tags(isset($_POST['wp_emember_lastname']) ? $_POST['wp_emember_lastname'] : "");
                $wp_user_info['user_email'] = strip_tags(isset($_POST['wp_emember_email']) ? $_POST['wp_emember_email'] : "");
                $wp_user_info['ID'] = $wp_user_id;
                if (!empty($_POST['wp_emember_pwd'])) {
                    $wp_user_info['user_pass'] = $_POST['wp_emember_pwd'];
                }
                wp_update_user($wp_user_info);
            }
            $_POST['member_id'] = strip_tags($_POST['member_id']);
            if (count($fields) > 0) {
                $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id =' . esc_sql($_POST['member_id']), $fields);
            }
            if (isset($_POST['emember_custom'])) {
                $custom_fields = dbAccess::find(WP_EMEMBER_MEMBERS_META_TABLE, ' user_id=' . esc_sql($_POST['member_id']) . ' AND meta_key=\'custom_field\'');
                if ($custom_fields) {
                    $ret = $wpdb->query('UPDATE ' . WP_EMEMBER_MEMBERS_META_TABLE . ' SET meta_value =' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\' WHERE meta_key = \'custom_field\' AND  user_id=' . $_POST['member_id']);
                } else {
                    $ret = $wpdb->query("INSERT INTO " . WP_EMEMBER_MEMBERS_META_TABLE . '( user_id, meta_key, meta_value ) VALUES(' . $_POST['member_id'] . ',"custom_field",' . '\'' . addslashes(serialize($_POST['emember_custom'])) . '\')');
                }
            } else {
                $ret = $wpdb->query('DELETE FROM ' . WP_EMEMBER_MEMBERS_META_TABLE . '  WHERE meta_key = \'custom_field\' AND  user_id=' . esc_sql($_POST['member_id']));
            }
            if ($ret === false) {
                $_POST['eMember_profile_update_result'] = 'Failed';
            } else {
                $edit_profile_page = $emember_config->getValue('eMember_profile_edit_page');
                $profile_updated_msg = '<div class="emember_profile_updated_msg">';
                $profile_updated_msg .= EMEMBER_PROFILE_UPDATED;
                if (!empty($edit_profile_page)) {
                    $profile_updated_msg .= ' <a href="' . $edit_profile_page . '">' . EMEMBER_EDIT_YOUR_PROFILE_AGAIN . '</a>';
                }
                $profile_updated_msg .= '</div>';
                $_POST['eMember_profile_update_result'] = $profile_updated_msg;
                do_action('eMember_profile_updated', $fields, $custom_fields);
                //Update the affiliate end if using the auto affiliate feature
                eMember_handle_affiliate_profile_update();
            }
        }
    }
}
Example #5
0
$email = strip_tags($_REQUEST['email']);
$first_name = strip_tags($_REQUEST['first_name']);
$last_name = strip_tags($_REQUEST['last_name']);
//optional data
$username = strip_tags($_REQUEST['username']);
$password = strip_tags($_REQUEST['password']);
$membership_level_name = strip_tags($_REQUEST['membership_level_name']);
$membership_level_id = strip_tags($_REQUEST['membership_level_id']);
eMember_log_debug('Received data:' . $email . '|' . $first_name . '|' . $last_name . '|' . $membership_level_name . '|' . $membership_level_id . '|' . $username . '|' . $password, true);
if (emember_wp_username_exists($username) || emember_username_exists($username)) {
    echo "Error!\n";
    echo "Username already in use.";
    eMember_log_debug('That username is already in use', false);
    exit;
}
if (emember_wp_email_exists($email) || emember_email_exists($email)) {
    echo "Error!\n";
    echo "Email address already exists.";
    eMember_log_debug('Email address already used...', false);
    exit;
}
if (is_blocked_email($email)) {
    echo "Error!\n";
    echo "Email address entered is forbidden..";
    eMember_log_debug("Forbidden email address used...", false);
    exit;
}
if (empty($membership_level_id)) {
    if (empty($membership_level_name)) {
        $membership_level_id = $emember_config->getValue('eMember_free_membership_level_id');
    } else {
function emember_process_free_rego_with_confirm_form()
{
    global $wpdb;
    $emember_config = Emember_Config::getInstance();
    $error_message = "";
    $enable_recaptcha = $emember_config->getValue('emember_enable_recaptcha');
    if (isset($_POST['eMember_Register_with_confirmation'])) {
        $_POST['wp_emember_aemail'] = strip_tags($_POST['wp_emember_aemail']);
        $valid = true;
        if (empty($_POST['wp_emember_aemail'])) {
            $valid = false;
        }
        if ($emember_config->getValue('eMember_reg_firstname') && $emember_config->getValue('eMember_reg_firstname_required')) {
            if (empty($_POST['wp_emember_afirstname'])) {
                $valid = false;
            } else {
                $_POST['wp_emember_afirstname'] = strip_tags($_POST['wp_emember_afirstname']);
            }
        } else {
            if ($emember_config->getValue('eMember_reg_firstname')) {
                $_POST['wp_emember_afirstname'] = strip_tags($_POST['wp_emember_afirstname']);
            } else {
                $_POST['wp_emember_afirstname'] = "";
            }
        }
        if ($emember_config->getValue('eMember_reg_lastname') && $emember_config->getValue('eMember_reg_lastname_required')) {
            if (empty($_POST['wp_emember_alastname'])) {
                $valid = false;
            } else {
                $_POST['wp_emember_alastname'] = strip_tags($_POST['wp_emember_alastname']);
            }
        } else {
            if ($emember_config->getValue('eMember_reg_lastname')) {
                $_POST['wp_emember_alastname'] = strip_tags($_POST['wp_emember_alastname']);
            } else {
                $_POST['wp_emember_alastname'] = "";
            }
        }
        if ($valid) {
            eMember_log_debug("Processing signup request of free membership with email confirmation for: " . $_POST['wp_emember_aemail'], true);
            if ($enable_recaptcha) {
                if (isset($_POST["recaptcha_response_field"])) {
                    $_POST["recaptcha_challenge_field"] = strip_tags($_POST["recaptcha_challenge_field"]);
                    $_POST["recaptcha_response_field"] = strip_tags($_POST["recaptcha_response_field"]);
                    $recaptcha_private_key = $emember_config->getValue('emember_recaptcha_private');
                    $resp = recaptcha_check_answer($recaptcha_private_key, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
                    if (!$resp->is_valid) {
                        $recaptcha_error = $resp->error;
                        $error_message = "<p class='emember_error'><strong>" . EMEMBER_CAPTCHA_VERIFICATION_FAILED . "</strong></p>";
                        $emember_config->set_stacked_message('emember_free_registration_confirm_captcha', $recaptcha_error);
                        $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'error', 'message' => $error_message));
                    }
                } else {
                    $output .= '<span class="emember_error">reCAPTCHA&trade; service encountered error. please Contact Admin. </span>';
                    $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'warning', 'message' => $output));
                }
            }
            if (!$enable_recaptcha || $resp->is_valid) {
                $valid_captcha = apply_filters('emember_captcha_varify', true);
                eMember_log_debug("reCAPTCH is valid... creating member account for: " . $_POST['wp_emember_aemail'], true);
                // create new member account and send the registration completion email
                if (emember_email_exists($_POST['wp_emember_aemail'])) {
                    $error_message = "<p class='emember_error'><strong>" . EMEMBER_EMAIL_TAKEN . "</strong></p>";
                    $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'error', 'message' => $error_message));
                } else {
                    if (!$valid_captcha) {
                        $error_message = "<p class='emember_error'><strong>" . EMEMBER_CAPTCHA_FAILED . "</strong></p>";
                        $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'error', 'message' => $error_message));
                    } else {
                        $fields = array();
                        $fields['user_name'] = '';
                        $fields['password'] = '';
                        $fields['first_name'] = $_POST['wp_emember_afirstname'];
                        $fields['last_name'] = $_POST['wp_emember_alastname'];
                        $fields['email'] = $_POST['wp_emember_aemail'];
                        $fields['last_accessed_from_ip'] = get_real_ip_addr();
                        $fields['member_since'] = date("Y-m-d");
                        //$fields['subscription_starts'] = date("Y-m-d");
                        if (isset($_POST['wp_emember_membership_level']) && !empty($_POST['wp_emember_membership_level'])) {
                            $fields['membership_level'] = strip_tags($_POST['wp_emember_membership_level']);
                        } else {
                            $fields['membership_level'] = $emember_config->getValue('eMember_free_membership_level_id');
                        }
                        //$fields['initial_membership_level'] = $emember_config->getValue('eMember_free_membership_level_id');
                        $eMember_manually_approve_member_registration = $emember_config->getValue('eMember_manually_approve_member_registration');
                        if ($eMember_manually_approve_member_registration) {
                            $fields['account_state'] = 'pending';
                        } else {
                            $fields['account_state'] = 'active';
                        }
                        $reg_code = uniqid();
                        //rand(10, 1000);
                        $md5_code = md5($reg_code);
                        $fields['reg_code'] = $reg_code;
                        $data_formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s');
                        //				$ret = dbAccess::insert(WP_EMEMBER_MEMBERS_TABLE_NAME, $fields);
                        $wpdb->insert(WP_EMEMBER_MEMBERS_TABLE_NAME, $fields, $data_formats);
                        $resultset = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' reg_code=\'' . $reg_code . '\'');
                        $id = $resultset->member_id;
                        $separator = '?';
                        $url = $emember_config->getValue('eMember_registration_page');
                        if (strpos($url, '?') !== false) {
                            $separator = '&';
                        }
                        $reg_url = $url . $separator . 'member_id=' . $id . '&code=' . $md5_code;
                        $subject = $emember_config->getValue('eMember_email_subject');
                        $body = $emember_config->getValue('eMember_email_body');
                        $from_address = $emember_config->getValue('senders_email_address');
                        $tags = array("{first_name}", "{last_name}", "{reg_link}");
                        $vals = array($_POST['wp_emember_afirstname'], $_POST['wp_emember_alastname'], $reg_url);
                        $email_body = str_replace($tags, $vals, $body);
                        $headers = 'From: ' . $from_address . "\r\n";
                        $to_email = strip_tags($_POST['wp_emember_aemail']);
                        eMember_log_debug("Sending registration completion email for free registration with confirmation to: " . $to_email, true);
                        wp_mail($to_email, $subject, $email_body, $headers);
                        $chk_mail_msg = '<div class="emember_check_email_msg">' . EMEMBER_PLEASE_CHECK_YOUR_INBOX . '<br />' . EMEMBER_EMAIL . ': ' . $to_email . '</div>';
                        $output = apply_filters('emember_registration_check_email_msg', $chk_mail_msg);
                        eMember_log_debug("Free registration with confirmation complete.", true);
                        $_SESSION['emember_dsc_nonce'] = $_REQUEST['emember_dsc_nonce'];
                        $_SESSION['emember_frwc_msg'] = $output;
                        $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'success', 'message' => $output));
                    }
                }
            }
        } else {
            $error_message = "<p class='emember_error'><strong>" . EMEMBER_YOU_MUST_FILL_IN_ALL_THE_FIELDS . "</strong></p>";
            $emember_config->set_stacked_message('emember_free_registration_confirm', array('type' => 'error', 'message' => $error_message));
        }
        $_SESSION['emember_frwc_msg'] = $error_message;
    }
}