* Author URI: https://www.aica-assistant.com * Text Domain: aica-smart-ai-commerce-assistant * Domain Path: /languages * Requires at least: 6.0 * Tested up to: 6.9 * Requires PHP: 7.4 * WC requires at least: 7.0 * WC tested up to: 9.0 * License: GPL v2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @package AICA_Smart_AI_Commerce_Assistant * @author joseph78developer * @since 1.0.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } // Define plugin constants if ( ! defined( 'AICA_VERSION' ) ) { define( 'AICA_VERSION', '1.0.5' ); } if ( ! defined( 'AICA_PLUGIN_DIR' ) ) { define( 'AICA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); } if ( ! defined( 'AICA_PLUGIN_URL' ) ) { define( 'AICA_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); } if ( ! defined( 'AICA_PLUGIN_BASENAME' ) ) { define( 'AICA_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); } /** * Main Plugin Class */ if ( ! class_exists( 'AICA_Smart_AI_Commerce_Assistant' ) ) { class AICA_Smart_AI_Commerce_Assistant { /** * Singleton instance * * @var AICA_Smart_AI_Commerce_Assistant */ private static $instance = null; /** * Get the singleton instance. * * @return AICA_Smart_AI_Commerce_Assistant */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Constructor. */ private function __construct() { $this->load_dependencies(); $this->define_admin_hooks(); // Initialize sub-classes on plugins_loaded to ensure WP is ready add_action( 'plugins_loaded', array( $this, 'init' ) ); // Activation/Deactivation register_activation_hook( __FILE__, array( $this, 'activate' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); // Assets add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); // WooCommerce compatibility add_action( 'before_woocommerce_init', array( $this, 'declare_woocommerce_compatibility' ) ); } /** * Define admin specific hooks */ private function define_admin_hooks() { // Add Settings Link add_filter( 'plugin_action_links_' . AICA_PLUGIN_BASENAME, array( $this, 'add_action_links' ) ); } /** * Add settings link to plugin list * * @param array $links Existing links * @return array Modified links */ public function add_action_links( $links ) { $settings_link = '' . __( 'Settings', 'aica-smart-ai-commerce-assistant' ) . ''; array_unshift( $links, $settings_link ); return $links; } /** * Load plugin dependencies. * * @return void */ private function load_dependencies() { // Core classes require_once plugin_dir_path( __FILE__ ) . 'includes/class-installer.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-product-indexer.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-ai-engine.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-cart-manager.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-analytics.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-conversion-tracking.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-onboarding.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-system-prompts.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-order-tracking.php'; // NEW // API endpoints require_once plugin_dir_path( __FILE__ ) . 'api/class-rest-api.php'; // Admin classes if ( is_admin() ) { require_once plugin_dir_path( __FILE__ ) . 'admin/class-admin-settings.php'; require_once plugin_dir_path( __FILE__ ) . 'admin/class-admin-menu.php'; require_once plugin_dir_path( __FILE__ ) . 'admin/class-magic-prompts.php'; require_once plugin_dir_path( __FILE__ ) . 'admin/class-system-health.php'; } } /** * Initialize plugin after WordPress loads. * * @return void */ public function init() { load_plugin_textdomain( 'aica-smart-ai-commerce-assistant', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); // Initialize Admin classes regardless of WooCommerce status // so the user can see the requirement notice and access settings if ( is_admin() ) { AICA_Onboarding::get_instance(); AICA_Admin_Menu::get_instance(); AICA_Admin_Settings::get_instance(); AICA_Magic_Prompts::get_instance(); AICA_System_Health::get_instance(); } if ( ! $this->is_woocommerce_active() ) { add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); return; } // Initialize frontend/API instances (requires WooCommerce) AICA_REST_API::get_instance(); AICA_Product_Indexer::get_instance(); AICA_Cart_Manager::get_instance(); AICA_Analytics::get_instance(); AICA_Conversion_Tracking::get_instance(); AICA_System_Prompts::get_instance(); AICA_Order_Tracking::get_instance(); // NEW } /** * Check if WooCommerce is active. * * @return bool True if WooCommerce is active, false otherwise. */ private function is_woocommerce_active() { return class_exists( 'WooCommerce' ); } /** * Declare WooCommerce HPOS and blocks compatibility. * * @return void */ public function declare_woocommerce_compatibility() { if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true ); } } /** * Display admin notice when WooCommerce is not active. * * @return void */ public function woocommerce_missing_notice() { ?>

