function simplr_reg_profile_form_fields($user)
{
    if (!class_exists('Form')) {
        include_once SIMPLR_DIR . '/lib/form.class.php';
    }
    $custom = new SREG_Fields();
    if (!current_user_can('promote_users')) {
        $fields = simplr_filter_profile_fields($custom->get_custom());
    } else {
        $fields = $custom->get_custom();
    }
    ?>
	<h3><?php 
    _e('Other Information', 'simplr-registration-form');
    ?>
</h3>
	<?php 
    wp_enqueue_style('simplr-admin-style');
    foreach ($fields as $field) {
        if (!in_array($field['key'], array('first_name', 'last_name', 'user_login', 'username'))) {
            $out = '';
            if ($field['key'] != '') {
                $args = array('name' => $field['key'], 'label' => $field['label'], 'required' => $field['required']);
                //setup specific field values for date and callback
                $sreg_form = new SREG_Form();
                $type = $field['type'];
                if ($type == 'callback') {
                    $field['options_array'][1] = array(get_user_meta($user->ID, $field['key'], true));
                    $sreg_form->{$type}($args, get_user_meta($user->ID, $field['key'], true), '', $field['options_array']);
                } elseif ($type != '') {
                    $sreg_form->{$type}($args, get_user_meta($user->ID, $field['key'], true), '', $field['options_array']);
                }
            }
        }
    }
}
function simplr_profile_init()
{
    global $simplr_options, $errors;
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
    wp_enqueue_script('user-profile');
    $custom = new SREG_Fields();
    $fields = simplr_filter_profile_fields($custom->get_custom());
    set_transient('simplr_profile_transient', $fields);
    if (isset($_POST['simplr-profile'])) {
        if (!wp_verify_nonce($_POST['_simplr_nonce'], 'simplr-profile')) {
            wp_die('No hackers please! Your security nonce check failed. Please try again or contact the systems admin.');
        } else {
            $errors = simplr_validate_profile($_POST, $fields);
            $data = $_POST;
            if (!is_array($errors)) {
                //update user
                $userdata = array('ID' => $data['user_id'], 'user_nicename' => @$data['user_nicename'], 'user_email' => @$data['user_email']);
                if (isset($data['pass1']) and $data['pass1'] != '' and $data['pass2'] == $data['pass1']) {
                    $userdata['user_pass'] = $data['pass1'];
                }
                wp_update_user($userdata);
                //update user meta fields
                foreach ($fields as $field) {
                    if ($field['type'] == 'date') {
                        $dy = $data[$field['key'] . '-dy'];
                        $mo = $data[$field['key'] . '-mo'];
                        $yr = $data[$field['key'] . '-yr'];
                        $dateinput = implode('-', array($yr, $mo, $dy));
                        update_user_meta($data['user_id'], $field['key'], $dateinput);
                    } elseif ($field['type'] == 'checkbox') {
                        if (isset($data[$field['key']])) {
                            update_user_meta($data['user_id'], $field['key'], 'on');
                        } else {
                            delete_user_meta($data['user_id'], $field['key']);
                        }
                    } else {
                        update_user_meta($data['user_id'], $field['key'], $data[$field['key']]);
                    }
                }
                do_action('simplr_profile_save');
                wp_redirect('?p=' . $simplr_options->profile_redirect . '&updated=true');
            }
        }
    }
}
function simplr_reg_profile_form_fields($user)
{
    if (!class_exists('Form')) {
        include_once SIMPLR_DIR . '/lib/form.class.php';
    }
    $custom = new SREG_Fields();
    if (!current_user_can('promote_users')) {
        $fields = simplr_filter_profile_fields($custom->get_custom());
    } else {
        $fields = $custom->get_custom();
    }
    ?>
	<link href="<?php 
    echo SIMPLR_URL;
    ?>
/assets/admin-style.css" rel="stylesheet" ></link>
	<h3><?php 
    _e('Other Information', 'simplr-reg');
    ?>
</h3>
	<?php 
    foreach ($fields as $field) {
        if (!in_array($field['key'], array('first_name', 'last_name', 'user_login', 'username'))) {
            $out = '';
            if ($field['key'] != '') {
                $args = array('name' => $field['key'], 'label' => $field['label'], 'required' => $field['required']);
                //setup specific field values for date and callback
                if ($field['type'] == 'callback') {
                    $field['options_array'][1] = array(get_user_meta($user->ID, $field['key'], true));
                    SREG_Form::$field['type']($args, get_user_meta($user->ID, $field['key'], true), '', $field['options_array']);
                } elseif ($field['type'] != '') {
                    SREG_Form::$field['type']($args, get_user_meta($user->ID, $field['key'], true), '', $field['options_array']);
                }
            }
        }
    }
}