Prevent a plugin from being automatically activated

On a site I look after, the hosting company automatically force a plugin on us that, well it's useless.

I'm looking for a hook/action that can be used to fully prevent that plugin from being activated ever as it seems that even if I delete the plugin it is auto reinstalled and reactivated. Anybody have any tips as to where I should be looking?

Topic deactivation activation php hooks plugins Wordpress

Category Web


You might want to add your own plugin to deactivate their plugin (silently). First open their main plugin file and see where the plugin hooks (or filters) in. Then unhook their plugin … and your's as well.

<?php
/** Plugin Name: Deactivate other plugin */
add_action( 'the_same_hook', 'removeOtherPlugin', PHP_INT_MAX -1 );
function removeOtherPlugin() {
    remove_filter( current_filter(), 'their_function_name' );
    remove_filter( current_filter(), __FUNCTION__ );
}

Explanation

  • The helper to make the removal more portable is current_filter(). It returns the name of the currently running filter.
  • PHP_INT_MAX is PHPs maximum integer (reduced by one), that it automatically adjusted to the OS capabilities. It is the most save method to guarantee that your function is registered later on. If they register their's afterwards, you still can try to start your function name with a later character like zzzRemoveOtherPlugin or similar.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.