-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
75 lines (61 loc) · 1.71 KB
/
uninstall.php
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
<?php
/**
* Advanced Job Listing Plugin Uninstall Script
*
* This script runs when the plugin is uninstalled via the WordPress admin.
* It removes all plugin-related data from the database.
*/
// If uninstall is not called from WordPress, exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// Delete all job listings
function ajl_delete_all_jobs() {
$args = array(
'post_type' => 'job',
'post_status' => 'any',
'posts_per_page' => -1,
'fields' => 'ids',
);
$job_ids = get_posts($args);
foreach ($job_ids as $job_id) {
wp_delete_post($job_id, true);
}
}
ajl_delete_all_jobs();
// Delete all job applications
function ajl_delete_all_applications() {
$args = array(
'post_type' => 'application',
'post_status' => 'any',
'posts_per_page' => -1,
'fields' => 'ids',
);
$application_ids = get_posts($args);
foreach ($application_ids as $application_id) {
wp_delete_post($application_id, true);
}
}
ajl_delete_all_applications();
// Clean up options from the wp_options table
$options_to_delete = array(
'ajl_job_options',
'ajl_version',
'ajl_db_version',
// Add any other options your plugin might have created
);
foreach ($options_to_delete as $option) {
delete_option($option);
}
// Remove custom database tables
global $wpdb;
$tables_to_delete = array(
$wpdb->prefix . 'job_subscriptions',
$wpdb->prefix . 'email_log',
// Add any other custom tables your plugin might have created
);
foreach ($tables_to_delete as $table) {
$wpdb->query("DROP TABLE IF EXISTS $table");
}
// Clear any cached data that may have been stored
wp_cache_flush();