-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeactivation.php
82 lines (74 loc) · 3.02 KB
/
deactivation.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
76
77
78
79
80
81
82
<?php
/**
* Deactivation functions for the User Wall plugin.
*
* @file deactivation.php
*
* @package UserWall_WP
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Deactivate the User Wall plugin.
*/
function userwall_wp_deactivate() {
// Check if the option for deletion is set to true.
$delete_on_deactivation = get_option( 'userwall_wp_delete_deactivation', false );
$delete_on_deactivation = 1;
// If the option is set to true, delete the tables.
if ( $delete_on_deactivation ) {
global $wpdb;
// Define the table names with the "userwall_" prefix.
$table_posts = $wpdb->prefix . 'userwall_posts';
$table_comments = $wpdb->prefix . 'userwall_comments';
$table_likes = $wpdb->prefix . 'userwall_likes';
$table_bookmarks = $wpdb->prefix . 'userwall_bookmarks';
$table_polls = $wpdb->prefix . 'userwall_polls';
$table_poll_votes = $wpdb->prefix . 'userwall_poll_votes';
$table_reports = $wpdb->prefix . 'userwall_reports';
$table_user_reputation = $wpdb->prefix . 'userwall_user_reputation';
$table_badges = $wpdb->prefix . 'userwall_badges';
$table_hashtags = $wpdb->prefix . 'userwall_hashtags';
$table_user_settings = $wpdb->prefix . 'userwall_user_settings';
$table_notifications = $wpdb->prefix . 'userwall_notifications';
$table_search_history = $wpdb->prefix . 'userwall_search_history';
$table_user_followers = $wpdb->prefix . 'userwall_user_followers';
$table_user_following = $wpdb->prefix . 'userwall_user_following';
$table_reports = $wpdb->prefix . 'userwall_reports';
$table_user_notifications = $wpdb->prefix . 'userwall_user_notifications';
$table_poll_options = $wpdb->prefix . 'userwall_poll_options';
$table_blocklist = $wpdb->prefix . 'userwall_blocklist';
// SQL queries to drop the tables.
$sql_queries = array(
$table_comments,
$table_likes,
$table_bookmarks,
$table_polls,
$table_poll_votes,
$table_reports,
$table_user_reputation,
$table_badges,
$table_hashtags,
$table_user_settings,
$table_notifications,
$table_search_history,
$table_user_followers,
$table_user_following,
$table_reports,
$table_user_notifications,
$table_poll_options,
$table_blocklist,
);
$drop_tables = apply_filters( 'userwall_wp_drop_tables', $sql_queries );
// Add the posts table to the list of tables to drop.
$drop_tables[] = $table_posts;
// Include the WordPress database upgrade file.
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// Execute the SQL queries to create the tables.
foreach ( $drop_tables as $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table ) );
}
}
}