file = $file; self::$instance->setup_constants(); self::$instance->load_textdomain(); self::$instance->includes(); } return self::$instance; } /** * Throws 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. * * @access public * @since 1.1 */ public function __clone() { // Cloning instances of the class is forbidden. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-allowed-products' ), '1.0' ); } /** * Disables unserializing of the class. * * @access public * @since 1.1 * * @return void */ public function __wakeup() { // Unserializing instances of the class is forbidden. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-allowed-products' ), '1.0' ); } /** * Runs during class start-up. * * @access private * @since 1.1 */ private function __construct() { self::$instance = $this; } /** * Resets the instance of the class. * * @access public * @since 1.1 * @static */ public static function reset() { self::$instance = null; } /** * Sets up plugin constants. * * @access private * @since 1.1 */ private function setup_constants() { // Plugin version. if ( ! defined( 'AFFWP_ALLP_VERSION' ) ) { define( 'AFFWP_ALLP_VERSION', $this->version ); } // Plugin Folder Path. if ( ! defined( 'AFFWP_ALLP_PLUGIN_DIR' ) ) { define( 'AFFWP_ALLP_PLUGIN_DIR', plugin_dir_path( $this->file ) ); } // Plugin Folder URL. if ( ! defined( 'AFFWP_ALLP_PLUGIN_URL' ) ) { define( 'AFFWP_ALLP_PLUGIN_URL', plugin_dir_url( $this->file ) ); } // Plugin Root File. if ( ! defined( 'AFFWP_ALLP_PLUGIN_FILE' ) ) { define( 'AFFWP_ALLP_PLUGIN_FILE', $this->file ); } } /** * Loads the plugin language files. * * @access public * @since 1.1 */ public function load_textdomain() { // Set filter for plugin's languages directory. $lang_dir = dirname( plugin_basename( $this->file ) ) . '/languages/'; $lang_dir = apply_filters( 'affwp_allp_languages_directory', $lang_dir ); // Traditional WordPress plugin locale filter. $locale = apply_filters( 'plugin_locale', get_locale(), 'affiliatewp-allowed-products' ); $mofile = sprintf( '%1$s-%2$s.mo', 'affiliatewp-allowed-products', $locale ); // Setup paths to current locale file. $mofile_local = $lang_dir . $mofile; $mofile_global = WP_LANG_DIR . '/affiliatewp-allowed-products/' . $mofile; if ( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/affiliatewp-allowed-products/ folder. load_textdomain( 'affiliatewp-allowed-products', $mofile_global ); } elseif ( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/affiliatewp-allowed-products/languages/ folder. load_textdomain( 'affiliatewp-allowed-products', $mofile_local ); } else { // Load the default language files. load_plugin_textdomain( 'affiliatewp-allowed-products', false, $lang_dir ); } } /** * Includes necessary files. * * @access private * @since 1.1 */ private function includes() { require_once AFFWP_ALLP_PLUGIN_DIR . 'includes/functions.php'; } } /** * The main function responsible for returning the one true AffiliateWP_Allowed_Products * Instance to functions everywhere. * * Use this function like you would a global variable, except without needing * to declare the global. * * Example: * * @since 1.1 * * @return \AffiliateWP_Allowed_Products The one true AffiliateWP_Allowed_Products Instance. */ function affiliatewp_allowed_products() { return AffiliateWP_Allowed_Products::instance(); } }