-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker: disable Jetpack update notices (#9500)
* Docker: disable Jetpack update notices Disables notices for Jetpack plugin in Docker environment. Deleting or updating the plugin would cause your complete development folder being erased. Not cool.
- Loading branch information
Showing
1 changed file
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
Plugin Name: Remove delete link for Jetpack | ||
Description: Removes the Delete link from your plugins list for the current Jetpack directory | ||
Version: 1.0 | ||
Plugin Name: Disable deleting and updating Jetpack | ||
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. | ||
Version: 2.0 | ||
Author: Automattic | ||
Author URI: http://automattic.com/ | ||
*/ | ||
|
||
// These are the plugins we don't want to update or delete | ||
$jetpack_docker_avoided_plugins = array( | ||
'jetpack/jetpack.php', | ||
); | ||
|
||
/** | ||
* avoid-plugin-deletion.php | ||
* | ||
* This file contains a hook that removes the Delete link from your plugins list for the current Jetpack directory. | ||
* | ||
* It was added because the effect of being able to delete your local development directory from WordPress is catastrophic and you can lose | ||
* your git history in the process. | ||
* Remove the Delete link from your plugins list for important plugins | ||
*/ | ||
add_filter( 'plugin_action_links', 'disable_plugin_deletion', 10, 4 ); | ||
|
||
function disable_plugin_deletion( $actions, $plugin_file, $plugin_data, $context ) { | ||
|
||
// Remove delete link for important plugins | ||
function jetpack_docker_disable_plugin_deletion_link( $actions, $plugin_file, $plugin_data, $context ) { | ||
global $jetpack_docker_avoided_plugins; | ||
if ( | ||
array_key_exists( 'delete', $actions ) && | ||
in_array( | ||
$plugin_file, | ||
array( | ||
'jetpack/jetpack.php', | ||
) | ||
$jetpack_docker_avoided_plugins | ||
) | ||
) { | ||
unset( $actions['delete'] ); | ||
} | ||
return $actions; | ||
} | ||
add_filter( 'plugin_action_links', 'jetpack_docker_disable_plugin_deletion_link', 10, 4 ); | ||
|
||
/** | ||
* Fail deletion attempts of our important plugins | ||
*/ | ||
function jetpack_docker_disable_delete_plugin( $plugin_file ) { | ||
global $jetpack_docker_avoided_plugins; | ||
if ( in_array( $plugin_file, $jetpack_docker_avoided_plugins ) ) { | ||
wp_die( | ||
'Deleting plugin "' . $plugin_file . '" is disabled at mu-plugins/avoid-plugin-deletion.php', | ||
403 | ||
); | ||
} | ||
} | ||
add_action( 'delete_plugin', 'jetpack_docker_disable_delete_plugin', 10, 2 ); | ||
|
||
/** | ||
* Stop WordPress noticing plugin updates for important plugins | ||
*/ | ||
function jetpack_docker_disable_plugin_update( $plugins ) { | ||
global $jetpack_docker_avoided_plugins; | ||
foreach( $jetpack_docker_avoided_plugins as $avoided_plugin ) { | ||
if ( isset( $plugins->response[ $avoided_plugin ] ) ) { | ||
unset( $plugins->response[ $avoided_plugin ] ); | ||
} | ||
} | ||
return $plugins; | ||
} | ||
add_filter( 'site_transient_update_plugins', 'jetpack_docker_disable_plugin_update' ); |