-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-replicas.php
134 lines (117 loc) · 3.61 KB
/
no-replicas.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
Plugin Name: No Replicas T-T
Plugin URI: https://soaringleads.com
Description: A mu-plugin to auto disable backup, cloning and file manager plugins on a WordPress site.
Version: 1.0.0
Author: Uriahs Victor
Author URI: https://soaringleads.com
License: GPL-2.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Requires PHP: 7.4
*/
/**
* Main class.
*
* More plugins can be added to the nr_get_blacklisted_plugins() array.
* Alternatively, you can completely replace the list with a custom one.
*/
class NR_Deactivate {
/**
* Class constructor.
*
* @return void
* @since 1.0.0
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'nr_deactivate_blacklisted_plugins' ) );
$this->nr_disable_editor();
}
/**
* Disable the file editor for plugins and themes.
*
* @return void
* @since 1.0.0
*/
private function nr_disable_editor(): void {
if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {
define( 'DISALLOW_FILE_EDIT', true );
}
}
/**
* Get current installed plugins.
*
* @return array
* @since 1.0.0
*/
private function nr_get_installed_plugins() : array {
$all_plugins = get_plugins();
$normalize = array();
foreach ( $all_plugins as $registered_name => $plugin_data ) {
$normalize[ $registered_name ] = $plugin_data['Name'];
}
return $normalize;
}
/**
* Get our blacklisted plugins.
*
* @return array
* @since 1.0.0
*/
private function nr_get_blacklisted_plugins() : array {
return array(
'Everest Backup', // https://wordpress.org/plugins/everest-backup
'WP File Manager', // https://wordpress.org/plugins/wp-file-manager
'FileBird Lite', // https://wordpress.org/plugins/filebird/
'File Manager Advanced', // https://wordpress.org/plugins/file-manager-advanced
'Duplicator', // https://wordpress.org/plugins/duplicator/
'UpdraftPlus - Backup/Restore', // https://wordpress.org/plugins/updraftplus/
'Backup Migration', // https://wordpress.org/plugins/backup-backup/
'Backup', // https://wordpress.org/plugins/backup/
'BackWPup', // https://wordpress.org/plugins/backwpup/
'Backup Duplicator & Migration - WP STAGING', // https://wordpress.org/plugins/wp-staging/
'WPvivid Backup Plugin', // https://wordpress.org/plugins/wpvivid-backuprestore/
'WordPress Backup & Security Plugin - BlogVault', // https://wordpress.org/plugins/blogvault-real-time-backup/
'Backup For WP', // https://wordpress.org/plugins/wp-database-backup/
'All-in-One WP Migration', // https://wordpress.org/plugins/all-in-one-wp-migration/
);
}
/**
* Prevent activation of blacklisted plugins.
*
* @return void
* @since 1.0.0
*/
public function nr_deactivate_blacklisted_plugins() {
$blacklist = $this->nr_get_blacklisted_plugins();
$installed = $this->nr_get_installed_plugins();
foreach ( $blacklist as $blacklisted ) {
array_filter(
$installed,
function ( $value, $key ) use ( $blacklisted ) {
if ( $blacklisted === $value ) {
if ( is_plugin_active( $key ) ) {
deactivate_plugins( $key );
add_action( 'admin_notices', array( $this, 'nr_create_admin_notice' ) );
}
}
},
ARRAY_FILTER_USE_BOTH
);
}
}
/**
* Create admin notice when user tries to activate a blacklisted plugin.
*
* @return void
* @since 1.0.0
*/
public function nr_create_admin_notice() : void {
echo "
<div class='notice notice-warning'>
<p style='font-size: 24px;'><strong>Sorry...</strong> You're not allowed to install this plugin. Please contact us if there's a particular reason you need it 🫣</p>
</div>
";
}
}
new NR_Deactivate();