init(); $this->init_classes(); register_activation_hook( $this->plugin_file, [ $this, 'activate' ] ); register_deactivation_hook( $this->plugin_file, [ $this, 'deactivate' ] ); add_action( 'plugins_loaded', [ $this, 'maybe_run_migrations' ] ); } /** * Initialize the plugin. * * @return void */ protected function init(): void { $this->version = '1.1.2'; $this->plugin_file = AISENTIC_FILE; $this->plugin_directory = AISENTIC_DIR; $this->basename = plugin_basename( $this->plugin_file ); $this->text_domain_directory = $this->plugin_directory . '/languages'; $this->template_directory = $this->plugin_directory . '/templates'; $this->plugin_url = plugins_url( '', $this->plugin_file ); $this->assets_url = $this->plugin_url . '/assets'; $this->build_url = $this->plugin_url . '/build'; } /** * Init classes * * @return void */ protected function init_classes() { $this->get_container()->get( 'global' ); } /** * Get container * * @return Container */ public function get_container() { return aisentic_container(); } /** * Initializes the Aisentic class. * * Checks for an existing Aisentic instance * and if it doesn't find one, creates it. * * @return Init */ public static function instance(): Init { static $instance = false; if ( ! $instance ) { $instance = new self(); } return $instance; } /** * Run migrations if the plugin version has changed. * * WordPress does not re-fire the activation hook on plugin updates, * so this ensures new migrations are applied when the plugin is updated. * * @return void */ public function maybe_run_migrations() { $stored_version = get_option( 'aisentic_db_version' ); if ( $stored_version !== $this->version ) { Migration_Runner::migrate(); update_option( 'aisentic_db_version', $this->version ); } } /** * Trigger plugin activation class * * @return void */ public function activate() { Activate::run(); } /** * Trigger plugin deactivation class * * @return void */ public function deactivate() { Deactivate::run(); } }