function wp_eMember_admin_functions_general_menu()
{
    $emember_config = Emember_Config::getInstance();
    if (isset($_POST['generate_registration_link'])) {
        $errorMsg = "";
        $eMember_member_id = (string) $_POST["eMember_member_id"];
        $member_record = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=\'' . $eMember_member_id . '\'');
        if ($member_record) {
            $md5_code = md5($member_record->reg_code);
            $separator = '?';
            $url = get_option('eMember_registration_page');
            if (empty($url)) {
                $errorMsg .= "Error! You need to specify the registration URL in the pages/forms settings menu of this plugin.";
            } else {
                if (strpos($url, '?') !== false) {
                    $separator = '&';
                }
                $reg_url = $url . $separator . 'member_id=' . $eMember_member_id . '&code=' . $md5_code;
            }
        } else {
            $errorMsg .= "Error! Could not find the member ID in the database. Please double check the member ID value.";
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = 'Registration Link Generated! Your customer can complete his/her membership registration by going to the generated link.';
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['generate_and_send_registration_link'])) {
        $errorMsg = "";
        $eMember_member_id = (string) $_POST["eMember_member_id"];
        $member_record = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=\'' . $eMember_member_id . '\'');
        if ($member_record) {
            $md5_code = md5($member_record->reg_code);
            $separator = '?';
            $url = get_option('eMember_registration_page');
            if (empty($url)) {
                $errorMsg .= "<br />You need to specify the registration URL in the pages settings menu of this plugin.";
            } else {
                if (strpos($url, '?') !== false) {
                    $separator = '&';
                }
                $reg_url = $url . $separator . 'member_id=' . $eMember_member_id . '&code=' . $md5_code;
            }
            $email = $member_record->email;
            $subject = get_option('eMember_email_subject');
            $body = get_option('eMember_email_body');
            $from_address = get_option('senders_email_address');
            $tags = array("{first_name}", "{last_name}", "{reg_link}");
            $vals = array($member_record->first_name, $member_record->last_name, $reg_url);
            $email_body = str_replace($tags, $vals, $body);
            $headers = 'From: ' . $from_address . "\r\n";
            wp_mail($email, $subject, $email_body, $headers);
        } else {
            $errorMsg .= "<br />Could not find the member ID in the database";
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = "Member registration completion email successfully sent to:" . $email;
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['generate_and_send_registration_link_bulk'])) {
        $errorMsg = "";
        global $wpdb;
        $query = "SELECT member_id,reg_code,first_name,last_name FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " WHERE user_name = ''";
        $member_records = $wpdb->get_results($query);
        if ($member_records) {
            foreach ($member_records as $member_record) {
                $md5_code = md5($member_record->reg_code);
                $separator = '?';
                $url = get_option('eMember_registration_page');
                if (empty($url)) {
                    $errorMsg .= "<br />You need to specify the registration URL in the pages settings menu of this plugin.";
                    break;
                } else {
                    if (strpos($url, '?') !== false) {
                        $separator = '&';
                    }
                    $reg_url = $url . $separator . 'member_id=' . $member_record->member_id . '&code=' . $md5_code;
                }
                $email = $member_record->email;
                $subject = get_option('eMember_email_subject');
                $body = get_option('eMember_email_body');
                $from_address = get_option('senders_email_address');
                $tags = array("{first_name}", "{last_name}", "{reg_link}");
                $vals = array($member_record->first_name, $member_record->last_name, $reg_url);
                $email_body = str_replace($tags, $vals, $body);
                $headers = 'From: ' . $from_address . "\r\n";
                wp_mail($email, $subject, $email_body, $headers);
            }
        }
        $message = "";
        if (!empty($errorMsg)) {
            $message = $errorMsg;
        } else {
            $message = "Member registration completion email successfully sent.";
        }
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    if (isset($_POST['emem_to_wp'])) {
        global $wpdb;
        $member_table = WP_EMEMBER_MEMBERS_TABLE_NAME;
        $ret_member_db = $wpdb->get_results("SELECT * FROM {$member_table} ", OBJECT);
        foreach ($ret_member_db as $emember) {
            $emember->user_name = trim($emember->user_name);
            if (empty($emember->user_name)) {
                continue;
            }
            if (strtolower($emember->user_name) === "admin") {
                continue;
            }
            if (!username_exists($emember->user_name)) {
                $role_names = array(1 => 'Administrator', 2 => 'Editor', 3 => 'Author', 4 => 'Contributor', 5 => 'Subscriber');
                $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $emember->membership_level . "'");
                $wp_user_info = array();
                $wp_user_info['user_nicename'] = implode('-', explode(' ', $emember->user_name));
                $wp_user_info['display_name'] = $emember->user_name;
                $wp_user_info['nickname'] = $emember->user_name;
                $wp_user_info['first_name'] = $emember->first_name;
                $wp_user_info['last_name'] = $emember->last_name;
                $wp_user_info['role'] = $role_names[$membership_level_resultset->role];
                $wp_user_info['user_registered'] = date('Y-m-d H:i:s');
                //$wp_user_id = wp_create_user($emember->user_name, 'changeme', $emember->email);
                $wp_user_id = eMember_wp_create_user($emember->user_name, 'changeme', $emember->email);
                $wp_user_info['ID'] = $wp_user_id;
                wp_update_user($wp_user_info);
                //$wpdb->query("UPDATE  $wpdb->users set user_pass = \'" . $emember->password . '\' WHERE ID = ' . $wp_user_id);
                $user_info = get_userdata($wp_user_id);
                $user_cap = is_array($user_info->wp_capabilities) ? array_keys($user_info->wp_capabilities) : array();
                if (!in_array('administrator', $user_cap)) {
                    update_wp_user_Role($wp_user_id, $membership_level_resultset->role);
                }
            }
        }
        echo '<div id="message" class="updated fade"><p>WordPress user account creation complete!</p></div>';
    }
    if (isset($_POST['emem_when_wp'])) {
        $emember_config->setValue('eMember_enable_emem_when_wp', $_POST['eMember_enable_emem_when_wp']);
        $emember_config->setValue('eMember_emem_when_wp_default_level', $_POST['eMember_emem_when_wp_default_level']);
        $emember_config->setValue('eMember_emem_when_wp_default_acstatus', $_POST['eMember_emem_when_wp_default_acstatus']);
        $emember_config->saveConfig();
        echo '<div id="message" class="updated fade"><p>Auto Member Account Creation Settings Saved!</p></div>';
    }
    if (isset($_POST['emember_management_permission_update'])) {
        $emember_config->setValue('emember_management_permission', $_POST['emember_management_permission']);
        $emember_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Management permission setting updated!';
        echo '</strong></p></div>';
    }
    ?>

            <div class="postbox">
                <h3><label for="title">Generate a Registration Completion link</label></h3>
                <div class="inside">
                    You can manually generate a registration completion link here and give it to your customer if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                        <table width="100%" border="0" cellspacing="0" cellpadding="6">
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Member ID: </strong>
                                </td><td align="left">
                                    <input name="eMember_member_id" type="text" size="5" value="<?php 
    echo isset($eMember_member_id) ? $eMember_member_id : "";
    ?>
