/**
     * Display a filter to select the current membership
     *
     * @since  1.0.0
     */
    public function membership_filter()
    {
        $memberships = MS_Model_Membership::get_membership_names(array('active' => true, 'include_guest' => false));
        $url = esc_url_raw(remove_query_arg(array('membership_id', 'paged')));
        $links = array();
        $links['all'] = array('label' => __('All', MS_TEXT_DOMAIN), 'url' => $url);
        foreach ($memberships as $id => $name) {
            if (empty($name)) {
                $name = __('(No Name)', MS_TEXT_DOMAIN);
            }
            $filter_url = esc_url_raw(add_query_arg(array('membership_id' => $id), $url));
            $links['ms-' . $id] = array('label' => esc_html($name), 'url' => $filter_url);
        }
        ?>
		<div class="wp-filter">
			<ul class="filter-links">
				<?php 
        foreach ($links as $key => $item) {
            $is_current = MS_Helper_Utility::is_current_url($item['url']);
            $class = $is_current ? 'current' : '';
            ?>
					<li>
						<a href="<?php 
            echo esc_url($item['url']);
            ?>
" class="<?php 
            echo esc_attr($class);
            ?>
">
							<?php 
            echo esc_html($item['label']);
            ?>
						</a>
					</li>
				<?php 
        }
        ?>
			</ul>
		</div>
		<?php 
    }
 /**
  * Outputs a list of filter-links. This is used to display the views above
  * the list but can also be used in other parts of the table.
  *
  * @since  1.0.0
  * @param  array $links {
  *     The list of links to display
  *
  *     string <array-key> .. Class of the link.
  *     string $label .. Link title
  *     string $url .. Link URL
  *     int    $count .. Optional.
  *     bool   $current .. Optional.
  *     bool   $separator .. Optional. If false then no ' | ' will be added.
  *
  */
 protected function display_filter_links(array $links)
 {
     end($links);
     $last_class = key($links);
     reset($links);
     foreach ($links as $class => $data) {
         lib3()->array->equip($data, 'label', 'url');
         $sep = '|';
         if ($last_class === $class) {
             $sep = '';
         }
         if (isset($data['separator']) && false === $data['separator']) {
             $sep = '';
         }
         $count = empty($data['count']) ? '' : '(' . $data['count'] . ')';
         if (!isset($data['url'])) {
             $data['url'] = '';
         }
         if (!isset($data['label'])) {
             $data['label'] = '';
         }
         if (empty($data['url'])) {
             printf('<li class="%1$s"><span class="group-label">%2$s</span></li>', esc_attr($class), $data['label'], esc_html($sep));
         } else {
             if (isset($data['current'])) {
                 $is_current = $data['current'];
             } else {
                 $is_current = MS_Helper_Utility::is_current_url($data['url']);
             }
             printf('<li class="%1$s"><a href="%2$s" class="%6$s">%3$s <span class="count">%4$s</span></a> %5$s</li>', esc_attr($class), $data['url'], $data['label'], $count, esc_html($sep), $is_current ? 'current' : '');
         }
     }
 }
 /**
  * Constructs the primary Plugin controller.
  *
  * Created by the MS_Plugin object during the setup_theme action.
  *
  * @since  1.0.0
  */
 public function __construct()
 {
     parent::__construct();
     /**
      * Fix for IE: This is a privacy policy which states, that we do not
      * collect personal contact information without consent.
      *
      * Note that other plugins that output this header later will overwrite
      * it! So this is a default value if no other file sends the P3P header.
      *
      * @since  1.0.2.2
      */
     $p3p_done = false;
     foreach (headers_list() as $header) {
         if (false !== stripos($header, 'P3P:')) {
             $p3p_done = true;
             break;
         }
     }
     if (!$p3p_done) {
         header('P3P:CP="NOI"');
     }
     /*
      * Remove the "&msg" attribute from the URL if it was already present in
      * the previous request.
      */
     if (empty($_POST)) {
         /*
          * No form was submitted:
          * It's save to redirect the request without losing form-data.
          */
         if (isset($_GET['msg']) && isset($_SERVER['HTTP_REFERER']) && MS_Helper_Utility::is_current_url($_SERVER['HTTP_REFERER'])) {
             // A msg is set AND the referer URL has the same msg flag!
             $url = esc_url_raw(remove_query_arg(array('msg')));
             wp_safe_redirect($url);
             exit;
         }
     }
     /**
      * We allow two ways to modify the default Admin-Capability setting:
      *
      * Either by defining the constant in wp-config or by using the filter.
      * The constant takes priority over the filter.
      *
      * @since  1.0.0
      */
     if (defined('MS_ADMIN_CAPABILITY')) {
         $this->capability = MS_ADMIN_CAPABILITY;
     } else {
         $this->capability = apply_filters('ms_admin_user_capability', $this->capability);
     }
     // Create core controllers that are available on every page.
     $this->model = MS_Factory::load('MS_Model_Plugin');
     $this->dialogs = MS_Factory::load('MS_Controller_Dialog');
     $this->controllers['widget'] = MS_Factory::load('MS_Controller_Widget');
     $this->controllers['membership'] = MS_Factory::load('MS_Controller_Membership');
     $this->controllers['protection'] = MS_Factory::load('MS_Controller_Protection');
     $this->controllers['rule'] = MS_Factory::load('MS_Controller_Rule');
     $this->controllers['member'] = MS_Factory::load('MS_Controller_Member');
     $this->controllers['billing'] = MS_Factory::load('MS_Controller_Billing');
     $this->controllers['addon'] = MS_Factory::load('MS_Controller_Addon');
     $this->controllers['pages'] = MS_Factory::load('MS_Controller_Pages');
     $this->controllers['settings'] = MS_Factory::load('MS_Controller_Settings');
     $this->controllers['communication'] = MS_Factory::load('MS_Controller_Communication');
     $this->controllers['gateway'] = MS_Factory::load('MS_Controller_Gateway');
     $this->controllers['admin_bar'] = MS_Factory::load('MS_Controller_Adminbar');
     $this->controllers['membership_metabox'] = MS_Factory::load('MS_Controller_Metabox');
     $this->controllers['membership_shortcode'] = MS_Factory::load('MS_Controller_Shortcode');
     $this->controllers['frontend'] = MS_Factory::load('MS_Controller_Frontend');
     $this->controllers['import'] = MS_Factory::load('MS_Controller_Import');
     $this->controllers['help'] = MS_Factory::load('MS_Controller_Help');
     // API should be the last Controller to create.
     $this->controllers['api'] = MS_Controller_Api::instance();
     // Register all available styles and scripts. Nothing is enqueued.
     $this->add_action('wp_loaded', 'wp_loaded');
     // Setup plugin admin UI.
     $this->add_action('admin_menu', 'add_menu_pages');
     if (MS_Plugin::is_network_wide()) {
         $this->add_action('network_admin_menu', 'add_menu_pages');
     }
     // Select the right page to display.
     $this->add_action('admin_init', 'route_submenu_request');
     // This will do the ADMIN-SIDE initialization of the controllers
     $this->add_action('ms_plugin_admin_setup', 'run_admin_init');
     // Changes the current themes "single" template to the invoice form when an invoice is displayed.
     $this->add_filter('single_template', 'custom_single_template');
     $this->add_filter('page_template', 'custom_page_template');
     // Register styles and javascripts for use in front-end
     $this->add_action('ms_register_public_scripts', 'register_public_scripts');
     $this->add_action('ms_register_public_scripts', 'register_public_styles');
     $this->add_action('wp_enqueue_scripts', 'enqueue_plugin_styles');
     $this->add_action('wp_enqueue_scripts', 'enqueue_plugin_scripts');
 }