-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
85 lines (67 loc) · 2.38 KB
/
uninstall.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
83
84
85
<?php
/**
* Uninstall Comment Converter.
*
* Remove:
* - Follower table
* - Follows table
* - ccvtr post_meta
* - Comment Converter settings/options
* - Comment Converter Uploads
*
* @package CommentConverter
*
* @since 0.9.1
*
* @var WP_Filesystem_Base $wp_filesystem
*/
use CommentConverter\Plugin\Database\Schema\Schema;
use CommentConverter\Plugin\Settings\Options;
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Load plugin file.
require_once 'comment-converter.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.
$ccvtr_settings = get_option( Options::OPTION_NAME, array() );
if (
empty( $ccvtr_settings['uninstall_data'] ) ||
is_plugin_active( 'comment-notifications/comment-converter.php' )
) {
return;
}
global $wpdb;
// phpcs:disable WordPress.DB.DirectDatabaseQuery
// Drop all the database tables.
Schema::drop_all_tables();
// Delete all the plugin options.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'ccvtr\_%'" );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'comment_converter\_%'" );
// Delete plugin post meta.
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'ccvtr\_%'" );
global $wp_filesystem;
// Remove uploaded files.
$ccvtr_uploads_directory = wp_upload_dir();
if ( empty( $ccvtr_uploads_directory['error'] ) ) {
$wp_filesystem->rmdir( $ccvtr_uploads_directory['basedir'] . '/comment-converter/', true );
}
// Remove translation files.
$ccvtr_languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/';
$ccvtr_translations = glob( wp_normalize_path( $ccvtr_languages_directory . 'plugins/comment-notifications' ) );
if ( ! empty( $ccvtr_translations ) ) {
foreach ( $ccvtr_translations as $ccvtr_file ) {
$wp_filesystem->delete( $ccvtr_file );
}
}
// Remove all scheduled actions related to the plugin.
if ( class_exists( 'ActionScheduler_DBStore' ) ) {
ActionScheduler_DBStore::instance()->cancel_actions_by_group( 'comment_converter' );
}
// Remove schedule cron hooks.
wp_clear_scheduled_hook( 'ccvtr_notification_digest_cron_daily' );
wp_clear_scheduled_hook( 'ccvtr_notification_digest_cron_weekly' );