version = get_plugin_data( self::$instance->file, false, false )['Version'] ?? ''; self::$instance->setup_constants(); self::$instance->hooks(); return self::$instance; } /** * Setup the singleton instance * * @since 1.1 * * @param string $file File path to the main plugin file. */ private static function setup_instance( $file ) { self::$instance = new \AffiliateWP_Allow_Own_Referrals; self::$instance->file = $file; } /** * Return whether the main loading class has been instantiated or not. * * @since 1.1 * * @return bool True if instantiated. False if not. */ private static function is_instantiated() { // Return true if instance is correct class if ( ! empty( self::$instance ) && ( self::$instance instanceof AffiliateWP_Allow_Own_Referrals ) ) { return true; } // Return false if not instantiated correctly. return false; } /** * Throws an 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.1 * * @return void */ public function __clone() { // Cloning instances of the class is forbidden. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh? This object cannot be cloned.', 'affiliatewp-allow-own-referrals' ), '1.1' ); } /** * Disables unserialization of the class. * * @since 1.1 * * @return void */ public function __wakeup() { // Unserializing instances of the class is forbidden _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh? This class cannot be unserialized.', 'affiliatewp-allow-own-referrals' ), '1.1' ); } /** * Sets up the class. * * @since 1.1 */ private function __construct() { self::$instance = $this; } /** * Resets the instance of the class. * * @since 1.1 * @static */ public static function reset() { self::$instance = null; } /** * Sets up plugin constants. * * @since 1.1 * * @return void */ private function setup_constants() { // Plugin version. if ( ! defined( 'AFFWP_AOR_VERSION' ) ) { define( 'AFFWP_AOR_VERSION', $this->version ); } // Plugin Folder Path. if ( ! defined( 'AFFWP_AOR_PLUGIN_DIR' ) ) { define( 'AFFWP_AOR_PLUGIN_DIR', plugin_dir_path( $this->file ) ); } // Plugin Folder URL. if ( ! defined( 'AFFWP_AOR_PLUGIN_URL' ) ) { define( 'AFFWP_AOR_PLUGIN_URL', plugin_dir_url( $this->file ) ); } // Plugin Root File. if ( ! defined( 'AFFWP_AOR_PLUGIN_FILE' ) ) { define( 'AFFWP_AOR_PLUGIN_FILE', $this->file ); } } /** * Sets up the default hooks and actions. * * @since 1.1 * * @return void */ private function hooks() { // Plugin meta. add_filter( 'plugin_row_meta', array( $this, 'plugin_meta' ), null, 2 ); add_filter( 'affwp_is_customer_email_affiliate_email', '__return_false' ); add_filter( 'affwp_tracking_is_valid_affiliate', array( $this, 'maybe_override_tracking' ), 10, 2 ); } /** * Filters whether the current tracked affiliate is valid. * * @since 1.1 * * @param bool $ret Whether the current affiliate is valid. * @param int $affiliate_id Tracked affiliate ID. * @return bool Whether the current tracked affiliate is valid. */ function maybe_override_tracking( $ret, $affiliate_id ) { if ( 'active' === affwp_get_affiliate_status( $affiliate_id ) ) { $ret = true; } return $ret; } /** * Modifies the plugin list table meta links. * * @since 1.1 * @since 1.2.1 Removed Get more add-ons link. * * @param array $links The current links array. * @param string $file A specific plugin table entry. * @return array The modified links array. */ public function plugin_meta( $links, $file ) { return $links; } /** * Set Dynamic Property * * @since 1.2.1 * * @param string $property Name of property. * @param mixed $value The value. */ public function __set( string $property, $value ) : void { $this->$property = $value; } /** * Get Dynamic Property * * @since 1.2.1 * * @param string $property The name of the property. * * @return mixed The value of the property, null if none. */ public function __get( string $property ) { return $this->$property ?? null; } } } /** * The main function responsible for returning the one true bootstrap 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_Allow_Own_Referrals The one true bootstrap instance. */ function affiliatewp_allow_own_referrals() { return AffiliateWP_Allow_Own_Referrals::instance(); }