-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuninstall.php
More file actions
81 lines (71 loc) · 3.34 KB
/
uninstall.php
File metadata and controls
81 lines (71 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Uninstall handler for Gratis AI Agent.
*
* Runs when the user deletes the plugin from the WordPress admin.
* Removes all plugin data: database tables, options, user meta, and cron events.
*
* @package GratisAiAgent
* @license GPL-2.0-or-later
*/
declare(strict_types=1);
// Guard: only run when WordPress triggers uninstall.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// ── 1. Drop all plugin database tables ──────────────────────────────────────
$gratis_ai_agent_tables = [
$wpdb->prefix . 'gratis_ai_agent_sessions',
$wpdb->prefix . 'gratis_ai_agent_usage',
$wpdb->prefix . 'gratis_ai_agent_memories',
$wpdb->prefix . 'gratis_ai_agent_skills',
$wpdb->prefix . 'gratis_ai_agent_custom_tools',
$wpdb->prefix . 'gratis_ai_agent_automations',
$wpdb->prefix . 'gratis_ai_agent_automation_logs',
$wpdb->prefix . 'gratis_ai_agent_event_automations',
$wpdb->prefix . 'gratis_ai_agent_conversation_templates',
$wpdb->prefix . 'gratis_ai_agent_git_tracked_files',
$wpdb->prefix . 'gratis_ai_agent_changes_log',
$wpdb->prefix . 'gratis_ai_agent_modified_files',
$wpdb->prefix . 'gratis_ai_agent_agents',
$wpdb->prefix . 'gratis_ai_agent_shared_sessions',
$wpdb->prefix . 'gratis_ai_agent_benchmark_runs',
$wpdb->prefix . 'gratis_ai_agent_benchmark_results',
];
foreach ( $gratis_ai_agent_tables as $gratis_ai_agent_table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall handler must drop tables; names are from $wpdb->prefix only, caching is irrelevant on uninstall.
$wpdb->query( "DROP TABLE IF EXISTS `{$gratis_ai_agent_table}`" );
}
// ── 2. Delete all plugin options ─────────────────────────────────────────────
$gratis_ai_agent_options = [
'gratis_ai_agent_settings',
'gratis_ai_agent_db_version',
'gratis_ai_agent_claude_max_token',
'gratis_ai_agent_provider_keys',
'gratis_ai_agent_gsc_credentials',
'gratis_ai_agent_tool_profiles',
'gratis_ai_agent_custom_tools_seeded',
'gratis_ai_agent_migrated_from_ai_agent',
];
foreach ( $gratis_ai_agent_options as $gratis_ai_agent_option ) {
delete_option( $gratis_ai_agent_option );
}
// ── 3. Delete user meta with plugin prefix ───────────────────────────────────
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall-only, caching is irrelevant on uninstall.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s",
$wpdb->esc_like( 'gratis_ai_agent_' ) . '%'
)
);
// ── 4. Clear scheduled cron events ───────────────────────────────────────────
$gratis_ai_agent_cron_hooks = [
'gratis_ai_agent_run_automation',
'gratis_ai_agent_run_event_automation',
'gratis_ai_agent_site_scan',
'wp_gratis_ai_agent_reindex',
];
foreach ( $gratis_ai_agent_cron_hooks as $gratis_ai_agent_hook ) {
wp_clear_scheduled_hook( $gratis_ai_agent_hook );
}