|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
Plugin Name: Disable deleting and updating Jetpack |
|
5
|
|
|
Description: Disable deleting and updating -actions for Jetpack plugin. Being able to delete your local development directory from WordPress is catastrophic and you can lose your git history in the process. |
|
6
|
|
|
Version: 2.0 |
|
7
|
|
|
Author: Automattic |
|
8
|
|
|
Author URI: http://automattic.com/ |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
// These are the plugins we don't want to update or delete |
|
12
|
|
|
$jetpack_docker_avoided_plugins = array( |
|
13
|
|
|
'jetpack/jetpack.php', |
|
14
|
|
|
); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Remove the Delete link from your plugins list for important plugins |
|
18
|
|
|
*/ |
|
19
|
|
|
function jetpack_docker_disable_plugin_deletion_link( $actions, $plugin_file, $plugin_data, $context ) { |
|
20
|
|
|
global $jetpack_docker_avoided_plugins; |
|
21
|
|
|
if ( |
|
22
|
|
|
array_key_exists( 'delete', $actions ) && |
|
23
|
|
|
in_array( |
|
24
|
|
|
$plugin_file, |
|
25
|
|
|
$jetpack_docker_avoided_plugins |
|
26
|
|
|
) |
|
27
|
|
|
) { |
|
28
|
|
|
unset( $actions['delete'] ); |
|
29
|
|
|
} |
|
30
|
|
|
return $actions; |
|
31
|
|
|
} |
|
32
|
|
|
add_filter( 'plugin_action_links', 'jetpack_docker_disable_plugin_deletion_link', 10, 4 ); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Fail deletion attempts of our important plugins |
|
36
|
|
|
*/ |
|
37
|
|
|
function jetpack_docker_disable_delete_plugin( $plugin_file ) { |
|
38
|
|
|
global $jetpack_docker_avoided_plugins; |
|
39
|
|
|
if ( in_array( $plugin_file, $jetpack_docker_avoided_plugins ) ) { |
|
40
|
|
|
wp_die( |
|
41
|
|
|
'Deleting plugin "' . $plugin_file . '" is disabled at mu-plugins/avoid-plugin-deletion.php', |
|
42
|
|
|
403 |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
add_action( 'delete_plugin', 'jetpack_docker_disable_delete_plugin', 10, 2 ); |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Stop WordPress noticing plugin updates for important plugins |
|
50
|
|
|
*/ |
|
51
|
|
|
function jetpack_docker_disable_plugin_update( $plugins ) { |
|
52
|
|
|
global $jetpack_docker_avoided_plugins; |
|
53
|
|
|
foreach( $jetpack_docker_avoided_plugins as $avoided_plugin ) { |
|
54
|
|
|
if ( isset( $plugins->response[ $avoided_plugin ] ) ) { |
|
55
|
|
|
unset( $plugins->response[ $avoided_plugin ] ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
return $plugins; |
|
59
|
|
|
} |
|
60
|
|
|
add_filter( 'site_transient_update_plugins', 'jetpack_docker_disable_plugin_update' ); |
|
61
|
|
|
|