setup(); } return self::$instance; } /** * Instantiate the plugin. */ private function setup() { // Define plugin constants. $this->define_constants(); // Include required files. $this->includes(); // Instantiate classes. $this->instantiate(); // Loaded action. do_action( 'affilinks/loaded' ); } /** * Define the plugin constants. */ private function define_constants() { define( 'AFFILINKS_VERSION', $this->version ); define( 'AFFILINKS_FILE', __FILE__ ); define( 'AFFILINKS_BASE', plugin_basename( AFFILINKS_FILE ) ); define( 'AFFILINKS_DIR', plugin_dir_path( AFFILINKS_FILE ) ); define( 'AFFILINKS_URI', plugins_url( '/', AFFILINKS_FILE ) ); } /** * Include the required files. */ private function includes() { include dirname( __FILE__ ) . '/vendor/autoload.php'; } /** * Instantiate classes. */ private function instantiate() { new \AffiLinks\Analytics(); new \AffiLinks\KB(); new \AffiLinks\Post(); new \AffiLinks\Rest_API(); new \AffiLinks\Shortcodes(); new \AffiLinks\Track(); new \AffiLinks\Track\Rest_API(); // Initialize the action and filter hooks. $this->init_actions(); // WP_CLI. if ( defined( 'WP_CLI' ) && WP_CLI ) { add_action( 'plugins_loaded', [ $this, 'init_wp_cli' ], 20 ); } } /** * Add our custom WP-CLI commands. */ public function init_wp_cli() { WP_CLI::add_command( 'affilinks flush', [ '\AffiLinks\CLI\Commands', 'flush' ] ); } /** * Initialize WordPress action and filter hooks. */ private function init_actions() { register_activation_hook( AFFILINKS_FILE, [ $this, 'activation' ] ); } /** * Activation hook. */ public function activation() { update_option( 'affilinks_flush_rewrite_rules', 'yes' ); global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $table_name = $wpdb->prefix . 'affilinks'; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, brand_id mediumint(9) NOT NULL, affiliate_id mediumint(9) NOT NULL, affiliate_type varchar(255) DEFAULT '' NOT NULL, placeholder_id mediumint(9) NOT NULL, group_id mediumint(9) NOT NULL, action varchar(255) DEFAULT '' NOT NULL, visit_type varchar(255) DEFAULT '' NOT NULL, source_id mediumint(9) NOT NULL, source_type varchar(255) DEFAULT '' NOT NULL, entry datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); } } /** * Returns the main instance of AffiLinks to prevent the need to use globals. * * @return AffiLinks */ function affilinks() { return AffiLinks::get(); } // Start it. affilinks();