-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
115 lines (101 loc) · 3.65 KB
/
Copy pathuninstall.php
File metadata and controls
115 lines (101 loc) · 3.65 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* SEO Magic uninstall routine.
*
* Normal deactivation, plugin updates and ZIP replacements must never remove
* user data. Cleanup only runs after an explicit opt-in in SEO Magic settings.
* Generated SEO content is preserved even during cleanup so reinstalling the
* plugin cannot erase taxonomy descriptions, author descriptions or schemas.
*
* @package SEO_Magic
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Always remove scheduled jobs. This does not affect saved content.
wp_clear_scheduled_hook( 'smg_autopilot_cron_event' );
wp_clear_scheduled_hook( 'smg_recalculation_cron_hook' );
wp_clear_scheduled_hook( 'smg_daily_license_check' );
$smg_settings = get_option( 'smg_settings', [] );
$smg_settings = is_array( $smg_settings ) ? $smg_settings : [];
// Cleanup is opt-in and intentionally uses a new key. The former
// delete_on_deactivation option is ignored because it could erase data during
// ordinary update/replacement workflows.
$smg_delete_on_uninstall = isset( $smg_settings['delete_on_uninstall'] ) && 'on' === $smg_settings['delete_on_uninstall'];
if ( ! $smg_delete_on_uninstall ) {
return;
}
$options_to_delete = [
'smg_settings',
'smg_gemini_api_key',
'smg_gemini_lock_pro',
'smg_gemini_lock_flash',
'smg_recalc_posts_queue',
'smg_recalc_archives_queue',
'smg_recalc_images_queue',
'smg_recalc_progress',
'smg_needs_initial_scan',
'smg_generation_log',
'smg_generation_count',
'smg_review_notice_completed',
'smg_google_oauth_tokens',
'smg_license_key',
'smg_license_status',
'smg_license_error_message',
'smg_core_data_hash',
'smg_active_product_id',
];
foreach ( $options_to_delete as $option_name ) {
delete_option( $option_name );
}
$transients_to_delete = [
'smg_api_errors',
'smg_deactivation_feedback_log',
'smg_flash_requests_today',
'smg_pro_requests_today',
'smg_gemini_rpm_count',
'smg_gemini_rpm_pro_count',
'smg_gemini_rpm_flash_count',
];
foreach ( $transients_to_delete as $transient_name ) {
delete_transient( $transient_name );
}
// Remove only recalculable internal caches. Generated SEO content such as
// _smg_meta_description and _smg_custom_schema is deliberately preserved.
global $wpdb;
$cache_meta_keys = [
'_smg_coverage_score',
'_smg_word_count',
'_smg_internal_link_count',
'_smg_external_link_count',
'_smg_optimized',
'_smg_autopilot_processed',
];
$placeholders = implode( ',', array_fill( 0, count( $cache_meta_keys ), '%s' ) );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->postmeta WHERE meta_key IN ($placeholders)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$cache_meta_keys
)
);
// Coverage scores are caches and can be rebuilt. The actual generated archive
// descriptions remain stored in _smg_meta_description.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->termmeta WHERE meta_key = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
'_smg_coverage_score'
)
);
// Keep author descriptions. Remove only user preferences and coverage cache.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->usermeta WHERE meta_key IN (%s, %s, %s, %s)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
'_smg_review_notice_dismissed',
'_smg_footer_stars_dismissed',
'smg_admin_theme',
'_smg_coverage_score'
)
);