public function edit($id)
 {
     global $wpdb;
     $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d", $id);
     $member = $wpdb->get_row($query, ARRAY_A);
     $email_address = $member['email'];
     $user_name = $member['user_name'];
     unset($member['member_id']);
     unset($member['user_name']);
     $form = new SwpmForm($member);
     if ($form->is_valid()) {
         $member = $form->get_sanitized();
         $plain_password = isset($member['plain_password']) ? $member['plain_password'] : "";
         SwpmUtils::update_wp_user($user_name, $member);
         unset($member['plain_password']);
         $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member, array('member_id' => $id));
         $message = array('succeeded' => true, 'message' => '<p>Member profile updated successfully.</p>');
         $error = apply_filters('swpm_admin_edit_custom_fields', array(), $member + array('member_id' => $id));
         if (!empty($error)) {
             $message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $error);
             SwpmTransfer::get_instance()->set('status', $message);
             return;
         }
         SwpmTransfer::get_instance()->set('status', $message);
         $send_notification = filter_input(INPUT_POST, 'account_status_change');
         if (!empty($send_notification)) {
             $settings = SwpmSettings::get_instance();
             $from_address = $settings->get_value('email-from');
             $headers = 'From: ' . $from_address . "\r\n";
             $subject = filter_input(INPUT_POST, 'notificationmailhead');
             $body = filter_input(INPUT_POST, 'notificationmailbody');
             $settings->set_value('account-change-email-body', $body)->set_value('account-change-email-subject', $subject)->save();
             $member['login_link'] = $settings->get_value('login-page-url');
             $member['user_name'] = $user_name;
             $member['password'] = empty($plain_password) ? SwpmUtils::_("Your current password") : $plain_password;
             $values = array_values($member);
             $keys = array_map('swpm_enclose_var', array_keys($member));
             $body = html_entity_decode(str_replace($keys, $values, $body));
             wp_mail($email_address, $subject, $body, $headers);
         }
         wp_redirect('admin.php?page=simple_wp_membership');
         exit(0);
     }
     $message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors());
     SwpmTransfer::get_instance()->set('status', $message);
 }
 public function edit()
 {
     global $wpdb;
     $auth = SwpmAuth::get_instance();
     if (!$auth->is_logged_in()) {
         return;
     }
     $user_data = (array) $auth->userData;
     unset($user_data['permitted']);
     $form = new SwpmForm($user_data);
     if ($form->is_valid()) {
         global $wpdb;
         $message = array('succeeded' => true, 'message' => SwpmUtils::_('Profile updated successfully.'));
         $member_info = $form->get_sanitized();
         SwpmUtils::update_wp_user($auth->get('user_name'), $member_info);
         //Update corresponding wp user record.
         if (isset($member_info['plain_password'])) {
             //Password was also changed so show the appropriate message
             $message = array('succeeded' => true, 'message' => SwpmUtils::_('Profile updated successfully. You will need to re-login since you changed your password.'));
             unset($member_info['plain_password']);
         }
         $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member_info, array('member_id' => $auth->get('member_id')));
         $auth->reload_user_data();
         SwpmTransfer::get_instance()->set('status', $message);
     } else {
         $message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following'), 'extra' => $form->get_errors());
         SwpmTransfer::get_instance()->set('status', $message);
         return;
     }
 }