/**
  * Save admin fields.
  *
  * Loops though the MailPoet Paid Memberships Pro Addon options array and outputs each field.
  *
  * @access public
  * @param array $options Opens array to output
  * @return bool
  */
 public static function save_fields($options)
 {
     if (empty($_POST)) {
         return false;
     }
     // Options to update will be stored here
     $update_options = array();
     // Loop options and get values to save
     foreach ($options as $value) {
         if (!isset($value['id'])) {
             continue;
         }
         $type = isset($value['type']) ? sanitize_title($value['type']) : '';
         // Get the option name
         $option_value = null;
         switch ($type) {
             // Standard types
             case "checkbox":
                 if (isset($_POST[$value['id']])) {
                     $option_value = 'yes';
                 } else {
                     $option_value = 'no';
                 }
                 break;
             case "textarea":
                 if (isset($_POST[$value['id']])) {
                     $option_value = wp_kses_post(trim(stripslashes($_POST[$value['id']])));
                 } else {
                     $option_value = '';
                 }
                 break;
             case "text":
             case "email":
             case "number":
             case "select":
             case "radio":
                 if (isset($_POST[$value['id']])) {
                     $option_value = mailpoet_paid_memberships_pro_add_on_clean(stripslashes($_POST[$value['id']]));
                 } else {
                     $option_value = '';
                 }
                 break;
                 // Custom handling
             // Custom handling
             default:
                 do_action('mailpoet_paid_memberships_pro_add_on_update_option_' . $type, $value);
                 break;
         }
         if (!is_null($option_value)) {
             // Check if option is an array
             if (strstr($value['id'], '[')) {
                 parse_str($value['id'], $option_array);
                 // Option name is first key
                 $option_name = current(array_keys($option_array));
                 // Get old option value
                 if (!isset($update_options[$option_name])) {
                     $update_options[$option_name] = get_option($option_name, array());
                 }
                 if (!is_array($update_options[$option_name])) {
                     $update_options[$option_name] = array();
                 }
                 // Set keys and value
                 $key = key($option_array[$option_name]);
                 $update_options[$option_name][$key] = $option_value;
                 // Single value
             } else {
                 $update_options[$value['id']] = $option_value;
             }
         }
         // Custom handling
         do_action('mailpoet_paid_memberships_pro_add_on_update_option', $value);
     }
     // Now save the options
     foreach ($update_options as $name => $value) {
         update_option($name, $value);
     }
     return true;
 }
 /**
  * Save User Fields on edit user pages
  *
  * @param mixed $user_id User ID of the user being saved
  */
 public function save_user_meta_fields($user_id)
 {
     $save_fields = $this->get_user_meta_fields();
     foreach ($save_fields as $fieldset) {
         foreach ($fieldset['fields'] as $key => $field) {
             if (isset($_POST[$key])) {
                 update_user_meta($user_id, $key, mailpoet_paid_memberships_pro_add_on_clean($_POST[$key]));
             }
             // This saves single checkbox field values.
             if ($field['type'] == 'checkbox') {
                 update_user_meta($user_id, $key, mailpoet_paid_memberships_pro_add_on_clean($_POST[$key]));
             }
             // This subscribes the user to each MailPoet lists selected under 'Settings -> MailPoet PMPro -> Lists'
             if (isset($_POST['pmpro_user_subscribe_to_mailpoet']) || !empty($_POST['pmpro_user_subscribe_to_mailpoet'])) {
                 $mailpoet_lists = get_option('mailpoet_paid_memberships_pro_subscribe_too');
                 foreach ($mailpoet_lists as $list_id) {
                     $this->mailpoet_subscribe_user($list_id, $user_id);
                 }
             }
             // This unsubscribes the user from each MailPoet lists selected under 'Settings -> MailPoet PMPro -> Lists'
             if (!isset($_POST['pmpro_user_subscribe_to_mailpoet']) || empty($_POST['pmpro_user_subscribe_to_mailpoet'])) {
                 $mailpoet_lists = get_option('mailpoet_paid_memberships_pro_subscribe_too');
                 foreach ($mailpoet_lists as $list_id) {
                     $this->mailpoet_unsubscribe_user($list_id, $user_id);
                 }
             }
         }
     }
 }