Kategorier
WordPress

Prevent WordPress plugin from being disabled

You properly already know that you can create a “MU” plugin, that prevents your plugin from being disabled.

But what if your theme depends on a plugin, you installed from WordPress.org, that you do not want your users to disable?

Add this to your functions.php:

$plugin = 'akismet/akismet.php'; // you might want to change this ;)
add_action("deactivate_{$plugin}", function() {
     wp_redirect(add_query_arg('resume', 1, $_SERVER['HTTP_REFERER']));
     exit;
}, PHP_INT_MIN);

Are you a plugin developer?

Another use case would be if your plugin requires WooCommerce to be enabled. Then this code could be used, in your plugin, to ensure that WooCommerce is not disabled as long as your plugin is enabled.

Skriv et svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *