| 1 |
<?php |
| 2 |
/** |
| 3 |
* Update counts to database. |
| 4 |
* |
| 5 |
* @package Top_Ten |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
if ( ! ( defined( 'WP_UNINSTALL_PLUGIN' ) || defined( 'WP_FS__UNINSTALL_MODE' ) ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
global $wpdb; |
| 15 |
|
| 16 |
$tptn_settings = get_option( 'tptn_settings' ); |
| 17 |
|
| 18 |
wp_clear_scheduled_hook( 'tptn_aggregation_cron_hook' ); |
| 19 |
|
| 20 |
if ( ! empty( $tptn_settings['uninstall_clean_tables'] ) ) { |
| 21 |
|
| 22 |
$table_names = array( |
| 23 |
$wpdb->base_prefix . 'top_ten', |
| 24 |
$wpdb->base_prefix . 'top_ten_daily', |
| 25 |
$wpdb->base_prefix . 'top_ten_visits_log', |
| 26 |
$wpdb->base_prefix . 'top_ten_visits_funnel', |
| 27 |
); |
| 28 |
|
| 29 |
foreach ( $table_names as $table_name ) { |
| 30 |
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 31 |
$wpdb->query( "DROP TABLE $table_name" ); |
| 32 |
} |
| 33 |
delete_site_option( 'tptn_db_version' ); |
| 34 |
} |
| 35 |
|
| 36 |
// Delete data across multisite or single site. |
| 37 |
if ( is_multisite() ) { |
| 38 |
|
| 39 |
$sites = get_sites( |
| 40 |
array( |
| 41 |
'archived' => 0, |
| 42 |
'spam' => 0, |
| 43 |
'deleted' => 0, |
| 44 |
) |
| 45 |
); |
| 46 |
|
| 47 |
foreach ( $sites as $site ) { |
| 48 |
switch_to_blog( (int) $site->blog_id ); |
| 49 |
tptn_delete_data(); |
| 50 |
restore_current_blog(); |
| 51 |
} |
| 52 |
} else { |
| 53 |
tptn_delete_data(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Function to delete data when the plugin is uninstalled. |
| 58 |
* |
| 59 |
* @since 4.0.0 |
| 60 |
*/ |
| 61 |
function tptn_delete_data() { |
| 62 |
global $wpdb; |
| 63 |
|
| 64 |
$settings = get_option( 'tptn_settings' ); |
| 65 |
|
| 66 |
if ( $settings['uninstall_clean_options'] ) { |
| 67 |
|
| 68 |
if ( wp_next_scheduled( 'tptn_cron_hook' ) ) { |
| 69 |
wp_clear_scheduled_hook( 'tptn_cron_hook' ); |
| 70 |
} |
| 71 |
delete_option( 'ald_tptn_settings' ); |
| 72 |
delete_option( 'tptn_settings' ); |
| 73 |
|
| 74 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 75 |
$wpdb->query( |
| 76 |
" |
| 77 |
DELETE FROM {$wpdb->options} |
| 78 |
WHERE option_name LIKE '%tptn%' |
| 79 |
" |
| 80 |
); |
| 81 |
} |
| 82 |
} |
| 83 |
|