. */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'AffiliateWP_Affiliate_Area_Tabs' ) ) { final class AffiliateWP_Affiliate_Area_Tabs { /** * Holds the instance * * Ensures that only one instance of AffiliateWP_Affiliate_Area_Tabs exists in memory at any one * time and it also prevents needing to define globals all over the place. * * TL;DR This is a static property property that holds the singleton instance. * * @var object * @static * @since 1.0 */ private static $instance; /** * The version number of AffiliateWP * * @since 1.0 */ private $version = '1.2.7'; /** * The functions instance variable * * @var object * @since 1.2 */ public $functions; /** * Main AffiliateWP_Affiliate_Area_Tabs Instance * * Insures that only one instance of AffiliateWP_Affiliate_Area_Tabs exists in memory at any one * time. Also prevents needing to define globals all over the place. * * @since 1.0 * @static var array $instance * @return The one true AffiliateWP_Affiliate_Area_Tabs */ public static function instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AffiliateWP_Affiliate_Area_Tabs ) ) { self::$instance = new AffiliateWP_Affiliate_Area_Tabs; self::$instance->setup_constants(); self::$instance->load_textdomain(); self::$instance->includes(); self::$instance->hooks(); self::$instance->functions = new AffiliateWP_Affiliate_Area_Tabs_Functions; } return self::$instance; } /** * Throw error on object clone * * The whole idea of the singleton design pattern is that there is a single * object therefore, we don't want the object to be cloned. * * @since 1.0.0 * @access protected * @return void */ public function __clone() { // Cloning instances of the class is forbidden _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-affiliate-area-tabs' ), '1.0' ); } /** * Disable unserializing of the class * * @since 1.0.0 * @access protected * @return void */ public function __wakeup() { // Unserializing instances of the class is forbidden _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-affiliate-area-tabs' ), '1.0' ); } /** * Constructor Function * * @since 1.0.0 * @access private */ private function __construct() { self::$instance = $this; } /** * Reset the instance of the class * * @since 1.0.0 * @access public * @static */ public static function reset() { self::$instance = null; } /** * Setup plugin constants * * @access private * @since 1.0.0 * @return void */ private function setup_constants() { // Plugin version if ( ! defined( 'AFFWP_AAT_VERSION' ) ) { define( 'AFFWP_AAT_VERSION', $this->version ); } // Plugin Folder Path if ( ! defined( 'AFFWP_AAT_PLUGIN_DIR' ) ) { define( 'AFFWP_AAT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); } // Plugin Folder URL if ( ! defined( 'AFFWP_AAT_PLUGIN_URL' ) ) { define( 'AFFWP_AAT_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); } // Plugin Root File if ( ! defined( 'AFFWP_AAT_PLUGIN_FILE' ) ) { define( 'AFFWP_AAT_PLUGIN_FILE', __FILE__ ); } } /** * Loads the plugin language files * * @access public * @since 1.0.0 * @return void */ public function load_textdomain() { // Set filter for plugin's languages directory $lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; $lang_dir = apply_filters( 'affiliatewp_affiliate_area_tabs_languages_directory', $lang_dir ); // Traditional WordPress plugin locale filter $locale = apply_filters( 'plugin_locale', get_locale(), 'affiliatewp-affiliate-area-tabs' ); $mofile = sprintf( '%1$s-%2$s.mo', 'affiliatewp-affiliate-area-tabs', $locale ); // Setup paths to current locale file $mofile_local = $lang_dir . $mofile; $mofile_global = WP_LANG_DIR . '/affiliatewp-affiliate-area-tabs/' . $mofile; if ( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/affiliatewp-affiliate-area-tabs/ folder load_textdomain( 'affiliatewp-affiliate-area-tabs', $mofile_global ); } elseif ( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/affiliatewp-affiliate-area-tabs/languages/ folder load_textdomain( 'affiliatewp-affiliate-area-tabs', $mofile_local ); } else { // Load the default language files load_plugin_textdomain( 'affiliatewp-affiliate-area-tabs', false, $lang_dir ); } } /** * Include necessary files * * @access private * @since 1.0.0 * @return void */ private function includes() { // Functions class. require_once AFFWP_AAT_PLUGIN_DIR . 'includes/class-functions.php'; // Upgrade class. require_once AFFWP_AAT_PLUGIN_DIR . 'includes/class-upgrades.php'; /** * Compatibility class. * This provides compatibility with AffiliateWP v1.8 - v2.1.6.1 */ if ( $this->has_1_8() && ! $this->has_2_1_7() ) { require_once AFFWP_AAT_PLUGIN_DIR . 'includes/class-compatibility.php'; } // Admin class. if ( is_admin() ) { require_once AFFWP_AAT_PLUGIN_DIR . 'includes/class-admin.php'; } } /** * Setup the default hooks and actions * * @since 1.0.0 * * @return void */ private function hooks() { // plugin meta add_filter( 'plugin_row_meta', array( $this, 'plugin_meta' ), null, 2 ); // Render the tab content. add_filter( 'affwp_render_affiliate_dashboard_tab', array( $this, 'render_custom_tab' ), 10, 2 ); // Redirect if non-affiliate tries to access a tab's page. add_action( 'template_redirect', array( $this, 'redirect' ) ); // User has at least AffiliateWP version 2.1.7 if ( $this->has_2_1_7() ) { /** * Filter the tabs in the Affiliate Area and in the admin. * * @since 1.1 * @since 1.2 Increased priority to 9999 so we can better listen for other tabs being added. E.g. Direct Link Tracking. */ add_filter( 'affwp_affiliate_area_tabs', array( $this, 'affiliate_area_tabs' ), 9999 ); } // Hide tabs in the Affiliate Area. add_filter( 'affwp_affiliate_area_show_tab', array( $this, 'hide_existing_tabs' ), 10, 2 ); } /** * Filter an existing tab's content * * @since 1.1.2 * @param string $content * @param string $active_tab The slug of the active tab. * * @return string $content The content to show in the tab. */ public function render_custom_tab( $content, $active_tab ) { if ( ! $this->functions->is_custom_tab( $active_tab ) ) { // Not a custom tab, return the content. return $content; } // Get the tab's content. $content = $this->custom_tab_content( $active_tab ); // Return the $content. return $content; } /** * The custom tab's content. * * @since 1.1.2 * @param string $active_tab The slug of the active tab. * * @return string $content The content of the tab */ public function custom_tab_content( $active_tab ) { ?>