" />
                                    <br /><i>(i) Enter the member ID (you can get the member ID from the members menu).</i><br /><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right">
                                </td><td align="left">
                                    <input type="submit" name="generate_registration_link" value="<?php 
    _e('Generate Link');
    ?>
 &raquo;" />
                                    <br /><i>(ii) Hit the "Generate Link" button.</i><br /><br />
                                </td></tr>
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Registration Link: </strong>
                                </td><td align="left">
                                    <textarea name="wp_eStore_rego_link" rows="3" cols="80"><?php 
    echo isset($reg_url) ? $reg_url : "";
    ?>
</textarea>
                                    <br /><i>This is the registration completion link.</i><br />
                                </td></tr>
                        </table>
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">Generate and Email the Registration Completion link</label></h3>
                <div class="inside">
                    You can generate a registration completion link and email it to your customer in one go. This can be useful if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

                        <table width="100%" border="0" cellspacing="0" cellpadding="6">
                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Member ID: </strong>
                                </td><td align="left">
                                    <input name="eMember_member_id" type="text" size="5" value="<?php 
    echo isset($eMember_member_id) ? $eMember_member_id : "";
    ?>
" />
                                    <br /><i>(i) Enter the member ID (you can get the member ID from the members menu).</i><br /><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right">
                                </td><td align="left">
                                    <input type="submit" name="generate_and_send_registration_link" value="<?php 
    _e('Generate & Email Link');
    ?>
 &raquo;" />
                                    <br /><i>(ii) Hit the "Generate & Email Link" button.</i><br /><br />
                                </td></tr>

                        </table>
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">Generate and Email the Registration Completion link (Bulk Mode)</label></h3>
                <div class="inside">

                    You can generate registration completion link and email it to all your members that are still waiting to complete the registration. This can be useful if they have missed the email that was automatically sent out to them after the payment.<br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <input type="submit" name="generate_and_send_registration_link_bulk" value="<?php 
    _e('Generate & Email Link in Bulk');
    ?>
 &raquo;" />
                        <br /><i>Hit the "Generate & Email Link in Bulk" button.</i><br /><br />
                    </form>
                </div></div>



            <div class="postbox">
                <h3><label for="title">Create WordPress User Account for the members that do not have one</label></h3>
                <div class="inside">
                    <strong>If you have a lot of eMember members that do not have a corresponding WordPress user account and for some reason you wanted to create WordPress user account for them then use this option.</strong>
                    <br /><br />
                    &raquo; When you use this option the plugin will create wordpress user accounts for every eMember user that does not have a corresponding WordPress account already.
                    <br />
                    &raquo; The WordPress user accounts will be created with the same details from eMember but the password will be set to "changeme" (The user will have to change the password to their liking).
                    <br />
                    &raquo; Why? The password is kept in the database using an one way encryption so nobody except the member knows what the real password is.
                    <br /><br />
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <input type="submit" name="emem_to_wp" value="<?php 
    _e('Create WP account for eMember users');
    ?>
 &raquo;" />
                    </form>
                </div></div>
            <div class="postbox">
                <h3><label for="title">Automatically Create eMember Account When a WordPress User Account is Created.</label></h3>
                <div class="inside">

                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <table width="100%" border="0" cellspacing="0" cellpadding="6">

                            <tr valign="top"><td width="25%" align="right">
                                    <strong>Enable this Feature: </strong>
                                </td><td align="left">
                                    <input name="eMember_enable_emem_when_wp" type="checkbox" <?php 
    echo $emember_config->getValue('eMember_enable_emem_when_wp');
    ?>
 value="checked='checked'" />
                                    <br /><i>When this feature is enabled, an eMember account will be created for every WP User account that gets created on this site.</i><br />
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right"><strong>Default Membership Level: </strong></td>
                                <td align="left">
                                    <select name="eMember_emem_when_wp_default_level">
                                        <?php 
    $all_levels = dbAccess::findAll(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, ' id != 1 ', ' id DESC ');
    $selected_level = $emember_config->getValue('eMember_emem_when_wp_default_level');
    $selected_acstatus = $emember_config->getValue('eMember_emem_when_wp_default_acstatus');
    foreach ($all_levels as $level) {
        ?>
                                            <option <?php 
        echo $selected_level == $level->id ? "selected='selected'" : "";
        ?>
 value="<?php 
        echo $level->id;
        ?>
"><?php 
        echo $level->alias;
        ?>
</option>
                                        <?php 
    }
    ?>
                                    </select>
                                    <br /><i>When automatically creating a member account in the background, the membership level will be set to the one you specify above.</i>
                                </td></tr>

                            <tr valign="top"><td width="25%" align="right"><strong>Default Account Status: </strong></td>
                                <td align="left">
                                    <select name="eMember_emem_when_wp_default_acstatus">
                                        <option <?php 
    echo $selected_acstatus == 'active' ? "selected='selected'" : "";
    ?>
 value="active">Active</option>
                                        <option <?php 
    echo $selected_acstatus == 'inactive' ? "selected='selected'" : "";
    ?>
 value="inactive">Inactive</option>
                                        <option <?php 
    echo $selected_acstatus == 'pending' ? "selected='selected'" : "";
    ?>
 value="pending">Pending</option>
                                        <option <?php 
    echo $selected_acstatus == 'expired' ? "selected='selected'" : "";
    ?>
 value="expired">Expired</option>
                                    </select>
                                    <br /><i>The account status will be set to the one specified above.</i>
                                </td></tr>
                        </table>
                        <input type="submit" name="emem_when_wp" value="Save Settings &raquo;" />
                    </form>
                </div></div>

            <div class="postbox">
                <h3><label for="title">eMember Admin Dashboard Access Permission</label></h3>
                <div class="inside">
                    <p>
                        eMember's admin dashboard is accessible to admin users only (just like any other plugin).
                        You can allow users with other WP role to access the eMember admin dashboard by selecting a value below.
                        <br /><br />
                        <strong>If don't know what this is for then don't change the following value.</strong>
                    </p>
                    <?php 
    $selected_permission = $emember_config->getValue('emember_management_permission');
    ?>
                    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
                        <select name="emember_management_permission">
                            <option <?php 
    echo $selected_permission == 'edit_themes' ? "selected='selected'" : "";
    ?>
 value="edit_themes">Admin</option>
                            <option <?php 
    echo $selected_permission == 'edit_pages' ? "selected='selected'" : "";
    ?>
 value="edit_pages">Editor</option>
                            <option <?php 
    echo $selected_permission == 'edit_published_posts' ? "selected='selected'" : "";
    ?>
 value="edit_published_posts">Author</option>
                            <option <?php 
    echo $selected_permission == 'edit_posts' ? "selected='selected'" : "";
    ?>
 value="edit_posts">Contributor</option>
                        </select>
                        <input type="submit" name="emember_management_permission_update" value="Save Permission &raquo" />
                    </form>
                </div></div>
            <?php 
}
Beispiel #2
0
//Query the membership level table to get a handle for the level
$membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $membership_level_id . "'");
// Create the corresponding wordpress user
$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');
    $wp_user_info = array();
    $wp_user_info['user_nicename'] = implode('-', explode(' ', $username));
    $wp_user_info['display_name'] = $username;
    $wp_user_info['nickname'] = $username;
    $wp_user_info['first_name'] = $first_name;
    $wp_user_info['last_name'] = $last_name;
    $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($username, $password, $email);  //Need to use the non hashed password
    $wp_user_id = eMember_wp_create_user($username, $password, $email);
    $wp_user_info['ID'] = $wp_user_id;
    wp_update_user($wp_user_info);
    eMember_log_debug('Updating WP user role to : ' . $membership_level_resultset->role, true);
    update_wp_user_Role($wp_user_id, $membership_level_resultset->role);
    //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
}
$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');
$login_link = $emember_config->getValue('login_page_url');
$tags1 = array("{first_name}", "{last_name}", "{user_name}", "{password}", "{login_link}");
$vals1 = array($first_name, $last_name, $username, $password, $login_link);
$email_body1 = str_replace($tags1, $vals1, $body_rego_complete);
$headers = 'From: ' . $from_address . "\r\n";
wp_mail($email, $subject_rego_complete, $email_body1, $headers);
Beispiel #3
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';
}
function emember_process_reg_form()
{
    $emember_config = Emember_Config::getInstance();
    if (is_blocked_ip(get_real_ip_addr())) {
        $message = '<span class="emember_error">' . EMEMBER_IP_BLACKLISTED . ' </span>';
        $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $message));
        return;
    }
    if (!function_exists('recaptcha_check_answer')) {
        require_once WP_PLUGIN_DIR . '/' . WP_EMEMBER_FOLDER . '/recaptchalib.php';
    }
    $output = '';
    $eMember_id = strip_tags(isset($_GET["member_id"]) ? $_GET["member_id"] : "");
    $code = strip_tags(isset($_GET["code"]) ? $_GET["code"] : "");
    $recaptcha_error = null;
    $resp = null;
    global $wpdb;
    $is_reg_successfull = false;
    if (isset($_POST['eMember_Register'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'emember-plain-registration-nonce')) {
            eMember_log_debug("Registration nonce check failed ", true);
            die("Security check failed on registration");
        }
        $_POST['wp_emember_email'] = strip_tags($_POST['wp_emember_email']);
        $_POST['wp_emember_user_name'] = strip_tags($_POST['wp_emember_user_name']);
        $_POST['wp_emember_pwd'] = strip_tags($_POST['wp_emember_pwd']);
        if ($emember_config->getValue('eMember_show_terms_conditions')) {
            if (!isset($_POST['emember_terms_conditions'])) {
                $output .= '<span class="emember_error">' . EMEMBER_TERMS_WARNING . '</span>';
                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
                return;
            }
        }
        eMember_log_debug("Processing signup request of membership for: " . $_POST['wp_emember_email'], true);
        if (is_blocked_email($_POST['wp_emember_email'])) {
            $output .= '<span class="emember_error"> ' . EMEMBER_EMAIL_BLACKLISTED . ' </span>';
            $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
            return;
        }
        $enable_recaptcha = $emember_config->getValue('emember_enable_recaptcha');
        if ($enable_recaptcha) {
            $_POST["recaptcha_challenge_field"] = strip_tags($_POST["recaptcha_challenge_field"]);
            $_POST["recaptcha_response_field"] = strip_tags($_POST["recaptcha_response_field"]);
            if (isset($_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) {
                    $emember_config->set_stacked_message('emember_full_registration_captcha', $resp->error);
                    $output .= '<div class="emember_error">' . EMEMBER_CAPTCHA_VERIFICATION_FAILED . '</div>';
                    $emember_config->set_stacked_message('emember_full_registration', array('type' => 'error', 'message' => $output));
                }
            } else {
                $output .= '<span class="emember_error">reCAPTCHA&trade; service encountered error. please Contact Admin. </span>';
                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
            }
        }
        if (!$enable_recaptcha || $resp && $resp->is_valid) {
            eMember_log_debug("reCAPTCHA is valid... creating membership account: " . $_POST['wp_emember_email'], true);
            include_once ABSPATH . WPINC . '/class-phpass.php';
            $wp_hasher = new PasswordHash(8, TRUE);
            $password = $wp_hasher->HashPassword($_POST['wp_emember_pwd']);
            include_once 'emember_validator.php';
            $validator = new Emember_Validator();
            $validator->add(array('value' => $_POST['wp_emember_user_name'], 'label' => EMEMBER_USERNAME, 'rules' => array('user_required', 'user_minlength', 'user_name', 'user_unavail')));
            $validator->add(array('value' => $_POST['wp_emember_email'], 'label' => EMEMBER_EMAIL, 'rules' => array('email_required', 'email', 'email_unavail')));
            $validator->add(array('value' => $_POST['wp_emember_pwd'], 'label' => EMEMBER_PASSWORD, 'rules' => array('pass_required')));
            $messages = $validator->validate();
            $show_confirm_pass = $emember_config->getValue('eMember_show_confirm_pass_field');
            if ($show_confirm_pass) {
                if ($_POST['wp_emember_pwd'] != $_POST['wp_emember_pwd_re']) {
                    $messages[] = EMEMBER_PASSWORD . ':' . EMEMBER_PASSWORD_MISMATCH;
                }
            }
            $valid_captcha = apply_filters('emember_captcha_varify', true);
            // create new member account and send the registration completion email
            if (!$valid_captcha) {
                $output .= "<p class='emember_error'><strong>" . EMEMBER_CAPTCHA_FAILED . "</strong></p>";
                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'error', 'message' => $output));
            } else {
                if (count($messages) > 0) {
                    $output .= '<span class="emember_error">' . implode('<br/>', $messages) . '</span>';
                    $emember_config->set_stacked_message('emember_full_registration', array('type' => 'error', 'message' => $output));
                } else {
                    $fields = array();
                    $custom_fields = array();
                    /* === Common registration fields value === */
                    if (isset($_COOKIE['ap_id'])) {
                        $fields['referrer'] = $_COOKIE['ap_id'];
                    } else {
                        $fields['referrer'] = '';
                    }
                    if (isset($_POST['emember_custom']) && is_array($_POST['emember_custom'])) {
                        $referrer_field_key = "Referrer";
                        if (array_key_exists($referrer_field_key, $_POST['emember_custom'])) {
                            $fields['referrer'] = strip_tags(trim($_POST['emember_custom'][$referrer_field_key]));
                        }
                    }
                    //if (!empty($_SESSION['eMember_id']) && !empty($_SESSION['reg_code']))
                    if (isset($_POST['eMember_id']) && isset($_POST['eMember_reg_code'])) {
                        //Update the membership data with the registration complete details (this path is exercised when the unique link is clicked from the email to do the registration complete action)
                        eMember_log_debug("Completing the registration for premium membership account. Member Email: " . $_POST['wp_emember_email'] . " eMember ID: " . $eMember_id, true);
                        $mresultset = $wpdb->get_row("SELECT reg_code,membership_level FROM " . WP_EMEMBER_MEMBERS_TABLE_NAME . " where member_id='{$eMember_id}'", ARRAY_A);
                        /*                     * ********************** */
                        $fields['user_name'] = $_POST['wp_emember_user_name'];
                        $fields['password'] = $password;
                        $fields['membership_level'] = $mresultset['membership_level'];
                        $fields['reg_code'] = '';
                        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_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']);
                        }
                        $fields['member_since'] = date("Y-m-d");
                        $fields['subscription_starts'] = date("Y-m-d");
                        //No need to update the membership level as it has already been set for this member when the unique rego complete link was sent out
                        $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';
                        }
                        $fields['email'] = $_POST['wp_emember_email'];
                        $fields['last_accessed_from_ip'] = get_real_ip_addr();
                        $reg_code = strip_tags($_POST['eMember_reg_code']);
                        if (md5($mresultset['reg_code']) == $reg_code) {
                            $ret = dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, ' member_id=' . esc_sql($eMember_id), $fields);
                            eMember_log_debug("Updating premium member account data. eMember ID: " . $eMember_id, true);
                            /*                         * ********************** */
                            $lastid = $eMember_id;
                            if (isset($_POST['emember_custom'])) {
                                foreach ($_POST['emember_custom'] as $key => $value) {
                                    $custom_fields[$key] = $value;
                                }
                                $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) {
                                $output .= '<br />' . ' DB Error.';
                                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'error', 'message' => $output));
                                $is_reg_successfull = false;
                            } else {
                                $is_reg_successfull = true;
                                unset($_SESSION['eMember_id']);
                                unset($_SESSION['reg_code']);
                            }
                        } else {
                            $output .= '<span class="emember_error">Error! Unique registration code do not match!</span>';
                            $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
                        }
                    } else {
                        //Create a new account for a free member or the level specified in the shortcode. This path is exercised when someone directly goes to the registration page and submits the details.
                        eMember_log_debug("Creating a new account for free membership or for the level specified in the shortcode. Member Email: " . $_POST['wp_emember_email'], true);
                        $fields['user_name'] = $_POST['wp_emember_user_name'];
                        $fields['password'] = $password;
                        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_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']);
                        }
                        $fields['member_since'] = date("Y-m-d");
                        $fields['subscription_starts'] = date("Y-m-d");
                        if (isset($_POST['custom_member_level_shortcode'])) {
                            $fields['membership_level'] = $_POST['custom_member_level_shortcode'];
                            //$fields['initial_membership_level']    = $_POST['custom_member_level_shortcode'];
                        } 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';
                        }
                        $fields['email'] = $_POST['wp_emember_email'];
                        $fields['last_accessed_from_ip'] = get_real_ip_addr();
                        $ret = dbAccess::insert(WP_EMEMBER_MEMBERS_TABLE_NAME, $fields);
                        $lastid = $wpdb->insert_id;
                        $fields['member_id'] = $lastid;
                        if (isset($_POST['emember_custom'])) {
                            foreach ($_POST['emember_custom'] as $key => $value) {
                                $custom_fields[$key] = $value;
                            }
                            $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) {
                            $output .= '<br />' . ' DB Error.';
                            $emember_config->set_stacked_message('emember_full_registration', array('type' => 'error', 'message' => $output));
                            $is_reg_successfull = false;
                        } else {
                            $is_reg_successfull = true;
                        }
                    }
                    if ($is_reg_successfull) {
                        eMember_log_debug("Processing registration submission...", true);
                        //Send notification to any other plugin listening for the eMember registration complete event.
                        do_action('eMember_registration_complete', $fields, $custom_fields);
                        //Query the membership level table to get a handle for the level
                        $membership_level_resultset = dbAccess::find(WP_EMEMBER_MEMBERSHIP_LEVEL_TABLE, " id='" . $fields['membership_level'] . "'");
                        // Create the corresponding wordpress user
                        $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');
                            $wp_user_info = array();
                            $wp_user_info['user_nicename'] = implode('-', explode(' ', $_POST['wp_emember_user_name']));
                            $wp_user_info['display_name'] = $_POST['wp_emember_user_name'];
                            $wp_user_info['nickname'] = $_POST['wp_emember_user_name'];
                            $wp_user_info['first_name'] = strip_tags($_POST['wp_emember_firstname']);
                            $wp_user_info['last_name'] = strip_tags($_POST['wp_emember_lastname']);
                            $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['wp_emember_user_name'], $_POST['wp_emember_pwd'], $_POST['wp_emember_email']);
                            $wp_user_id = eMember_wp_create_user($_POST['wp_emember_user_name'], $_POST['wp_emember_pwd'], $_POST['wp_emember_email'], $wp_user_info);
                            //do_action( 'set_user_role', $wp_user_id, $membership_level_resultset->role );
                        }
                        //-----------------
                        $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');
                        $login_link = $emember_config->getValue('login_page_url');
                        //Do the full dynamic member details replacement
                        $curr_member_id = $lastid;
                        $additional_params = array('password' => $_POST['wp_emember_pwd'], 'login_link' => $login_link);
                        $email_body1 = emember_dynamically_replace_member_details_in_message($curr_member_id, $body_rego_complete, $additional_params);
                        //The filter for email notification body
                        $email_body1 = apply_filters('eMember_notification_email_body_filter', $email_body1, $curr_member_id);
                        $headers = 'From: ' . $from_address . "\r\n";
                        $member_email = $_POST['wp_emember_email'];
                        wp_mail($member_email, $subject_rego_complete, $email_body1, $headers);
                        eMember_log_debug("Member registration complete email successfully sent to: " . $member_email, true);
                        if ($emember_config->getValue('eMember_admin_notification_after_registration')) {
                            $admin_email = $emember_config->getValue('eMember_admin_notification_email_address');
                            $notify_emails_array = explode(",", $admin_email);
                            foreach ($notify_emails_array as $notify_email_address) {
                                if (!empty($notify_email_address)) {
                                    $admin_notification_subject = EMEMBER_NEW_ACCOUNT_MAIL_HEAD;
                                    $admin_email_body = EMEMBER_NEW_ACCOUNT_MAIL_BODY . "\n\n-------Member Email----------\n" . $email_body1 . "\n\n------End------\n";
                                    wp_mail($notify_email_address, $admin_notification_subject, $admin_email_body, $headers);
                                    eMember_log_debug("Admin notification email successfully sent to: " . $admin_email, true);
                                }
                            }
                        }
                        //Create the corresponding affliate account
                        if ($emember_config->getValue('eMember_auto_affiliate_account')) {
                            eMember_log_debug("Creating affiliate account for this member.", true);
                            eMember_handle_affiliate_signup($_POST['wp_emember_user_name'], $_POST['wp_emember_pwd'], $_POST['wp_emember_firstname'], $_POST['wp_emember_lastname'], $_POST['wp_emember_email'], eMember_get_aff_referrer());
                        }
                        /*                     * * Signup the member to Autoresponder List (Autoresponder integration) ** */
                        eMember_log_debug("===> Performing autoresponder signup if needed <===", true);
                        $membership_level_id = $fields['membership_level'];
                        $firstname = isset($_POST['wp_emember_firstname']) ? $_POST['wp_emember_firstname'] : "";
                        $lastname = isset($_POST['wp_emember_lastname']) ? $_POST['wp_emember_lastname'] : "";
                        $emailaddress = $_POST['wp_emember_email'];
                        eMember_level_specific_autoresponder_signup($membership_level_id, $firstname, $lastname, $emailaddress);
                        eMember_global_autoresponder_signup($firstname, $lastname, $emailaddress);
                        /*                     * * end of autoresponder integration ** */
                        /*                     * * check redirection options and redirect accordingly ** */
                        $after_rego_page = $emember_config->getValue('eMember_after_registration_page');
                        $redirect_page = $emember_config->getValue('login_page_url');
                        $auto_login_after_rego = $emember_config->getValue('eMember_enable_auto_login_after_rego');
                        if ($auto_login_after_rego) {
                            if (!empty($redirect_page)) {
                                $separator = wp_emember_get_query_separator_for_url($redirect_page);
                                $encoded_pass = base64_encode($_POST['wp_emember_pwd']);
                                $redirect_page = $redirect_page . $separator . "doLogin=1&pwd_encoded=1&emember_u_name=" . urlencode($_POST['wp_emember_user_name']) . "&emember_pwd=" . urlencode($encoded_pass);
                                //$redirect_page = wp_nonce_url($redirect_page,'emember-login-nonce');
                                $login_nonce = wp_create_nonce('emember-login-nonce');
                                $redirect_page = $redirect_page . "&_wpnonce=" . $login_nonce;
                                wp_emember_redirect_to_url($redirect_page);
                            } else {
                                $output .= '<div class="emember_error">Error! The "Login Page URL" field value is missing! Go to the Pages/Forms settings menu and correct the mistake.</div>';
                                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
                            }
                        } else {
                            if (!empty($after_rego_page)) {
                                wp_emember_redirect_to_url($after_rego_page);
                            } else {
                                if ($eMember_manually_approve_member_registration) {
                                    $output .= '<p>' . EMEMBER_REG_COMPLETE_PENDING_APPROVAL . '</p>';
                                } else {
                                    $output .= '<p>' . EMEMBER_REG_COMPLETE . EMEMBER_PLEASE . ' <a href="' . $redirect_page . '">' . EMEMBER_LOGIN . '</a></p>';
                                }
                                $emember_config->set_stacked_message('emember_full_registration', array('type' => 'success', 'message' => $output));
                            }
                        }
                        /*                     * * End of redirection stuff ** */
                    } else {
                        $output .= "<b><br/>Something went wrong. Please Contact <a href='mailto:" . get_bloginfo('admin_email') . "'>Admin.</a></b>";
                        $emember_config->set_stacked_message('emember_full_registration', array('type' => 'warning', 'message' => $output));
                    }
                }
            }
            //End no error on submission
        }
        //End recaptcha valid block
    }
    //End POST register submission
    return;
}