/**
  * Display Membership Edit page.
  *
  * @since  1.0.0
  */
 public function page_edit()
 {
     $membership = $this->load_membership();
     $data = array();
     $data['tabs'] = $this->get_edit_tabs();
     $data['settings'] = MS_Plugin::instance()->settings;
     $data['membership'] = $membership;
     switch ($this->get_active_edit_tab()) {
         case self::TAB_EMAILS:
             $default_type = MS_Model_Communication::COMM_TYPE_REGISTRATION;
             if (!empty($_REQUEST['membership_id'])) {
                 $membership_id = intval($_REQUEST['membership_id']);
                 $comm_types = array_keys(MS_Model_Communication::get_communication_type_titles($membership_id));
                 $default_type = reset($comm_types);
             }
             $temp_type = isset($_GET['comm_type']) ? $_GET['comm_type'] : '';
             if (MS_Model_Communication::is_valid_communication_type($temp_type)) {
                 $type = $temp_type;
             } else {
                 $type = $default_type;
             }
             $comm = MS_Model_Communication::get_communication($type, $membership, true);
             $data['comm'] = $comm;
             break;
     }
     $view = MS_Factory::create('MS_View_Membership_Edit');
     $view->data = apply_filters('ms_view_membership_edit_data', $data, $this);
     $view->render();
 }
 /**
  * Manages communication actions.
  *
  * Verifies GET and POST requests to manage settings.
  *
  * @since  1.0.1.0
  */
 public function admin_manager()
 {
     $msg = 0;
     $redirect = false;
     if ($this->is_admin_user() && $this->verify_nonce()) {
         /**
          * After verifying permissions this filters can be used by Add-ons
          * to process their own settings.
          *
          * @since  1.0.1.0
          */
         do_action('ms_admin_communication_manager');
         $fields = array('type', 'subject', 'email_body');
         if (self::validate_required(array('comm_type')) && MS_Model_Communication::is_valid_communication_type($_POST['comm_type'])) {
             // Load comm type from user select.
             $redirect = esc_url_raw(remove_query_arg('msg', add_query_arg('comm_type', $_POST['comm_type'])));
         } elseif (isset($_POST['save_email']) && self::validate_required($fields)) {
             // Save email template form.
             $default_type = MS_Model_Communication::COMM_TYPE_REGISTRATION;
             if (!empty($_REQUEST['membership_id'])) {
                 $membership_id = intval($_REQUEST['membership_id']);
                 $comm_types = array_keys(MS_Model_Communication::get_communication_type_titles($membership_id));
                 $default_type = reset($comm_types);
             }
             if (!empty($_POST['type']) && MS_Model_Communication::is_valid_communication_type($_POST['type'])) {
                 $type = $_POST['type'];
             } else {
                 $type = $default_type;
             }
             $msg = $this->save_communication($type, $_POST);
             $redirect = esc_url_raw(add_query_arg(array('comm_type' => urlencode($_POST['type']), 'msg' => $msg)));
         }
     }
     if ($redirect) {
         wp_safe_redirect($redirect);
         exit;
     }
 }
 /**
  * Callback function from 'Membership' navigation.
  *
  * Menu Item: Membership > Settings
  *
  * @since  1.0.0
  */
 public function admin_page()
 {
     $hook = 'ms_controller_settings-' . $this->active_tab;
     do_action($hook);
     $view = MS_Factory::create('MS_View_Settings_Edit');
     $view = apply_filters($hook . '_view', $view);
     $data = array();
     $data['tabs'] = $this->get_tabs();
     $data['settings'] = $this->get_model();
     $data['message'] = self::_message();
     if (isset($data['message']['error'])) {
         lib3()->ui->admin_message($data['message']['error'], 'err');
     }
     switch ($this->get_active_tab()) {
         case self::TAB_EMAILS:
             $type = MS_Model_Communication::COMM_TYPE_REGISTRATION;
             $temp_type = isset($_GET['comm_type']) ? $_GET['comm_type'] : '';
             if (MS_Model_Communication::is_valid_communication_type($temp_type)) {
                 $type = $temp_type;
             }
             $comm = MS_Model_Communication::get_communication($type);
             $data['comm'] = $comm;
             break;
     }
     $data = array_merge($data, $view->data);
     $view->data = apply_filters($hook . '_data', $data);
     $view->model = $this->get_model();
     $view->render();
 }