should_take_over() ) { return $data; } $data['evnetin_ai_active'] = true; $data['evnetin_pro_active'] = true; // Banner images are out of scope for now (one AI image costs hundreds of credits). // New Eventin hides the banner AI icon when this is false. $data['banner_ai_active'] = false; return $data; } /** * Give our empty class the name EventinAI, for old Eventin versions. * Runs only while admin scripts load, so it can never block activating the real plugin. * * @return bool True when the alias was made now. */ public function maybe_declare_shim(): bool { if ( ! class_exists( 'Wpeventin' ) || class_exists( 'EventinAI', false ) ) { return false; } return class_alias( Eventin_Ai_Legacy_Shim::class, 'EventinAI' ); } /** * Remove the old plugin's React bundle, so only Aisentic's AI window opens. * * @return void */ public function remove_legacy_assets(): void { if ( ! $this->legacy_plugin_active() || ! $this->should_take_over() ) { return; } wp_dequeue_script( 'etn-ai-script' ); wp_dequeue_style( 'etn-ai-style' ); } /** * Tell admins the old plugin can go. Only on the Plugins page and Eventin pages. * * @return void */ public function legacy_plugin_notice(): void { if ( ! $this->legacy_plugin_active() || ! current_user_can( 'activate_plugins' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! in_array( $screen->id, [ 'plugins', 'toplevel_page_eventin' ], true ) ) { return; } if ( get_user_meta( get_current_user_id(), self::DISMISS_META, true ) ) { return; } $dismiss_url = wp_nonce_url( add_query_arg( self::DISMISS_ACTION, '1' ), self::DISMISS_ACTION ); $message = $this->should_take_over() ? __( 'Aisentic now handles Eventin AI features. You can deactivate the Eventin AI plugin.', 'aisentic' ) : __( 'Aisentic can now handle Eventin AI features. Connect Aisentic in its settings, then you can deactivate the Eventin AI plugin.', 'aisentic' ); printf( '

%1$s %3$s

', esc_html( $message ), esc_url( $dismiss_url ), esc_html__( 'Dismiss', 'aisentic' ) ); } /** * Save that this user closed the notice. * * @return void */ public function handle_dismiss(): void { if ( empty( $_GET[ self::DISMISS_ACTION ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checked below. return; } check_admin_referer( self::DISMISS_ACTION ); update_user_meta( get_current_user_id(), self::DISMISS_META, 1 ); wp_safe_redirect( remove_query_arg( [ self::DISMISS_ACTION, '_wpnonce' ] ) ); exit; } /** * Should Aisentic handle the AI buttons? * * Yes when the old plugin is not running. When it is running, only once Aisentic * is ready, so a site that works with the old plugin keeps working. * * @return bool */ public function should_take_over(): bool { return ! $this->legacy_plugin_active() || $this->aisentic_ready(); } /** * Does the provider selected in Aisentic have its key? * * @return bool */ protected function aisentic_ready(): bool { return Llm_Provider_Factory::has_credentials( new Settings() ); } /** * Is the old Eventin AI plugin running? Its main file defines ETN_AI_VERSION. * Do not use class_exists( 'EventinAI' ): our shim makes that true. * * @return bool */ protected function legacy_plugin_active(): bool { return defined( 'ETN_AI_VERSION' ); } }