1

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?

2
  • 1
    Don't delete the plugin. Open it, find the hook that makes it run and comment it out.
    – shanebp
    Apr 22, 2020 at 19:55
  • That may well work, however I suspect the hosting company will just overwrite it. Would rather do it within my theme. Although thinking about it, I wonder if I can hook into it...
    – rich
    Apr 23, 2020 at 7:57

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.