id) || $screen->id !== 'plugins') { return; } $url = admin_url('admin.php?page=agentinstore'); $dismiss = wp_nonce_url( admin_url('admin-post.php?action=agenti_dismiss_connect_notice'), 'agenti_dismiss_connect_notice' ); echo '

'; echo '' . esc_html__('AgentInStore', 'agentinstore') . ' '; echo esc_html__('is installed but not connected.', 'agentinstore') . ' '; echo '' . esc_html__('Open AgentInStore settings', 'agentinstore') . ''; echo ' ' . esc_html__('Dismiss', 'agentinstore') . ''; echo '

'; }); add_action('admin_post_agenti_dismiss_connect_notice', function () { if (!current_user_can('manage_options')) { wp_die(esc_html__('Forbidden', 'agentinstore'), 403); } check_admin_referer('agenti_dismiss_connect_notice'); update_user_meta(get_current_user_id(), 'agenti_dismiss_connect_notice', 1); wp_safe_redirect(wp_get_referer() ? wp_get_referer() : admin_url('plugins.php')); exit; }); /** * Bootstrap. */ final class AGENTI_Plugin { /** * Suggested text for Settings → Privacy. */ public static function privacy_policy_content() { if (!function_exists('wp_add_privacy_policy_content')) { return; } $content = '

' . esc_html__('AgentInStore connects your store to the AgentInStore service only after an administrator configures an API base URL and public key and clicks Connect.', 'agentinstore') . '

'; $content .= '

' . esc_html__('When connected, the following may be sent to your configured AgentInStore API: store URL, store name, admin email, WordPress/WooCommerce/plugin versions, product catalog data (including names, descriptions, prices, stock, images, categories, attributes, variations, and approved reviews), and periodic connection heartbeats.', 'agentinstore') . '

'; $content .= '

' . esc_html__('If the chat widget is enabled, the storefront loads widget.js from the same configured API base URL so visitors can chat with your agent.', 'agentinstore') . '

'; $content .= '

' . esc_html__('Disconnecting or uninstalling the plugin clears stored credentials on this site and notifies the service when possible.', 'agentinstore') . '

'; wp_add_privacy_policy_content('AgentInStore', wp_kses_post($content)); } /** * One-time migrate legacy ca_* options to agenti_* (local installs). */ public static function maybe_migrate_legacy_options() { if (get_option('agenti_options_migrated', '')) { return; } $map = [ 'ca_api_base' => 'agenti_api_base', 'ca_public_key' => 'agenti_public_key', 'ca_webhook_secret' => 'agenti_webhook_secret', 'ca_connection_id' => 'agenti_connection_id', 'ca_bot_color' => 'agenti_bot_color', 'ca_widget_enabled' => 'agenti_widget_enabled', 'ca_store_connected' => 'agenti_store_connected', 'ca_last_full_sync_at' => 'agenti_last_full_sync_at', 'ca_last_full_sync_count' => 'agenti_last_full_sync_count', 'ca_last_full_sync_failed' => 'agenti_last_full_sync_failed', ]; foreach ($map as $old => $new) { $old_val = get_option($old, null); if ($old_val !== null && false === get_option($new, false) && $old_val !== false) { update_option($new, $old_val, false); delete_option($old); } } update_option('agenti_options_migrated', '1', false); } /** * Init feature modules. */ public static function init() { self::maybe_migrate_legacy_options(); // Ensure cron survives updates (activate() only runs on first install). if (!wp_next_scheduled('agenti_daily_heartbeat')) { wp_schedule_event(time() + HOUR_IN_SECONDS, 'daily', 'agenti_daily_heartbeat'); } AGENTI_Admin::init(); AGENTI_Sync::init(); AGENTI_Widget::init(); } /** * Activation: schedule heartbeat only (no remote call / no admin redirect). */ public static function activate() { self::maybe_migrate_legacy_options(); if (!wp_next_scheduled('agenti_daily_heartbeat')) { wp_schedule_event(time() + HOUR_IN_SECONDS, 'daily', 'agenti_daily_heartbeat'); } } /** * Deactivation: clear cron. Keep credentials until uninstall. */ public static function deactivate() { $timestamp = wp_next_scheduled('agenti_daily_heartbeat'); if ($timestamp) { wp_unschedule_event($timestamp, 'agenti_daily_heartbeat'); } $full = wp_next_scheduled('agenti_full_catalog_sync'); if ($full) { wp_unschedule_event($full, 'agenti_full_catalog_sync'); } } } add_action('plugins_loaded', ['AGENTI_Plugin', 'init']);