ÌìÃÀ´«Ã½
← Back
Editing: ai-features-pro.php
<?php /** * Plugin Name: AI Features * Plugin URI: https://www.echoknowledgebase.com/wordpress-add-ons/ * Description: A fully featured, easy-to-use documentation plugin with AI chat and search integration. Build beautiful knowledge bases, FAQs, docs, and wikis. * Version: 6.2.2 * Author: Echo Plugins * Author URI: https://www.echoknowledgebase.com * Text Domain: ai-features-pro * Domain Path: /languages * Copyright: (c) 2025 Echo Plugins */ if ( ! defined( 'ABSPATH' ) ) exit; // plugin name; used in KB core if ( ! defined( 'AI_FEATURES_PRO_PLUGIN_NAME' ) ) { define( 'AI_FEATURES_PRO_PLUGIN_NAME', 'AI Features' ); } /** * Main class to load the plugin. * * Singleton */ final class AI_Features_Pro { /* @var Ai_Features_Pro */ private static $instance; public static $version = '6.2.2'; const MIN_KB_VERSION = '17.111.0'; public static $plugin_dir; public static $plugin_url; public static $plugin_file = __FILE__; /* @var AIPRO_License_Handler */ public $license_handler; /** * Initialise the plugin */ private function __construct() { self::$plugin_dir = plugin_dir_path( __FILE__ ); self::$plugin_url = plugin_dir_url( __FILE__ ); } /** * Retrieve or create a new instance of this main class (avoid global vars) * * @return Ai_Features_Pro */ public static function instance() { if ( ! empty( self::$instance ) && ( self::$instance instanceof Ai_Features_Pro ) ) { return self::$instance; } self::$instance = new Ai_Features_Pro(); self::$instance->setup_system(); self::$instance->setup_plugin(); add_action( 'plugins_loaded', array( self::$instance, 'load_text_domain' ), 11 ); return self::$instance; } /** * Setup class auto-loading and other support functions. Setup custom core features. */ private function setup_system() { // autoload classes ONLY when needed by executed code rather than on every page request require_once self::$plugin_dir . 'includes/system/class-aipro-autoloader.php'; // load non-classes require_once self::$plugin_dir . 'includes/system/scripts-registration.php'; // Register AI Training Data filters globally (admin + REST) new AIPRO_AI_Training_Data(); // Register AI Notes custom post type new AIPRO_AI_Notes(); // Register AI Tag Suggestions feature new AIPRO_AI_Tag_Suggestions(); // Register Gap Analysis AIPRO_AI_Gap_Analysis::init(); // Register AI Glossary Generator AIPRO_AI_Glossary_Generator::init(); // Initialize AI Search Results hook handler AIPRO_SR_Hook_Handler::init(); // Initialize REST API Controller AIPRO_AI_REST_Controller::init(); // invoke last self::instance()->license_handler = new AIPRO_License_Handler( self::$plugin_file, self::$version ); } /** * Setup plugin before it runs. Include functions and instantiate classes based on user action */ private function setup_plugin() { $action = AIPRO_Utilities::get( 'action' ); // process action request if any if ( ! empty( $action ) ) { $this->handle_action_request( $action ); } // handle AJAX front & back-end requests (no admin, no admin bar) if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { $this->handle_ajax_requests( $action ); return; } /** @disregard P1011 */ if ( ( empty( $_REQUEST['epkb-editor-backend-mode'] ) && is_admin() ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { $this->setup_backend_classes(); return; } // Initialize email notification handler AIPRO_AI_Email_Notifications_Handler::init(); // FRONT-END with admin-bar // FRONT-END (no ajax, possibly admin bar) } /** * Handle plugin actions here such as saving settings * @param $action */ private function handle_action_request( $action ) { // Actions can be handled here if needed } /** * Handle AJAX requests coming from front-end and back-end * @param $action */ private function handle_ajax_requests( $action ) { if ( empty( $action ) ) { return; } if ( $action == 'aipro_handle_license_request' ) { new AIPRO_Add_Ons_Page(); return; } // Register AI Chat analytics filter for the analytics AJAX request if ( $action == 'epkb_get_filtered_analytics' ) { new AIPRO_AI_Chat_Analytics(); } } /** * Setup up classes when on ADMIN pages */ private function setup_backend_classes() { global $pagenow, $post; new AIPRO_Add_Ons_Page(); new AIPRO_All_Notes_Page(); new AIPRO_AI_Chat_Analytics(); add_action( 'admin_enqueue_scripts', 'aipro_load_admin_plugin_pages_resources' ); } public function load_text_domain() { /** Check for a translation file in includes/languages/plugins/echo-knowledge-base-LOCALE.mo or .php. If it does not find one, it will try the default path you specify (the /languages directory in your plugin). */ load_plugin_textdomain( 'ai-features-pro', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } // Don't allow this singleton to be cloned. public function __clone() { _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); } // Don't allow un-serializing of the class except when testing public function __wakeup() { if ( strpos($GLOBALS['argv'][0], 'phpunit') === false ) { _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); } } } // for add-on we need to register installation scripts now require_once Ai_Features_Pro::$plugin_dir . 'includes/system/plugin-setup.php'; /** * Returns the single instance of this class */ function aipro_get_instance() { if ( aipro_get_kb_core_compatibility_issue() ) { // Keep the plugin active so the admin notice remains visible until KB core is available and compatible. add_action( 'admin_notices', 'aipro_display_kb_version_mismatch_notice' ); add_action( 'network_admin_notices', 'aipro_display_kb_version_mismatch_notice' ); return null; } return Ai_Features_Pro::instance(); } /** * Get the current KB core compatibility issue, if any. * * @return string Empty string when compatible, otherwise 'missing' or 'outdated'. */ function aipro_get_kb_core_compatibility_issue() { if ( ! class_exists( 'Echo_Knowledge_Base' ) || empty( Echo_Knowledge_Base::$version ) ) { return 'missing'; } if ( version_compare( Echo_Knowledge_Base::$version, AI_Features_Pro::MIN_KB_VERSION, '<' ) ) { return 'outdated'; } return ''; } /** * Check if the current admin request belongs to a KB admin page. * * @return bool */ function aipro_is_kb_admin_request() { $post_type = empty( $_REQUEST['post_type'] ) ? '' : sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ); if ( strpos( $post_type, 'epkb_post_type_' ) === 0 ) { return true; } $taxonomy = empty( $_REQUEST['taxonomy'] ) ? '' : sanitize_key( wp_unslash( $_REQUEST['taxonomy'] ) ); return strpos( $taxonomy, 'epkb_post_type_' ) === 0; } /** * Render a persistent, non-dismissible notice when AI PRO is blocked by a missing or old KB core. */ function aipro_display_kb_version_mismatch_notice() { $kb_core_issue = aipro_get_kb_core_compatibility_issue(); if ( ! current_user_can( 'manage_options' ) || empty( $kb_core_issue ) ) { return; } if ( ! aipro_is_kb_admin_request() ) { return; } $plugins_url = is_network_admin() ? network_admin_url( 'plugins.php' ) : admin_url( 'plugins.php' ); ?> <div class="notice notice-error"> <p> <strong><?php esc_html_e( 'AI Features could not be loaded.', 'ai-features-pro' ); ?></strong> <?php if ( $kb_core_issue === 'missing' ) { if ( defined( 'AMAG_PLUGIN_NAME' ) ) { printf( /* translators: 1: current AI Features version */ esc_html__( 'AI Features %1$s requires Access Manager 14.111.0 or later, but Access Manager is not available. Activate Access Manager or resolve its loading issue, then reload this page.', 'ai-features-pro' ), esc_html( AI_Features_Pro::$version ) ); } else { printf( /* translators: 1: current AI Features version, 2: required Knowledge Base version */ esc_html__( 'AI Features %1$s requires Knowledge Base %2$s or later, but Knowledge Base is not available. Activate Knowledge Base or resolve its loading issue, then reload this page.', 'ai-features-pro' ), esc_html( AI_Features_Pro::$version ), esc_html( AI_Features_Pro::MIN_KB_VERSION ) ); } } else { if ( defined( 'AMAG_PLUGIN_NAME' ) ) { printf( /* translators: 1: current AI Features version, 2: current Access Manager version */ esc_html__( 'AI Features %1$s requires Access Manager 14.111.0 or later. You are currently running Access Manager %2$s. Update Access Manager to continue using AI Features.', 'ai-features-pro' ), esc_html( AI_Features_Pro::$version ), esc_html( Echo_Knowledge_Base::$amag_version ) ); } else { printf( /* translators: 1: current AI Features version, 2: current Knowledge Base version, 3: required Knowledge Base version */ esc_html__( 'AI Features %1$s requires Knowledge Base %3$s or later. You are currently running Knowledge Base %2$s. Update Knowledge Base to continue using AI Features.', 'ai-features-pro' ), esc_html( AI_Features_Pro::$version ), esc_html( Echo_Knowledge_Base::$version ), esc_html( AI_Features_Pro::MIN_KB_VERSION ) ); } } ?> <a href="<?php echo esc_url( $plugins_url ); ?>"><?php esc_html_e( 'Go to Plugins', 'ai-features-pro' ); ?></a> </p> </div> <?php } // ensure this happens after main KB plugin is loaded add_action( 'plugins_loaded', 'aipro_get_instance' );
Save File
Cancel