Disable WordPress Plugin Deactivation

Disable WordPress Plugin Deactivation

There are occasions when you have a WordPress plugin that your entire site is dependent on. Because the site is dependent the plugin simply can’t be disabled or your entire site may stop working. You could try to remember the particular plugin that, but that’s not advisable in some cases.  I can almost guarantee that as time goes on, you will eventually forget and it may get deactivated while your troubleshooting in the future.

A even more likely situation is if the site was built for a client and you don’t want them in disabling things that they don’t understand or need to be messing with.

Thankfully you can remove the ability to deactivate your specified WordPress plugins.  This can be done with a small amount of code in your theme’s functions.php file.

In the code below, simply replace the lines that read 'plugin-directory/plugin.php', and 'plugin2-directory/plugin.php' with the Plugin directory name and php file name.

If you’re unsure, you can download the Plugin and unzip it on your local computer to see the names or you can FTP to your website and look inside /wp-content/plugins for the Plugin Directory name and finally move inside the directory to find the php file name.

You can add additional lines to this as well or remove one of the two if you only have need for one.  For example, if you only need one Plugin, you can remove 'plugin2-directory/plugin.php' along with the comma that ends the line before it, making 'plugin-directory/plugin.php', become this 'plugin-directory/plugin.php'.

WordPress Plugin Deactivation Code


// Remove ability to disable specific plugins.  Edit list for specific plugins
add_filter( 'plugin_action_links', 'slt_lock_plugins', 10, 4 );
function slt_lock_plugins( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
    	unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'plugin-directory/plugin.php',
        'plugin2-directory/plugin.php'
    )))
    unset( $actions['deactivate'] );
    return $actions;
}
, ,
Previous Post
Restricting WordPress Author’s to Specific Categories
Next Post
Cleaning-up Post Meta Screens With Tabs

Related Posts

You must be logged in to post a comment.
Menu