/**
  * Prepare fields that are displayed in the form.
  *
  * @since  1.0.1.0
  * @return array
  */
 protected function prepare_fields()
 {
     $membership = $this->data['membership'];
     $action = MS_Addon_Attributes::AJAX_ACTION_SAVE_ATTRIBUTE;
     $fields = array();
     $field_def = MS_Addon_Attributes::list_field_def();
     foreach ($field_def as $field) {
         $field_type = MS_Helper_Html::INPUT_TYPE_TEXT;
         $before = '';
         $after = '';
         $value = MS_Addon_Attributes::get_attr($field->slug, $membership);
         switch ($field->type) {
             case 'number':
                 $field_type = MS_Helper_Html::INPUT_TYPE_NUMBER;
                 break;
             case 'textarea':
                 $field_type = MS_Helper_Html::INPUT_TYPE_TEXT_AREA;
                 break;
             case 'bool':
                 $field_type = MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER;
                 $before = __('No', 'membership2');
                 $after = __('Yes', 'membership2');
         }
         $fields[] = array('id' => $field->slug, 'title' => $field->title, 'desc' => $field->info, 'type' => $field_type, 'value' => $value, 'before' => $before, 'after' => $after, 'ajax_data' => array('action' => $action, '_wpnonce' => wp_create_nonce($action), 'field' => $field->slug, 'membership_id' => $membership->id));
     }
     return $fields;
 }
/**
 * Convenience function to access a membership attribute value.
 *
 * @since  1.0.1.0
 * @param  string $slug The attribute slug.
 * @param  int $membership_id Membership ID.
 * @return string|false The attribute value or false.
 */
function ms_membership_attr($slug, $membership_id = 0)
{
    return MS_Addon_Attributes::get_attr($slug, $membership_id);
}