100) { return 100; } return $limit; } } // Add upgrade notice for existing users add_action('admin_notices', function () { if (!current_user_can('manage_options')) { return; } // Handle dismissal early (before output) and persist if (isset($_GET['aivesese_dismiss_cli_upgrade']) && check_admin_referer('aivesese_cli_upgrade_nonce')) { update_option('aivesese_cli_upgrade_notice_dismissed', time()); wp_safe_redirect(remove_query_arg(['aivesese_dismiss_cli_upgrade', '_wpnonce'])); exit; } // Show enhanced setup notice (skip if dismissed) $current_version = get_option('aivesese_plugin_version'); $dismissed = get_option('aivesese_cli_upgrade_notice_dismissed'); if (!$dismissed && $current_version && version_compare($current_version, '0.17.0', '<')) { $dismiss_url = wp_nonce_url( add_query_arg('aivesese_dismiss_cli_upgrade', '1'), 'aivesese_cli_upgrade_nonce' ); echo '
'; echo '

🎉 AI Vector Search - WP-CLI Support Added!

'; echo '

New Professional Installation Method:

'; echo ''; echo '

Setup: Add your PostgreSQL connection string in '; echo 'Settings - AI Supabase '; echo 'and use WP-CLI commands for reliable schema management.

'; echo '

'; echo 'Configure Connection '; echo 'Dismiss'; echo '

'; echo '
'; } }); // Add plugin action links add_filter('plugin_action_links_' . plugin_basename(__FILE__), function ($links) { $connection_mode = get_option('aivesese_connection_mode', 'lite'); $settings_link = 'Settings'; $status_link = 'Status'; // Add WP-CLI indicator $cli_indicator = ''; if (defined('WP_CLI') && WP_CLI && get_option('aivesese_postgres_connection_string')) { $cli_indicator = '⚡ CLI Ready'; } elseif (defined('WP_CLI') && WP_CLI) { $cli_indicator = '⚡ CLI Available'; } if ($connection_mode === 'api') { $mode_indicator = 'API Mode'; } elseif ($connection_mode === 'lite') { $mode_indicator = 'Lite Mode'; } else { $mode_indicator = 'Self-Hosted'; } $result_links = [$settings_link, $status_link, $mode_indicator]; if ($cli_indicator) { $result_links[] = $cli_indicator; } return array_merge($result_links, $links); }, 10, 1); // Add plugin row meta add_filter('plugin_row_meta', function ($links, $file) { if ($file === plugin_basename(__FILE__)) { $row_meta = [ 'docs' => 'Documentation', 'support' => 'Support', 'api_service' => '🚀 Get API Service' ]; return array_merge($links, $row_meta); } return $links; }, 10, 2); // Add admin body class for styling add_filter('admin_body_class', function ($classes) { $screen = get_current_screen(); if ($screen && strpos($screen->id, 'aivesese') !== false) { $connection_mode = get_option('aivesese_connection_mode', 'lite'); $classes .= ' aivesese-admin aivesese-mode-' . $connection_mode; } return $classes; }); // Run database updates on plugin version change add_action('plugins_loaded', function () { $current_version = get_option('aivesese_plugin_version', '0'); if (version_compare($current_version, AIVESESE_PLUGIN_VERSION, '<')) { // Plugin was updated, run database updates aivesese_update_database(); update_option('aivesese_plugin_version', AIVESESE_PLUGIN_VERSION); } }); function aivesese_update_database() { // Create/update analytics table $analytics = AIVectorSearch_Analytics::instance(); $analytics->create_table(); // Any other database updates for future versions // if (version_compare($old_version, '0.17.0', '<')) { // // Run updates for version 0.17.0 // } } // Load WP-CLI commands if WP-CLI is available if (defined('WP_CLI') && WP_CLI) { require_once AIVESESE_PLUGIN_PATH . 'includes/class-cli-commands.php'; } // Add PostgreSQL connection string to encryption manager add_filter('pre_update_option_aivesese_postgres_connection_string', function ($value, $old_value, $option) { if (empty($value)) { return $value; } $encryption_manager = AIVectorSearch_Encryption_Manager::instance(); return wp_json_encode($encryption_manager->encrypt($value)); }, 10, 3); add_filter('option_aivesese_postgres_connection_string', function ($value) { if (empty($value)) { return $value; } $arr = json_decode($value, true); if (is_array($arr)) { $encryption_manager = AIVectorSearch_Encryption_Manager::instance(); return $encryption_manager->decrypt($arr); } return $value; // Return as-is if not encrypted (backwards compatibility) }); // Add WP-CLI commands help to status page add_action('aivesese_status_page_footer', function () { if (!defined('WP_CLI') || !WP_CLI) { return; } $has_connection = !empty(get_option('aivesese_postgres_connection_string')); echo '
'; echo '

⚡ WP-CLI Commands

'; if ($has_connection) { echo '
'; echo '

✅ WP-CLI is available and PostgreSQL connection is configured!

'; echo '
'; echo '

Available Commands:

'; echo '
'; $commands = [ 'wp aivs install-schema' => 'Install or update database schema', 'wp aivs check-schema' => 'Check current schema status', 'wp aivs test-connection' => 'Test PostgreSQL connection', 'wp aivs sync-products' => 'Sync WooCommerce products to database' ]; foreach ($commands as $command => $description) { echo '
'; echo '' . esc_html($command) . ''; echo '

' . esc_html($description) . '

'; echo '
'; } echo '
'; echo '

💡 Recommended workflow:

'; echo '
    '; echo '
  1. wp aivs test-connection - Verify database access
  2. '; echo '
  3. wp aivs install-schema - Install database schema
  4. '; echo '
  5. wp aivs sync-products - Sync your products
  6. '; echo '
  7. wp aivs check-schema - Verify everything is working
  8. '; echo '
'; } else { echo '
'; echo '

⚠️ WP-CLI is available but PostgreSQL connection string is not configured.

'; echo '

Add your connection string in Settings to enable WP-CLI commands.

'; echo '
'; } echo '
'; // Add styles ?>