<?php
/**
 * Singleton class for setting up the plugin.
 *
 * @since  1.0.0
 * @access public
 */
if (!defined('ABSPATH')) {
    die('You are not allowed to call this page directly.');
}

final class Members_Role_Levels_Plugin {

	/**
	 * Plugin directory path.
	 *
	 * @since  1.0.0
	 * @access public
	 * @var    string
	 */
	public $dir_path = '';

	/**
	 * Constructor method.
	 *
	 * @since  1.0.0
	 * @access private
	 * @return void
	 */
	private function __construct() {}

	/**
	 * Sets up globals.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return void
	 */
	private function setup() {

		$this->dir_path = trailingslashit( plugin_dir_path( __FILE__ ) );
	}

	/**
	 * Loads files needed by the plugin.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return void
	 */
	private function includes() {

		if ( is_admin() ) {

			require_once( $this->dir_path . 'admin/functions-helpers.php'    );
			require_once( $this->dir_path . 'admin/class-column-level.php'   );
			require_once( $this->dir_path . 'admin/class-meta-box-level.php' );
		}
	}

	/**
	 * Sets up main plugin actions and filters.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return void
	 */
	private function setup_actions() {

		// Always hide the old user levels in Members.
		add_filter( 'members_remove_old_levels', '__return_true', 95 );
	}

	/**
	 * Returns the instance.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return object
	 */
	public static function get_instance() {

		static $instance = null;

		if ( is_null( $instance ) ) {
			$instance = new Members_Role_Levels_Plugin;
			$instance->setup();
			$instance->includes();
			$instance->setup_actions();
		}

		return $instance;
	}
}

Members_Role_Levels_Plugin::get_instance();
