define_constants(); add_action( 'plugins_loaded', [ $this, 'init_plugin' ] ); add_action( 'wp_ajax_connect_with_appsero', [ $this, 'connect_with_appsero' ] ); // Add settings page for set API key require_once __DIR__ . '/includes/SettingsPage.php'; new Appsero\Helper\SettingsPage(); } /** * Initializes the AppSero_Helper() class * * Checks for an existing AppSero_Helper() instance * and if it doesn't find one, creates it. */ public static function instance() { if ( is_null( self::$_instance ) ) { self::$_instance = new self(); } return self::$_instance; } /** * Define the constants * * @return void */ public function define_constants() { define( 'ASHP_VERSION', $this->version ); define( 'ASHP_ROOT_PATH', plugin_dir_path( __FILE__ ) ); } /** * Initialize the plugin * * @return void */ public function init_plugin() { $this->includes(); } /** * Include the required files * * @return void */ public function includes() { if ( ! class_exists( 'WooCommerce' ) && ! class_exists( 'Easy_Digital_Downloads' ) ) { add_action( 'admin_notices', array( $this, 'dependency_error' ) ); return; } require_once __DIR__ . '/includes/functions.php'; require_once __DIR__ . '/includes/Traits/Hooker.php'; require_once __DIR__ . '/includes/Traits/Rest.php'; require_once __DIR__ . '/includes/Api.php'; require_once __DIR__ . '/includes/SendRequests.php'; if ( class_exists( 'WooCommerce' ) ) { require_once __DIR__ . '/includes/WooCommerce.php'; $client = new Appsero\Helper\WooCommerce(); } else if ( class_exists( 'Easy_Digital_Downloads' ) ) { require_once __DIR__ . '/includes/Edd.php'; $client = new Appsero\Helper\Edd(); } // Initialize API hooks new Appsero\Helper\Api( $client ); // Initialize request hooks new Appsero\Helper\SendRequests(); } /** * Admin notice for no EDD or WC */ public function dependency_error() { if ( ! current_user_can( 'manage_options' ) ) { return; } $woo = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' ); $edd = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=easy-digital-downloads' ), 'install-plugin_easy-digital-downloads' ); $needed = 'WooCommerce or '; $needed .= 'Easy Digital Downloads'; $install = sprintf( '
Install WooCommerce or Install Easy Digital Downloads
', $woo, $edd ); echo 'Appsero Helper requires ' . $needed . ' to be installed and active.
'; if ( current_user_can( 'install_plugins' ) ) { echo $install; } echo '