'15096', 'slug' => 'ai-auto-tool', 'premium_slug' => 'ai-auto-tool-pay', 'type' => 'plugin', 'public_key' => 'pk_a1bb06b76f38f9ff1132089d99b21', 'is_premium' => false, 'has_premium_version' => false, 'has_addons' => false, 'has_paid_plans' => true, 'has_affiliation' => 'all', 'menu' => array( 'slug' => 'ai_auto_tool', 'contact' => true, 'support' => false, 'network' => true, ), ) ); } return $aiautotool_premium; } aiautotool_premium(); do_action( 'aiautotool_premium_loaded' ); } aiautotool_premium()->add_filter( 'hide_freemius_powered_by', '__return_true' ); /* translators: %s là đường dẫn tới trang nâng cấp lên bản Pro của AI Auto Tool.*/ $Upgrade_notifice = sprintf('AI Auto Tool Limit Quota. Please Upgrade Pro', aiautotool_premium()->get_upgrade_url()); define('AIAUTOTOOL_TITLE_UPGRADE', $Upgrade_notifice); function aiautotool_activate() { require_once esc_html( plugin_dir_path( __FILE__ ) ) . 'vendor/aiautotool/class-ai-auto-tool-activator.php'; Ai_auto_tool_Activator::activate(); } function aiautotool_deactivate() { require_once esc_html( plugin_dir_path( __FILE__ ) ) . 'vendor/aiautotool/class-ai-auto-tool-deactivator.php'; Ai_auto_tool_Deactivator::deactivate(); } register_activation_hook( __FILE__, 'aiautotool_activate' ); register_deactivation_hook( __FILE__, 'aiautotool_deactivate' ); // Load textdomain immediately before loading any other files that might use translations // This must happen before bootstrap.php is loaded to prevent WordPress 6.7.0 warnings if (function_exists('load_plugin_textdomain')) { load_plugin_textdomain('ai-auto-tool', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } // Load Extra Config Module (MANDATORY - always loads, not dependent on active/disable) // Must load BEFORE class instantiation to ensure class exists when registering $extra_config_bootstrap = plugin_dir_path(__FILE__) . 'inc/extra-config/bootstrap.php'; if (file_exists($extra_config_bootstrap)) { require_once $extra_config_bootstrap; } // Load Floating Robot Widget EARLY to ensure admin_enqueue_scripts hook is registered // This must be loaded before AI_Auto_Tool class is instantiated to catch admin_enqueue_scripts hook if( ! class_exists( 'AI_Auto_Tool' ) ) { class AI_Auto_Tool { protected $subclasses = []; private $aiautotool_config_settings; public function __construct() { // Initialize Professional Autoloader System $this->init_autoloader_system(); // Textdomain is now loaded early in the plugin file (line ~61) before any code runs // This prevents WordPress 6.7.0 translation loading warnings // Menu registration now handled by Menu Manager // add_action( 'admin_menu', array( $this, 'add_menu_page' ) , 10, 2); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'rest_api_init', array($this,'create_post_route')); add_action('wp_ajax_aiautotool_insert_post', array( $this, 'aiautotool_insert_post_ajax' )); add_action( 'wp_ajax_aiautotool_get_cate', array( $this, 'aiautotool_get_cate' )); add_action( 'wp_ajax_get_all_media', array( $this, 'get_all_media_callback' )); add_action( 'wp_ajax_aiautotool_save_image', array( $this, 'aiautotool_save_image' )); // AJAX handlers for Bard API to avoid CORS issues add_action( 'wp_ajax_aiautotool_bard_contentmore', array( $this, 'aiautotool_bard_contentmore_callback' )); add_action( 'wp_ajax_aiautotool_bard_content', array( $this, 'aiautotool_bard_content_callback' )); add_action( 'wp_ajax_aiautotool_bard_rewrite', array( $this, 'aiautotool_bard_rewrite_callback' )); // Legacy loading methods (now handled by autoloader) // DEBUG MODE: Track memory during initialization if (defined('WP_DEBUG') && WP_DEBUG && (defined('AIAUTOTOOL_DEBUG_LOADING') && AIAUTOTOOL_DEBUG_LOADING)) { $init_memory = round(memory_get_usage(true) / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [INIT] Starting plugin initialization - Memory: {$init_memory} MB"); } self::load_lib(); if (defined('WP_DEBUG') && WP_DEBUG && (defined('AIAUTOTOOL_DEBUG_LOADING') && AIAUTOTOOL_DEBUG_LOADING)) { $after_lib_memory = round(memory_get_usage(true) / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [AFTER load_lib] Memory: {$after_lib_memory} MB"); } // self::load_inc(); self::aiautotool_new_object(); if (defined('WP_DEBUG') && WP_DEBUG && (defined('AIAUTOTOOL_DEBUG_LOADING') && AIAUTOTOOL_DEBUG_LOADING)) { $after_new_object_memory = round(memory_get_usage(true) / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [AFTER aiautotool_new_object] Memory: {$after_new_object_memory} MB"); } // Assets are now managed by Asset Manager (inc/asset-manager.php) // Old method add_aiautotool_button_js() is kept for backward compatibility // but Asset Manager handles it more efficiently with conditional loading // Register AJAX handlers for all features add_action( 'init', array( $this, 'register_all_ajax_handlers' ) ); add_filter('plugin_action_links', array( $this, 'add_ai_auto_tool_settings_link' ), 10, 2); // SSL Management AJAX handlers are registered in SSL Manager class (inc/features/ssl-manager/ssl.php) // No need to register here to avoid duplicates register_activation_hook(__FILE__, array($this, 'activate')); register_deactivation_hook(__FILE__, array($this, 'deactivate')); $aiautotool_Warning_Notice = new aiautotool_Warning_Notice(array( 'icon_url' => plugins_url('/images/logo.svg', __FILE__), 'title' => 'Aiautotool Plugin ', 'content' => 'The plugin is available for free so if it benefits you. Join the plugin support group here.', 'button_text' => 'Join group support Ai auto Tool Plugin', 'button_url' => 'https://t.me/aiautotoolchat', )); } public function init_settings() { } private function aiautotool_getdata() { return rendersetting::aiautotool_getdata(); } public function load_textdomain() { load_plugin_textdomain('ai-auto-tool', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } public function activate() { if (class_exists('activeCallBack')) { $activeCallBack = new activeCallBack(); $activeCallBack->activate(); } } public function deactivate(){ $siteurl = get_option('siteurl'); $siteurl = str_replace('https://', 'http://', $siteurl); update_option('siteurl', $siteurl); // } $home = get_option('home'); $home = str_replace('https://', 'http://', $home); update_option('home', $home); if (class_exists('activeCallBack')) { $activeCallBack = new activeCallBack(); $activeCallBack->deactivate(); } global $wpdb; $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'aiautotool_%'" ); $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'fs_%'" ); } function add_ai_auto_tool_settings_link($links, $file) { if (false !== strpos($file, 'ai-auto-tool/Ai-Auto-Tool.php')) { $settings_link = 'Settings'; array_unshift($links, $settings_link); } return $links; } public function addSubclass($subclass) { // Prevent duplicate instances foreach ($this->subclasses as $existing) { if (get_class($existing) === get_class($subclass)) { return; // Already added, skip duplicate } } $this->subclasses[] = $subclass; } public function aiautotool_new_object(){ // Static flag to prevent multiple executions static $new_object_loaded = false; if ($new_object_loaded) { return; } // Use option cache helper if available $use_cache = class_exists('AIAutoTool_OptionCache'); $is_admin_page = is_admin(); // CRITICAL OPTIMIZATION: Only load essential classes immediately // Other features will be loaded on-demand when needed (lazy loading) // Extra Config - New Architecture (required for settings) if (class_exists('Aiautotool_Extra_Config_Manager')) { $extra_config_manager = Aiautotool_Extra_Config_Manager::instance(); $this->addSubclass($extra_config_manager); } // AI Provider Settings UI - Always loaded (mandatory) if (class_exists('AIAutotool_AI_Provider_Settings_UI')) { $ai_provider_settings_ui = new AIAutotool_AI_Provider_Settings_UI(); $this->addSubclass($ai_provider_settings_ui); } // OPTIMIZED: Only load features that are active OR needed for admin UI // Features are loaded on-demand when their settings page is accessed // SSL Manager - Only load if active or on admin page $ssl_active = $use_cache ? AIAutoTool_OptionCache::is_active('aiautotool_SSL_active') : (get_option('aiautotool_SSL_active', 'false') === 'true'); if ($ssl_active || $is_admin_page) { $ssl_manager_file = plugin_dir_path(__FILE__) . 'inc/features/ssl-manager/ssl-manager.php'; $file_exists = $use_cache ? AIAutoTool_OptionCache::file_exists($ssl_manager_file) : file_exists($ssl_manager_file); if ($file_exists) { require_once $ssl_manager_file; if (class_exists('AIAutoTool\\Features\\SSLManager\\SSLManager')) { try { $ssl_manager = new \AIAutoTool\Features\SSLManager\SSLManager(); $this->addSubclass($ssl_manager); } catch (Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log('AI Auto Tool: Failed to load SSLManager: ' . $e->getMessage()); } } } } } // Autoblogging - Only load if active $autoblogging_active = $use_cache ? AIAutoTool_OptionCache::is_active('AI_AutoTool_Autoblogging_active') : (get_option('AI_AutoTool_Autoblogging_active', 'false') === 'true'); if ($autoblogging_active) { $autoblogging_file = plugin_dir_path(__FILE__) . 'inc/features/autoblogging/autoblogging.php'; $file_exists = $use_cache ? AIAutoTool_OptionCache::file_exists($autoblogging_file) : file_exists($autoblogging_file); if ($file_exists) { require_once $autoblogging_file; if (class_exists('AIAutoTool\\Features\\Autoblogging\\Autoblogging')) { try { $autoblogging = new \AIAutoTool\Features\Autoblogging\Autoblogging(); $this->addSubclass($autoblogging); } catch (Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log('AI Auto Tool: Failed to load Autoblogging: ' . $e->getMessage()); } } } } } // OPTIMIZED: Batch load features only when active or needed for admin UI // Features are defined with their active option names for efficient checking $features_to_load = array( array( 'file' => 'inc/features/image-scanner/image-scanner.php', 'class' => 'AIAutoTool\\Features\\ImageScanner\\ImageScanner', 'option' => 'AIAutotool_Image404Scanner_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/bot-security/bot-security.php', 'class' => 'AIAutoTool\\Features\\BotSecurity\\BotSecurity', 'option' => 'AIAutoToolSecurityBot_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/auto-comment/auto-comment.php', 'class' => 'AIAutoTool\\Features\\AutoComment\\AutoComment', 'option' => 'AIautotool_autocomment_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/auto-create-tags/auto-create-tags.php', 'class' => 'AIAutoTool\\Features\\AutoCreateTags\\AutoCreateTags', 'option' => 'AIautotool_autocreatetags_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/canonical-manager/canonical-manager.php', 'class' => 'AIAutoTool\\Features\\CanonicalManager\\CanonicalManager', 'option' => 'Aiautotool_Canonical_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/external-links/external-links.php', 'class' => 'AIAutoTool\\Features\\ExternalLinks\\ExternalLinks', 'option' => 'Aiautotool_exLink_backlink_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/cloudflare-ai/cloudflare-ai.php', 'class' => 'AIAutoTool\\Features\\CloudflareAI\\CloudflareAI', 'option' => 'AI_AutoTool_cloudflareAI_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/submit-index/submit-index.php', 'class' => 'AIAutoTool\\Features\\SubmitIndex\\SubmitIndex', 'option' => 'AIAutoTool_SubmitIndex_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/suggest-auto/suggest-auto.php', 'class' => 'AIAutoTool\\Features\\SuggestAuto\\SuggestAuto', 'option' => 'AI_AutoTool_suggetauto_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/username-generator/username-generator.php', 'class' => 'AIAutoTool\\Features\\UsernameGenerator\\UsernameGenerator', 'option' => 'aiautotool_AutoGenerateUsername_active', 'load_on_admin' => false ), array( 'file' => 'inc/features/web-stories/web-stories.php', 'class' => 'AIAutoTool\\Features\\WebStories\\WebStories', 'option' => 'AIautotool_Web_Stories_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/footer-base/footer-base.php', 'class' => 'AIAutoTool\\Features\\FooterBase\\FooterBase', 'option' => 'Aiautotool_footer_base_active', 'load_on_admin' => true ), array( 'file' => 'inc/features/prompt-cpt/prompt-cpt.php', 'class' => 'AIAutoTool\\Features\\PromptCPT\\PromptCPT', 'option' => 'AIautotool_Prompt_CPT_active', 'load_on_admin' => true ), ); // Batch load features foreach ($features_to_load as $feature) { $is_active = $use_cache ? AIAutoTool_OptionCache::is_active($feature['option']) : (get_option($feature['option'], 'false') === 'true'); // Load if active OR if on admin page and feature should load on admin if ($is_active || ($is_admin_page && $feature['load_on_admin'])) { $file_path = plugin_dir_path(__FILE__) . $feature['file']; $file_exists = $use_cache ? AIAutoTool_OptionCache::file_exists($file_path) : file_exists($file_path); if ($file_exists) { require_once $file_path; if (class_exists($feature['class'])) { try { $instance = new $feature['class'](); $this->addSubclass($instance); } catch (Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log('AI Auto Tool: Failed to load ' . $feature['class'] . ': ' . $e->getMessage()); } } } } } } // Legacy class loading - only if classes already exist (loaded by features above) if (class_exists('URL_Scanner_Plugin')) { $url_scanner_plugin = new URL_Scanner_Plugin(); $this->addSubclass($url_scanner_plugin); } if (class_exists('AIAutoToolsinglepost')) { $AIAutoToolsinglepost = new AIAutoToolsinglepost(); $this->addSubclass($AIAutoToolsinglepost); } if (class_exists('AIautotool_autocomment')) { $AIautotool_autocomment = new AIautotool_autocomment(); $this->addSubclass($AIautotool_autocomment); } if (class_exists('AIautotool_autocreatetags')) { $AIautotool_autocreatetags = new AIautotool_autocreatetags(); $this->addSubclass($AIautotool_autocreatetags); } if (class_exists('AI_AutoTool_cloudflareAI')) { $AI_AutoTool_cloudflareAI = new AI_AutoTool_cloudflareAI(); $this->addSubclass($AI_AutoTool_cloudflareAI); } if (class_exists('AI_AutoTool_suggetauto')) { $AI_AutoTool_suggetauto = new AI_AutoTool_suggetauto(); $this->addSubclass($AI_AutoTool_suggetauto); } if (class_exists('AIautotool_Prompt_CPT')) { $AIautotool_Prompt_CPT = new AIautotool_Prompt_CPT(); $this->addSubclass($AIautotool_Prompt_CPT); } if (class_exists('AIAutoTool_SubmitIndex')) { $AIAutoTool_SubmitIndex = new AIAutoTool_SubmitIndex(); $this->addSubclass($AIAutoTool_SubmitIndex); } if (class_exists('Aiautotool_exLink_backlink')) { $Aiautotool_exLink_backlink = new Aiautotool_exLink_backlink(); $this->addSubclass($Aiautotool_exLink_backlink); } if (class_exists('Aiautotool_Canonical')) { $Aiautotool_Canonical = new Aiautotool_Canonical(); $this->addSubclass($Aiautotool_Canonical); } if (class_exists('AIautotool_Web_Stories')) { $AIautotool_Web_Stories = new AIautotool_Web_Stories(); $this->addSubclass($AIautotool_Web_Stories); } // if (class_exists('AIAutoToolSecurityBot')) { // $AIAutoToolSecurityBot = new AIAutoToolSecurityBot(); // $this->addSubclass($AIAutoToolSecurityBot); // } // if (class_exists('AIAutotool_Image404Scanner')) { // $AIAutotool_Image404Scanner = new AIAutotool_Image404Scanner(); // $this->addSubclass($AIAutotool_Image404Scanner); // } // if (class_exists('aiautotool_AutoGenerateUsername')) { // $aiautotool_AutoGenerateUsername = new aiautotool_AutoGenerateUsername(); // $this->addSubclass($aiautotool_AutoGenerateUsername); // } // if (class_exists('Post_Exporter_Plugin')) { // $Post_Exporter_Plugin = new Post_Exporter_Plugin(); // $this->addSubclass($Post_Exporter_Plugin); // } // if (class_exists('Auto_Install_Plugins')) { // $Auto_Install_Plugins = new Auto_Install_Plugins(); // $this->addSubclass($Auto_Install_Plugins); // } // if (class_exists('Keyword_Autopost_Plugin')) { // $Keyword_Autopost_Plugin = new Keyword_Autopost_Plugin(); // $this->addSubclass($Keyword_Autopost_Plugin); // } // if (class_exists('Aiautotool_Footer_Base')) { // $Aiautotool_Footer_Base = new Aiautotool_Footer_Base(); // $this->addSubclass($Aiautotool_Footer_Base); // } // if (class_exists('aiautotool_SSL_active')) { // $aiautotool_SSL_active = new aiautotool_SSL_active(); // $this->addSubclass($aiautotool_SSL_active); // } // if (class_exists('activeCallBack')) { // $activeCallBack = new activeCallBack(); // } // if (class_exists('AI_AutoTool_Prompt_Customer')) { // $AI_AutoTool_Prompt_Customer = new AI_AutoTool_Prompt_Customer(); // } $new_object_loaded = true; } public function show_render_setting() { foreach ($this->subclasses as $subclass) { if (method_exists($subclass, 'render_setting')) { $subclass->render_setting(); } } } public function show_render_tab_setting() { foreach ($this->subclasses as $subclass) { if (method_exists($subclass, 'render_tab_setting')) { $subclass->render_tab_setting(); } } } public function render_list_feature(){ // Load only active features from inc directory $this->load_all_inc_features(); // Render all features (both active and inactive) using AutoToolBox $this->render_all_features(); } /** * Force load feature descriptions file */ private function ensure_feature_descriptions_loaded() { if (!class_exists('AiAutoTool_Feature_Descriptions')) { $file_path = plugin_dir_path(__FILE__) . 'lib/feature-descriptions.php'; if (file_exists($file_path)) { require_once $file_path; error_log('AI Auto Tool Debug: Force loaded feature-descriptions.php'); } else { error_log('AI Auto Tool Debug: feature-descriptions.php not found at: ' . $file_path); } } } /** * Get feature description with fallback * * @param string $feature_key Feature key * @param string $fallback_description Fallback description if class not available * @return string Description HTML */ private function get_feature_description($feature_key, $fallback_description = '') { // Ensure feature descriptions are loaded $this->ensure_feature_descriptions_loaded(); // Debug: Check if class exists if (!class_exists('AiAutoTool_Feature_Descriptions')) { error_log('AI Auto Tool Debug: AiAutoTool_Feature_Descriptions class not found for feature: ' . $feature_key); return $fallback_description; } $description = AiAutoTool_Feature_Descriptions::get_truncated_description($feature_key); if (empty($description)) { error_log('AI Auto Tool Debug: Empty description for feature: ' . $feature_key); return $fallback_description; } return $description; } /** * Render all features (active and inactive) using AutoToolBox * IMPORTANT FUNCTION: This method controls feature rendering in the main UI. */ private function render_all_features() { // Static flag to prevent multiple renders static $features_rendered = false; if ($features_rendered) { return; } // Cache for option values to prevent repeated database queries static $option_cache = array(); $inc_dir = plugin_dir_path(__FILE__) . 'inc/'; // Define all feature files with their metadata // NOTE: Descriptions are hardcoded here to avoid calling get_feature_description() // which could trigger recursive loading $feature_files = array( 'features/ssl-manager/ssl-manager.php' => array( 'class' => 'AIAutoTool\Features\SSLManager\SSLManager', 'active_option' => 'aiautotool_SSL_active', 'title' => 'SSL Manager', 'description' => $this->get_feature_description('ssl_fix', 'Manage SSL certificates and security settings'), 'icon' => '' ), 'features/canonical-manager/canonical-manager.php' => array( 'class' => 'AIAutoTool\Features\CanonicalManager\CanonicalManager', 'active_option' => 'Aiautotool_Canonical_active', 'title' => 'Canonical Manager', 'description' => $this->get_feature_description('canonical', 'Manage canonical URLs and redirects'), 'icon' => '' ), 'features/external-links/external-links.php' => array( 'class' => 'AIAutoTool\Features\ExternalLinks\ExternalLinks', 'active_option' => 'Aiautotool_exLink_backlink_active', 'title' => 'Auto External Links', 'description' => $this->get_feature_description('microsite_backlink', 'Automatically manage external links and backlinks'), 'icon' => '' ), 'features/submit-index/submit-index.php' => array( 'class' => 'AIAutoTool\Features\SubmitIndex\SubmitIndex', 'active_option' => 'AIAutoTool_SubmitIndex_active', 'title' => 'Submit Index', 'description' => $this->get_feature_description('google_index', 'Submit URLs to search engines for indexing'), 'icon' => '' ), 'features/post-exporter/post-exporter.php' => array( 'class' => 'AIAutoTool\Features\PostExporter\PostExporter', 'active_option' => 'Post_Exporter_Plugin_active', 'title' => 'Post Exporter', 'description' => $this->get_feature_description('post_exporter', 'Export posts and content to various formats'), 'icon' => '' ), 'features/keyword-autopost/keyword-autopost.php' => array( 'class' => 'AIAutoTool\Features\KeywordAutopost\KeywordAutopost', 'active_option' => 'Keyword_Autopost_Plugin_active', 'title' => 'Keyword Autopost', 'description' => $this->get_feature_description('keyword_autopost', 'Automatically create posts based on keywords'), 'icon' => '' ), 'features/single-ai/single-ai.php' => array( 'class' => 'AIAutoTool\Features\SingleAI\SingleAI', 'active_option' => 'AIAutoToolsinglepost_active', 'title' => 'Single AI Post', 'description' => $this->get_feature_description('single_ai', 'Create individual AI-powered posts'), 'icon' => '' ), 'features/image-scanner/image-scanner.php' => array( 'class' => 'AIAutoTool\Features\ImageScanner\ImageScanner', 'active_option' => 'AIAutotool_Image404Scanner_active', 'title' => 'Image Scanner', 'description' => $this->get_feature_description('thumb_fix', 'Scan and manage images for 404 errors'), 'icon' => '' ), 'features/auto-comment/auto-comment.php' => array( 'class' => 'AIAutoTool\Features\AutoComment\AutoComment', 'active_option' => 'AIautotool_autocomment_active', 'title' => 'Auto Comment', 'description' => $this->get_feature_description('auto_comment', 'Automatically generate and post comments using AI'), 'icon' => '' ), 'features/auto-create-tags/auto-create-tags.php' => array( 'class' => 'AIAutoTool\Features\AutoCreateTags\AutoCreateTags', 'active_option' => 'AIautotool_autocreatetags_active', 'title' => 'Auto Create Tags', 'description' => $this->get_feature_description('auto_create_tag', 'Automatically create and assign tags to posts'), 'icon' => '' ), 'features/cloudflare-ai/cloudflare-ai.php' => array( 'class' => 'AIAutoTool\Features\CloudflareAI\CloudflareAI', 'active_option' => 'AI_AutoTool_cloudflareAI_active', 'title' => 'Cloudflare AI', 'description' => $this->get_feature_description('cloudflare_ai', 'Integrate with Cloudflare AI services'), 'icon' => '' ), 'features/suggest-auto/suggest-auto.php' => array( 'class' => 'AIAutoTool\Features\SuggestAuto\SuggestAuto', 'active_option' => 'AI_AutoTool_suggetauto_active', 'title' => 'Suggest Auto', 'description' => $this->get_feature_description('suggest_auto', 'Automatically suggest content improvements'), 'icon' => '' ), 'features/prompt-cpt/prompt-cpt.php' => array( 'class' => 'AIAutoTool\Features\PromptCPT\PromptCPT', 'active_option' => 'AIautotool_Prompt_CPT_active', 'title' => 'Prompt CPT', 'description' => $this->get_feature_description('prompt_manager', 'Manage custom post types for prompts'), 'icon' => '' ), 'features/prompt-customer/prompt-customer.php' => array( 'class' => 'AIAutoTool\Features\PromptCustomer\PromptCustomer', 'active_option' => 'AI_AutoTool_Prompt_Customer_active', 'title' => 'Prompt Customer', 'description' => 'Manage customer-specific prompts', 'icon' => '' ), // Temporarily disabled due to HTML output issues 'features/bot-security/bot-security.php' => array( 'class' => 'AIAutoTool\Features\BotSecurity\BotSecurity', 'active_option' => 'AIAutoToolSecurityBot_active', 'title' => 'Bot Security', 'description' => 'Security features for bot protection', 'icon' => '' ), 'features/web-stories/web-stories.php' => array( 'class' => 'AIAutoTool\Features\WebStories\WebStories', 'active_option' => 'AIautotool_Web_Stories_active', 'title' => 'Web Stories', 'description' => $this->get_feature_description('webstories', 'Create and manage web stories'), 'icon' => '' ), 'features/install-plugin/install-plugin.php' => array( 'class' => 'AIAutoTool\Features\InstallPlugin\InstallPlugin', 'active_option' => 'Aiautotool_Install_Plugin_active', 'title' => 'Install Plugin', 'description' => $this->get_feature_description('install_plugin', 'Install and manage plugins'), 'icon' => '' ), 'features/footer-base/footer-base.php' => array( 'class' => 'AIAutoTool\Features\FooterBase\FooterBase', 'active_option' => 'Aiautotool_footer_base_active', 'title' => 'Footer Base', 'description' => 'Manage footer content and base elements', 'icon' => '' ), 'features/username-generator/username-generator.php' => array( 'class' => 'AIAutoTool\Features\UsernameGenerator\UsernameGenerator', 'active_option' => 'aiautotool_AutoGenerateUsername_active', 'title' => 'Auto Generate Username', 'description' => 'Automatically generate usernames', 'icon' => '' ), 'features/autoblogging/autoblogging.php' => array( 'class' => 'AIAutoTool\Features\Autoblogging\Autoblogging', 'active_option' => 'AI_AutoTool_Autoblogging_active', 'title' => 'Autoblogging', 'description' => 'Automatically create blog posts from URLs using AI', 'icon' => '' ), // 'cron-status-widget/cron-status-widget.php' => array( // 'class' => 'AIAutoTool_Cron_Status_Widget', // 'active_option' => 'AIAutoTool_Cron_Status_Widget_active', // 'title' => 'Cron Status Widget', // 'description' => 'Monitor and manage WordPress cron jobs', // 'icon' => '' // ), ); foreach ($feature_files as $file => $config) { $file_path = $inc_dir . $file; $class_name = $config['class']; $active_option = $config['active_option']; $title = $config['title']; $description = $config['description']; $icon = $config['icon']; // Check if file exists if (file_exists($file_path)) { // Check if feature is active - use cache to prevent repeated DB queries // Special handling: Cron Status Widget is always active if ($active_option === 'AIAutoTool_Cron_Status_Widget_active') { $is_active = 'true'; // Always active, cannot be disabled // Ensure option is set to true if (!isset($option_cache[$active_option])) { update_option($active_option, 'true'); $option_cache[$active_option] = 'true'; } } else { if (!isset($option_cache[$active_option])) { $option_cache[$active_option] = get_option($active_option, false); } $is_active = $option_cache[$active_option]; } $active = ($is_active === 'true' || $is_active === true); // Create AutoToolBox for this feature $box = new AutoToolBox( $icon . ' ' . $title, $description, admin_url('admin.php?page=aiautotool_integrations'), $active_option, $active, '', false ); // Render the box echo $box->generateHTML(); } } $features_rendered = true; } /** * Register AJAX handlers for all features */ public function register_all_ajax_handlers() { $active_options = array( 'aiautotool_SSL_active', 'Aiautotool_Canonical_active', 'Aiautotool_exLink_backlink_active', 'AIAutoTool_SubmitIndex_active', 'Post_Exporter_Plugin_active', 'Keyword_Autopost_Plugin_active', 'AIAutoToolsinglepost_active', 'AIAutotool_Image404Scanner_active', 'AIautotool_autocomment_active', 'AIautotool_autocreatetags_active', 'AI_AutoTool_cloudflareAI_active', 'AI_AutoTool_suggetauto_active', 'AIautotool_Prompt_CPT_active', // Temporarily disabled due to HTML output issues 'AIAutoToolSecurityBot_active', 'AIautotool_Web_Stories_active', 'Aiautotool_Install_Plugin_active', 'AI_AutoTool_Autoblogging_active', 'AIAutoTool_Cron_Status_Widget_active', 'aiautotool_AutoGenerateUsername_active', 'Aiautotool_footer_base_active', ); foreach ($active_options as $option) { // Register AJAX handler for this option (requires authentication - options modification) add_action('wp_ajax_update_active_option_canonical_' . $option, array($this, 'generic_update_active_option_callback')); } } /** * Generic AJAX callback for updating active options */ public function generic_update_active_option_callback() { check_ajax_referer('aiautotool_nonce', 'security'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Permission denied', 'ai-auto-tool')), 403); return; } if (isset($_POST['active'])) { $active = sanitize_text_field($_POST['active']); // Get the option name from the action hook $action = current_action(); $option_name = str_replace('wp_ajax_update_active_option_canonical_', '', $action); // Update the option update_option($option_name, $active, null, 'no'); // Return the new value wp_send_json_success(array('active' => $active, 'option' => $option_name)); } wp_send_json_error('Invalid request'); } /** * Tải tất cả các tính năng từ thư mục inc và thêm vào subclasses * Chỉ tải các tính năng đang được kích hoạt * CHẾ ĐỘ DEBUG: Bao gồm từng tệp một để theo dõi mức sử dụng bộ nhớ */ private function load_all_inc_features() { // Static flag to prevent multiple loads static $features_loaded = false; if ($features_loaded) { return; } // DEBUG MODE: Enable to track memory usage per file $debug_mode = defined('WP_DEBUG') && WP_DEBUG && (defined('AIAUTOTOOL_DEBUG_LOADING') && AIAUTOTOOL_DEBUG_LOADING); // Cache for option values to prevent repeated database queries static $option_cache = array(); $inc_dir = plugin_dir_path(__FILE__) . 'inc/'; // Define all feature files, their classes, and active option names $feature_files = array( 'features/ssl-manager/ssl-manager.php' => array( 'class' => 'AIAutoTool\Features\SSLManager\SSLManager', 'active_option' => 'aiautotool_SSL_active' ), 'features/canonical-manager/canonical-manager.php' => array( 'class' => 'AIAutoTool\Features\CanonicalManager\CanonicalManager', 'active_option' => 'Aiautotool_Canonical_active' ), 'features/external-links/external-links.php' => array( 'class' => 'AIAutoTool\Features\ExternalLinks\ExternalLinks', 'active_option' => 'Aiautotool_exLink_backlink_active' ), 'features/submit-index/submit-index.php' => array( 'class' => 'AIAutoTool\Features\SubmitIndex\SubmitIndex', 'active_option' => 'AIAutoTool_SubmitIndex_active' ), 'features/post-exporter/post-exporter.php' => array( 'class' => 'AIAutoTool\Features\PostExporter\PostExporter', 'active_option' => 'Post_Exporter_Plugin_active' ), 'features/keyword-autopost/keyword-autopost.php' => array( 'class' => 'AIAutoTool\Features\KeywordAutopost\KeywordAutopost', 'active_option' => 'Keyword_Autopost_Plugin_active' ), 'features/single-ai/single-ai.php' => array( 'class' => 'AIAutoTool\Features\SingleAI\SingleAI', 'active_option' => 'AIAutoToolsinglepost_active' ), 'features/image-scanner/image-scanner.php' => array( 'class' => 'AIAutoTool\Features\ImageScanner\ImageScanner', 'active_option' => 'AIAutotool_Image404Scanner_active' ), 'features/auto-comment/auto-comment.php' => array( 'class' => 'AIAutoTool\Features\AutoComment\AutoComment', 'active_option' => 'AIautotool_autocomment_active' ), 'features/auto-create-tags/auto-create-tags.php' => array( 'class' => 'AIAutoTool\Features\AutoCreateTags\AutoCreateTags', 'active_option' => 'AIautotool_autocreatetags_active' ), 'features/cloudflare-ai/cloudflare-ai.php' => array( 'class' => 'AIAutoTool\Features\CloudflareAI\CloudflareAI', 'active_option' => 'AI_AutoTool_cloudflareAI_active' ), 'features/suggest-auto/suggest-auto.php' => array( 'class' => 'AIAutoTool\Features\SuggestAuto\SuggestAuto', 'active_option' => 'AI_AutoTool_suggetauto_active' ), 'features/prompt-cpt/prompt-cpt.php' => array( 'class' => 'AIAutoTool\Features\PromptCPT\PromptCPT', 'active_option' => 'AIautotool_Prompt_CPT_active' ), 'features/prompt-customer/prompt-customer.php' => array( 'class' => 'AIAutoTool\Features\PromptCustomer\PromptCustomer', 'active_option' => 'AI_AutoTool_Prompt_Customer_active' ), // Temporarily disabled due to HTML output issues 'features/bot-security/bot-security.php' => array( 'class' => 'AIAutoTool\Features\BotSecurity\BotSecurity', 'active_option' => 'AIAutoToolSecurityBot_active' ), 'features/web-stories/web-stories.php' => array( 'class' => 'AIAutoTool\Features\WebStories\WebStories', 'active_option' => 'AIautotool_Web_Stories_active' ), 'features/install-plugin/install-plugin.php' => array( 'class' => 'AIAutoTool\Features\InstallPlugin\InstallPlugin', 'active_option' => 'Aiautotool_Install_Plugin_active' ), 'features/footer-base/footer-base.php' => array( 'class' => 'AIAutoTool\Features\FooterBase\FooterBase', 'active_option' => 'Aiautotool_footer_base_active' ), 'features/username-generator/username-generator.php' => array( 'class' => 'AIAutoTool\Features\UsernameGenerator\UsernameGenerator', 'active_option' => 'aiautotool_AutoGenerateUsername_active' ), 'features/autoblogging/autoblogging.php' => array( 'class' => 'AIAutoTool\Features\Autoblogging\Autoblogging', 'active_option' => 'AI_AutoTool_Autoblogging_active' ), ); foreach ($feature_files as $file => $config) { $file_path = $inc_dir . $file; $class_name = $config['class']; $active_option = $config['active_option']; // Check if file exists and class is not already loaded if (file_exists($file_path) && !$this->is_class_loaded($class_name)) { // Check if feature is active - use cache to prevent repeated DB queries // Special handling: Cron Status Widget is always active if ($active_option === 'AIAutoTool_Cron_Status_Widget_active') { $is_active = 'true'; // Always active, cannot be disabled // Ensure option is set to true if (!isset($option_cache[$active_option])) { update_option($active_option, 'true'); $option_cache[$active_option] = 'true'; } } else { if (!isset($option_cache[$active_option])) { $option_cache[$active_option] = get_option($active_option, false); } $is_active = $option_cache[$active_option]; } // CRITICAL: Don't instantiate classes here to prevent memory exhaustion // Classes will be loaded on-demand when actually needed // Only require the file to ensure it's available if needed if (!class_exists($class_name)) { // DEBUG MODE: Track memory before and after loading each file if ($debug_mode) { $memory_before = memory_get_usage(true); $memory_before_mb = round($memory_before / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [BEFORE] Loading {$file} - Memory: {$memory_before_mb} MB"); } try { require_once $file_path; if ($debug_mode) { $memory_after = memory_get_usage(true); $memory_after_mb = round($memory_after / 1024 / 1024, 2); $memory_diff = round(($memory_after - $memory_before) / 1024 / 1024, 2); $peak_memory = round(memory_get_peak_usage(true) / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [AFTER] Loaded {$file} - Memory: {$memory_after_mb} MB (+{$memory_diff} MB) - Peak: {$peak_memory} MB"); // Warn if memory increase is significant if ($memory_diff > 5) { error_log("AI Auto Tool DEBUG: ⚠️ WARNING - {$file} increased memory by {$memory_diff} MB!"); } } } catch (Exception $e) { if ($debug_mode) { error_log("AI Auto Tool DEBUG: ❌ ERROR loading {$file}: " . $e->getMessage()); } // Continue with next file even if one fails continue; } catch (Error $e) { if ($debug_mode) { error_log("AI Auto Tool DEBUG: ❌ FATAL ERROR loading {$file}: " . $e->getMessage()); } // Continue with next file even if one fails continue; } } // DO NOT instantiate here - causes memory exhaustion // Instantiation will happen on-demand via render_all_features() or when feature is actually used /* // Check if class exists if (class_exists($class_name)) { try { $instance = new $class_name(); // Only add classes that have render_feature method if (method_exists($instance, 'render_feature')) { $this->addSubclass($instance); if (defined('WP_DEBUG') && WP_DEBUG) { error_log("AI Auto Tool: Loaded feature {$class_name} from {$file} (active: " . ($is_active ? 'yes' : 'no') . ")"); } } else { if (defined('WP_DEBUG') && WP_DEBUG) { error_log("AI Auto Tool: Skipped {$class_name} - no render_feature method"); } } } catch (Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log("AI Auto Tool: Failed to load {$class_name}: " . $e->getMessage()); } } } */ } } if ($debug_mode) { $final_memory = round(memory_get_usage(true) / 1024 / 1024, 2); $peak_memory = round(memory_get_peak_usage(true) / 1024 / 1024, 2); error_log("AI Auto Tool DEBUG: [COMPLETE] load_all_inc_features() finished - Final Memory: {$final_memory} MB - Peak: {$peak_memory} MB"); } $features_loaded = true; } /** * Check if a class is already loaded in subclasses */ private function is_class_loaded($class_name) { foreach ($this->subclasses as $subclass) { if (get_class($subclass) === $class_name) { return true; } } return false; } public function render_plan(){ // Track rendered features by active_option_name to prevent duplicates $rendered_features = array(); foreach ($this->subclasses as $subclass) { // Check if this feature has already been rendered if (isset($subclass->active_option_name)) { $option_name = $subclass->active_option_name; // Skip if already rendered if (isset($rendered_features[$option_name])) { continue; } // Mark as rendered $rendered_features[$option_name] = true; } // Only render if feature is active if (method_exists($subclass, 'render_plan')) { $subclass->render_plan(); } } } /** * Initialize Professional Autoloader System */ private function init_autoloader_system() { // Load Asset Manager FIRST (before other components that may need it) $asset_manager_file = plugin_dir_path(__FILE__) . 'inc/asset-manager.php'; if (file_exists($asset_manager_file)) { require_once $asset_manager_file; } // Load autoloader components $autoloader_files = array( 'inc/option-cache.php', // Load option cache FIRST for performance 'inc/autoloader.php', 'inc/class-mapper.php', 'inc/lazy-loader.php', 'inc/optimized-loader.php', 'inc/feature-options.php', 'inc/feature-manager.php', 'inc/migration.php', 'inc/menu-manager.php', // Add menu manager 'inc/class-duplicate-fixer.php', // Add duplicate fixer 'inc/menu-test.php', // Add menu test ); foreach ($autoloader_files as $file) { $file_path = plugin_dir_path(__FILE__) . $file; if (file_exists($file_path)) { require_once $file_path; } } // Initialize autoloader if (class_exists('AIAutoTool_Autoloader')) { AIAutoTool_Autoloader::init(); } // Initialize lazy loader if (class_exists('AIAutoTool_LazyLoader')) { AIAutoTool_LazyLoader::init(); } // Initialize menu manager if (class_exists('AIAutoTool_MenuManager')) { AIAutoTool_MenuManager::init($this); } // Initialize feature options if (class_exists('AIAutoTool_FeatureOptions')) { AIAutoTool_FeatureOptions::init_default_options(); } // CRITICAL FIX: Defer class map generation to avoid memory exhaustion // Only generate on-demand or via admin action, not during plugin initialization // This prevents recursive file scanning that can exhaust memory // The autoloader will work without the generated map using fallback methods /* if (class_exists('AIAutoTool_ClassMapper')) { AIAutoTool_ClassMapper::generateClassMap(); } */ if (defined('WP_DEBUG') && WP_DEBUG) { error_log('AI Auto Tool: Professional autoloader system initialized'); } } /** * Legacy load_inc method - now uses lazy loading * @deprecated Use AIAutoTool_LazyLoader instead */ public function load_inc() { // Load rendersetting class first (required by many inc classes) $rendersetting_file = plugin_dir_path(__FILE__) . 'lib/setting.php'; if (file_exists($rendersetting_file)) { require_once $rendersetting_file; } // Load essential library classes (required by many inc classes) $essential_lib_files = array( 'lib/aiautotool_notice_control.php', // aiautotool_Warning_Notice 'lib/boxf.php', // AutoToolBox 'lib/bard.php', // BardGenContent 'lib/AIautotool_logall.php', // AIautoTool_log 'lib/feature-descriptions.php', // AiAutoTool_Feature_Descriptions ); foreach ($essential_lib_files as $file) { $file_path = plugin_dir_path(__FILE__) . $file; if (file_exists($file_path)) { require_once $file_path; // Debug: Log when feature-descriptions.php is loaded if ($file === 'lib/feature-descriptions.php') { error_log('AI Auto Tool Debug: feature-descriptions.php loaded successfully'); if (class_exists('AiAutoTool_Feature_Descriptions')) { error_log('AI Auto Tool Debug: AiAutoTool_Feature_Descriptions class exists'); } else { error_log('AI Auto Tool Debug: AiAutoTool_Feature_Descriptions class NOT found after loading file'); } } } else { // Debug: Log if file doesn't exist if ($file === 'lib/feature-descriptions.php') { error_log('AI Auto Tool Debug: feature-descriptions.php file not found at: ' . $file_path); } } } // This method is now handled by the autoloader system // Only load core files immediately (excluding API manager - handled by autoloader) $core_files = array( 'inc/canonical.php', 'inc/ssl.php', ); foreach ($core_files as $file) { $file_path = plugin_dir_path(__FILE__) . $file; if (file_exists($file_path)) { require_once $file_path; } } // Load AI Providers Module (MUST load before features that use AI) $ai_providers_index = plugin_dir_path(__FILE__) . 'inc/ai-providers/index.php'; if (file_exists($ai_providers_index)) { require_once $ai_providers_index; } // Load new Extra Config architecture $extra_config_bootstrap = plugin_dir_path(__FILE__) . 'inc/extra-config/bootstrap.php'; if (file_exists($extra_config_bootstrap)) { require_once $extra_config_bootstrap; } } /** * Legacy load_lib method - now uses lazy loading * @deprecated Use AIAutoTool_LazyLoader instead * FIXED: Only load essential files, not all files in lib directory * This prevents memory exhaustion from loading unnecessary files */ public function load_lib() { // Static flag to prevent multiple loads static $lib_loaded = false; if ($lib_loaded) { return; } // Only load essential library files that are required immediately // Other files will be loaded on-demand by the autoloader $essential_files = array( 'lib/setting.php', // rendersetting class - required by many features 'lib/aiautotool_notice_control.php', // aiautotool_Warning_Notice ); foreach ($essential_files as $file) { $file_path = plugin_dir_path(__FILE__) . $file; if (file_exists($file_path)) { require_once $file_path; } } $lib_loaded = true; // Note: Other lib files will be loaded on-demand via autoloader // This prevents loading all files upfront which causes memory issues } /** * Get autoloader statistics */ public function get_autoloader_stats() { if (class_exists('AIAutoTool_Autoloader')) { return AIAutoTool_Autoloader::getStats(); } return array(); } /** * Get lazy loader statistics */ public function get_lazy_loader_stats() { if (class_exists('AIAutoTool_LazyLoader')) { return AIAutoTool_LazyLoader::getStats(); } return array(); } /** * Force load feature */ public function load_feature($feature_name) { if (class_exists('AIAutoTool_LazyLoader')) { return AIAutoTool_LazyLoader::loadFeature($feature_name); } return false; } /** * Check if feature is loaded */ public function is_feature_loaded($feature_name) { if (class_exists('AIAutoTool_LazyLoader')) { return AIAutoTool_LazyLoader::isFeatureLoaded($feature_name); } return false; } /** * Legacy method for backward compatibility * Assets are now managed by Asset Manager (inc/asset-manager.php) * This method is kept for any external code that might call it directly * * @deprecated Use AIAutoTool_Asset_Manager instead */ public function add_aiautotool_button_js() { // Asset Manager now handles this, but we keep this method for backward compatibility // Assets will be loaded automatically by Asset Manager on plugin pages if (defined('WP_DEBUG') && WP_DEBUG) { error_log('AI Auto Tool: add_aiautotool_button_js() called (deprecated - use Asset Manager)'); } } /** * Ensure scripts are loaded for integrations page * Assets are now handled by Asset Manager * * @deprecated Use AIAutoTool_Asset_Manager instead */ public function ensure_integrations_scripts($hook) { // Asset Manager now handles this automatically // This method is kept for backward compatibility } public function add_menu_page() { add_menu_page( ' Ai Auto Tool', ' Ai Auto Tool', 'manage_options', MENUSUBPARRENT, array( $this, 'menu_page' ), 'data:image/svg+xml;base64,' . base64_encode(file_get_contents(plugin_dir_path(__FILE__) . '/images/logo.svg')), 3 ); add_submenu_page( MENUSUBPARRENT, ' Integrations', ' Integrations', 'manage_options', 'aiautotool_integrations', array($this, 'aiautotool_integrations') ); } public function aiautotool_integrations(){ ?>
SSL class not found. Please check if the SSL feature is properly loaded.
New API key added.
Reset log Images Success!!!!.
Remove log item image Success!!!!.