WooCommerce' ); ?>

rest_url( 'ai-assistant/v1/' ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'settings' => array( 'position' => $settings['widget_position'] ?? 'bottom-right', 'primaryColor' => $settings['primary_color'] ?? '#0066FF', 'widgetTitle' => $settings['widget_title'] ?? __( 'AI Assistant', 'aica-smart-ai-commerce-assistant' ), 'greeting' => $settings['greeting_message'] ?? __( 'Hi! How can I help you today?', 'aica-smart-ai-commerce-assistant' ), 'defaultTheme' => $settings['default_theme'] ?? 'auto', // AGGIUNTO 'magic_prompts' => array_values( $enabled_prompts ), ), 'i18n' => array( 'typing' => __( 'Typing...', 'aica-smart-ai-commerce-assistant' ), 'send' => __( 'Send', 'aica-smart-ai-commerce-assistant' ), 'placeholder' => __( 'Type your message...', 'aica-smart-ai-commerce-assistant' ), 'addToCart' => __( 'Add to Cart', 'aica-smart-ai-commerce-assistant' ), 'viewProduct' => __( 'View', 'aica-smart-ai-commerce-assistant' ), 'inStock' => __( 'In Stock', 'aica-smart-ai-commerce-assistant' ), 'outOfStock' => __( 'Out of Stock', 'aica-smart-ai-commerce-assistant' ), 'close' => __( 'Close', 'aica-smart-ai-commerce-assistant' ), 'minimize' => __( 'Minimize', 'aica-smart-ai-commerce-assistant' ), 'maximize' => __( 'Maximize', 'aica-smart-ai-commerce-assistant' ), 'enterToSend' => __( 'Press Enter to send, Shift+Enter for new line', 'aica-smart-ai-commerce-assistant' ), // AGGIUNTO 'switchToDark' => __( 'Switch to dark mode', 'aica-smart-ai-commerce-assistant' ), // AGGIUNTO 'switchToLight' => __( 'Switch to light mode', 'aica-smart-ai-commerce-assistant' ), ), 'currency' => array( 'symbol' => html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' ), 'position' => get_option( 'woocommerce_currency_pos' ), 'thousand_sep' => get_option( 'woocommerce_price_thousand_sep' ), 'decimal_sep' => get_option( 'woocommerce_price_decimal_sep' ), 'decimals' => absint( get_option( 'woocommerce_price_num_decimals', 2 ) ), ), ) ); // Inline CSS per variabili personalizzate $custom_css = sprintf( ':root { --aica-primary-color: %s; }', esc_attr( $settings['primary_color'] ?? '#0066FF' ) ); wp_add_inline_style( 'aica-widget', $custom_css ); } /** * Enqueue admin scripts and styles. * * @param string $hook Current admin page hook. * @return void */ public function enqueue_admin_assets( $hook ) { if ( strpos( $hook, 'aica-smart-ai-commerce-assistant' ) === false ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'aica-admin', AICA_PLUGIN_URL . 'assets/admin/admin.css', array( 'wp-color-picker' ), AICA_VERSION ); wp_enqueue_script( 'aica-admin', AICA_PLUGIN_URL . 'assets/admin/admin.js', array( 'jquery', 'wp-color-picker' ), AICA_VERSION, true ); wp_localize_script( 'aica-admin', 'aicaAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aica_admin' ), 'i18n' => array( 'indexing' => __( 'Indexing...', 'aica-smart-ai-commerce-assistant' ), 'success' => __( 'Success!', 'aica-smart-ai-commerce-assistant' ), 'error' => __( 'Error occurred', 'aica-smart-ai-commerce-assistant' ), ), ) ); } } } // Initialize /** * Initialize the plugin. * * @return AICA_Smart_AI_Commerce_Assistant Instance of the plugin. */ if ( ! function_exists( 'aica_init' ) ) { function aica_init() { if ( class_exists( 'AICA_Smart_AI_Commerce_Assistant' ) ) { return AICA_Smart_AI_Commerce_Assistant::get_instance(); } } } aica_init();