uninstall.php
2.45 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
<?php
/**
* Uninstall AIOSEO
*
* Remove:
* - AIOSEO Notifications table
* - AIOSEO Posts table
* - AIOSEO Terms table
*
* @since 4.0.0
*/
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Load plugin file.
require_once 'all_in_one_seo_pack.php';
// Disable Action Schedule Queue Runner.
if ( class_exists( 'ActionScheduler_QueueRunner' ) ) {
ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request();
}
// Confirm user has decided to remove all data, otherwise stop.
if ( ! aioseo()->options->advanced->uninstall ) {
return;
}
global $wpdb;
$tablesToDrop = [
'aioseo_notifications',
'aioseo_posts',
'aioseo_terms',
'aioseo_redirects',
'aioseo_redirects_404_logs',
'aioseo_redirects_hits',
'aioseo_redirects_logs',
'aioseo_cache',
'aioseo_links',
'aioseo_links_suggestions',
'aioseo_links_post_relationships'
];
// Delete all our custom tables.
foreach ( $tablesToDrop as $tableName ) {
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . $tableName ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
// Delete all AIOSEO Locations and Location Categories.
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'aioseo-location'" );
$wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'aioseo-location-category'" );
// Delete all the plugin settings.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
// Remove any transients we've left behind.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_aioseo\_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
// Delete all entries from the action scheduler table.
$wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE hook LIKE 'aioseo\_%'" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_groups WHERE slug = 'aioseo'" );
global $wp_filesystem;
// Remove translation files.
$languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/';
$translations = glob( wp_normalize_path( $languages_directory . 'plugins/aioseo-*' ) );
if ( ! empty( $translations ) ) {
foreach ( $translations as $file ) {
$wp_filesystem->delete( $file );
}
}
$translations = glob( wp_normalize_path( $languages_directory . 'plugins/all-in-one-seo-*' ) );
if ( ! empty( $translations ) ) {
foreach ( $translations as $file ) {
$wp_filesystem->delete( $file );
}
}