Skip to content

Commit

Permalink
Docker: disable Jetpack update notices (#9500)
Browse files Browse the repository at this point in the history
* 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
simison authored and oskosk committed May 24, 2018
1 parent b175cd4 commit 76ae03c
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions docker/mu-plugins/avoid-plugin-deletion.php
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' );

0 comments on commit 76ae03c

Please sign in to comment.