file = $file; $this->setup(); } /** * Setup plugin configuration and hooks. * * @since 1.0.0 * @return void */ private function setup() { $this->setup_config(); if ( ! $this->check_dependencies() ) { return; } $this->includes(); $this->init_hooks(); } /** * Setup plugin configuration. * * @since 1.0.0 * @return void */ private function setup_config() { $this->config = array( 'version' => self::VERSION, 'file' => $this->file, 'path' => dirname( $this->file ), 'includes' => dirname( $this->file ) . '/includes', 'url' => plugins_url( '', $this->file ), 'assets' => plugins_url( 'assets', $this->file ), 'basename' => plugin_basename( $this->file ), 'settings_url' => admin_url( 'admin.php?page=ai-stock-predictor' ), 'docs_url' => 'https://pluginmagnet.com/docs/ai-stock-predictor/', 'support_url' => 'https://pluginmagnet.com/support/', ); define( 'AISTPR_VERSION', self::VERSION ); define( 'AISTPR_TEMPLATE_PATH', plugin_dir_path( __FILE__ ) . 'templates/' ); } /** * Check plugin dependencies. * * @since 1.0.0 * @return bool */ private function check_dependencies() { if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); return false; } return true; } /** * Gets the single instance of the class. * * @since 1.0.0 * * @param string $file Plugin base file. * * @return static */ public static function instance( $file = '' ) { if ( null === self::$instance ) { if ( empty( $file ) ) { wp_die( esc_html__( 'AI Stock Predictor plugin file not set', 'ai-stock-predictor' ) ); } self::$instance = new self( $file ); } return self::$instance; } /** * Include required files. * * @since 1.0.0 * @return void */ private function includes() { if ( file_exists( $this->config['path'] . '/vendor/autoload.php' ) ) { require_once $this->config['path'] . '/vendor/autoload.php'; } require_once $this->config['includes'] . '/functions.php'; if ( is_admin() ) { require_once $this->config['includes'] . '/Admin/Admin.php'; } } /** * Hook into actions and filters. * * @since 1.0.0 * @return void */ private function init_hooks() { add_action( 'before_woocommerce_init', array( $this, 'woocommerce_hpos_issue' ) ); add_action( 'woocommerce_init', array( $this, 'init' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } /** * Handle WooCommerce HPOS compatibility. * * @since 1.0.0 * @return void */ public function woocommerce_hpos_issue() { if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->config['file'], true ); \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $this->config['file'], true ); } } /** * Init the plugin after WooCommerce is loaded. * * @since 1.0.0 * @return void */ public function init() { if ( is_admin() ) { new Admin\Admin(); } /** * Plugin initialization action. * * @since 1.0.0 * @param Plugin $plugin Plugin instance. */ do_action( 'aistpr_init', $this ); } /** * Display WooCommerce missing notice. * * @since 1.0.0 * @return void */ public function woocommerce_missing_notice() { ?>