PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.10.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.10.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / includes / core / class-deactivator.php

class-deactivator.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.10.0, at includes/core/class-deactivator.php

127 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Deactivator Class
4 *
5 * Handles plugin deactivation tasks
6 *
7 * @package ThinkRank\Core
8 * @since 1.0.0
9 */
10
11 declare(strict_types=1);
12
13 namespace ThinkRank\Core;
14
15 // Prevent direct access
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 /**
21 * Deactivator Class
22 *
23 * Single Responsibility: Handle plugin deactivation tasks only
24 *
25 * @since 1.0.0
26 */
27 class Deactivator {
28
29 /**
30 * Plugin deactivation tasks
31 *
32 * @return void
33 */
34 public function deactivate(): void {
35 $this->clear_scheduled_hooks();
36 $this->clear_cache();
37 $this->log_deactivation();
38
39 // Note: We don't delete user data on deactivation
40 // Data is only removed on uninstall
41 }
42
43 /**
44 * Clear all scheduled hooks
45 *
46 * @return void
47 */
48 private function clear_scheduled_hooks(): void {
49 $scheduled_hooks = [
50 'thinkrank_monthly_credit_reset',
51 'thinkrank_cache_cleanup',
52 'thinkrank_usage_analytics',
53 ];
54
55 foreach ($scheduled_hooks as $hook) {
56 $timestamp = wp_next_scheduled($hook);
57 if ($timestamp) {
58 wp_unschedule_event($timestamp, $hook);
59 }
60 }
61
62 // Clear all instances of our hooks
63 wp_clear_scheduled_hook('thinkrank_monthly_credit_reset');
64 wp_clear_scheduled_hook('thinkrank_cache_cleanup');
65 wp_clear_scheduled_hook('thinkrank_usage_analytics');
66 }
67
68 /**
69 * Clear plugin cache
70 *
71 * @return void
72 */
73 private function clear_cache(): void {
74 global $wpdb;
75
76 // Clear AI cache table with proper escaping
77 $cache_table = $wpdb->prefix . 'thinkrank_ai_cache';
78 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin deactivation requires direct database access to check table existence
79 $table_exists = $wpdb->get_var(
80 $wpdb->prepare("SHOW TABLES LIKE %s", $cache_table)
81 );
82 if ($table_exists === $cache_table) {
83 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name is properly constructed from controlled prefix, plugin deactivation requires direct database access
84 $wpdb->query("TRUNCATE TABLE {$cache_table}");
85 }
86
87 // Clear WordPress transients with proper escaping
88 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- $wpdb->options is a WordPress core property, plugin deactivation requires direct database access
89 $wpdb->query(
90 $wpdb->prepare(
91 "DELETE FROM {$wpdb->options}
92 WHERE option_name LIKE %s
93 OR option_name LIKE %s",
94 $wpdb->esc_like('_transient_thinkrank_') . '%',
95 $wpdb->esc_like('_transient_timeout_thinkrank_') . '%'
96 )
97 );
98
99 // Clear object cache if available
100 if (function_exists('wp_cache_flush_group')) {
101 wp_cache_flush_group('thinkrank');
102 }
103 }
104
105 /**
106 * Log deactivation for analytics
107 *
108 * @return void
109 */
110 private function log_deactivation(): void {
111 $deactivation_data = [
112 'timestamp' => time(),
113 'version' => THINKRANK_VERSION,
114 'wp_version' => get_bloginfo('version'),
115 'php_version' => PHP_VERSION,
116 'active_plugins' => get_option('active_plugins', []),
117 'site_url' => get_site_url(),
118 ];
119
120 // Store deactivation data for potential feedback
121 update_option('thinkrank_last_deactivation', $deactivation_data);
122
123 // Remove activation flag
124 delete_option('thinkrank_activated');
125 }
126 }
127