/**
 * Updates WP-Members fields from the WP user profile screen.
 *
 * @since 2.1
 */
function wpmem_admin_update()
{
    global $wpmem;
    $user_id = $_REQUEST['user_id'];
    $wpmem_fields = $wpmem->fields;
    // get_option( 'wpmembers_fields' );
    /**
     * Fires before the user profile is updated.
     *
     * @since 2.9.2
     *
     * @param int   $user_id      The user ID.
     * @param array $wpmem_fields Array of the custom fields.
     */
    do_action('wpmem_admin_pre_user_update', $user_id, $wpmem_fields);
    $fields = array();
    $chk_pass = false;
    foreach ($wpmem_fields as $meta) {
        if ($meta[6] == "n" && $meta[3] != 'password' && $meta[3] != 'checkbox') {
            isset($_POST[$meta[2]]) ? $fields[$meta[2]] = $_POST[$meta[2]] : false;
        } elseif ($meta[2] == 'password' && $meta[4] == 'y') {
            $chk_pass = true;
        } elseif ($meta[3] == 'checkbox') {
            $fields[$meta[2]] = isset($_POST[$meta[2]]) ? $_POST[$meta[2]] : '';
        }
    }
    /**
     * Filter the submitted field values for backend profile update.
     *
     * @since 2.8.2
     *
     * @param array $fields An array of the posted form values.
     * @param int   $user_id The ID of the user being updated.
     */
    $fields = apply_filters('wpmem_admin_profile_update', $fields, $user_id);
    // Get any excluded meta fields.
    $exclude = wpmem_get_excluded_meta('admin-profile');
    foreach ($fields as $key => $val) {
        if (!in_array($key, $exclude)) {
            update_user_meta($user_id, $key, $val);
        }
    }
    if ($wpmem->mod_reg == 1) {
        $wpmem_activate_user = isset($_POST['activate_user']) == '' ? -1 : $_POST['activate_user'];
        if ($wpmem_activate_user == 1) {
            wpmem_a_activate_user($user_id, $chk_pass);
        } elseif ($wpmem_activate_user == 0) {
            wpmem_a_deactivate_user($user_id);
        }
    }
    defined('WPMEM_EXP_MODULE') && $wpmem->use_exp == 1 ? wpmem_a_extend_user($user_id) : '';
    /**
     * Fires after the user profile is updated.
     *
     * @since 2.9.2
     *
     * @param int $user_id The user ID.
     */
    do_action('wpmem_admin_after_user_update', $user_id);
    return;
}
/**
 * updates WP-Members fields from the WP user profile screen
 *
 * @since 2.1
 *
 * @uses apply_filters Calls wpmem_admin_profile_update
 */
function wpmem_admin_update()
{
    $user_id = $_REQUEST['user_id'];
    $wpmem_fields = get_option('wpmembers_fields');
    $fields = array();
    $chk_pass = false;
    for ($row = 0; $row < count($wpmem_fields); $row++) {
        if ($wpmem_fields[$row][6] == "n" && $wpmem_fields[$row][2] != 'password') {
            $_POST ? $fields[$wpmem_fields[$row][2]] = $_POST[$wpmem_fields[$row][2]] : false;
        } elseif ($wpmem_fields[$row][2] == 'password') {
            $chk_pass = true;
        }
    }
    $fields = apply_filters('wpmem_admin_profile_update', $fields);
    foreach ($fields as $key => $val) {
        update_user_meta($user_id, $key, $val);
    }
    if (WPMEM_MOD_REG == 1) {
        // $wpmem_activate_user = $_POST['activate_user'];
        // if( $wpmem_activate_user == '' ) { $wpmem_activate_user = -1; }
        $wpmem_activate_user = isset($_POST['activate_user']) == '' ? $wpmem_activate_user = -1 : $_POST['activate_user'];
        if ($wpmem_activate_user == 1) {
            wpmem_a_activate_user($user_id, $chk_pass);
        } elseif ($wpmem_activate_user == 0) {
            wpmem_a_deactivate_user($user_id);
        }
    }
    WPMEM_USE_EXP == 1 ? wpmem_a_extend_user($user_id) : '';
}