Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Disable Plugin Deactivation from WordPress Admin Panel

Last updated on by
Follow WPBeginner on YouTube
How to Disable Plugin Deactivation from WordPress Admin Panel

One of the best parts about WordPress is the availability of plugins that makes your job easy as a user and as a developer. Often when creating sites for clients, we as developers use plugins that are absolutely crucial for the site to have certain functionalities. Recently, we ran into a problem where one of our client’s site was broken. The sidebar wasn’t loading completely, there were missing elements on the single post page which freaked them out. The bottom line of this story was that one of their new staff members who was new to WordPress deactivated some of the plugins which were required for the site to function properly. We went in and activated all the plugins that were deactivated, but there had to be something done in order for us to prevent this issue in the future. In this article, we will show you how to disable plugin deactivation from WordPress Admin Panel (only for specific plugins).

Theoretically, you should be able to use Justin Tadlock’s Members plugin and create new role for users. However, the client we had did not want to go this route. It is a small business, and they hired this new employee to deal with their social media and blog, so we cannot restrict access. They wanted to give him the ability to activate/deactivate plugins at his will. We had to find a way which would keep our client happy, and we also had to find a way to prevent this issue from happening in the future. Thankfully to Steve Taylor, we found a snippet that lets you remove the “Deactivate” link from specified plugins. It also removes the Edit link for all plugins because we did not want our client to edit any plugins through the editor.

So all you have to do is paste the following codes in your theme’s functions.php file:

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $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(
		'facebook-open-graph-meta-in-wordpress/fbogmeta.php',
		'wp-pagenavi/wp-pagenavi.php'
	)))
		unset( $actions['deactivate'] );
	return $actions;
}

Now, you need to change the array of $plugin_file where you see the list of specified plugins. The path of the file is relative to /wp-content/plugins/. So in the example above ‘facebook-open-graph-meta-in-wordpress/fbogmeta.php’ is a file located in the folder facebook-open-graph-meta-in-wordpress which is located inside the plugins folder. You can change the list to add as many plugins as you want.

This trick is a shortcut, and it does not actually prevent the actual deactivation. All we are doing is hiding the Deactivate link. Anyone with a little bit of WordPress knowledge can generate a deactivation URL and run it. But if your client is crafty enough to do that, then they already know what FTP is, and they can simply delete the plugins that way.

Are you working on a theme that absolutely requires a specific plugin for it to function properly? Then don’t forget to drop the code above.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • darrinb

    WordPress also calls a filter hook on your plugin’s specific action links. So if you want to just target your plugin, just call it on your plugin’s specific action links like so:

    add_filter(“plugin_action_links_$plugin_file”, ‘disable_plugin_deactivation’), 10, 4 );

    Where “$plugin_file” is the folder/main file of your plugin.

    This way, you can leave other plugins alone.

  • NowellVanHoesen

    @wpbeginnerotto42 understood. I only use mu-plugins for sites where I make custom widgets, post-types, or plugins for a specific client. Any updates should only be coming from me.

  • wpbeginner

    @NowellVanHoesen Just got a respond from otto42 and he said that NO you cannot allow upgrades by dropping it into wp-content/mu-plugins/ folder….So he suggests that we use network activated plugins … which is useless for what we are trying to do here…

  • wpbeginner

    @NowellVanHoesen Another issue is that you cannot put plugins in folders when you drop it into wp-content/mu-plugins/ folder… However @BillErickson mentioned that there is a patch for this in trac.

  • wpbeginner

    @wp_smith nope @Billerickson is not sure either…. will ask @nacin and @otth42

  • BillErickson

    @wpbeginner But I think there’s a patch for it (can’t find it on trac right now)

  • BillErickson

    @wpbeginner I’m not sure, I only put plugins I write in there. Bigger issue is mu-plugins can’t be in folders (last time I checked)

  • wp_smith

    @wpbeginner did u ever find this out?

  • wpbeginner

    @billerickson can a user upgrade plugins if you drop it into mu-plugins without having to manually do it via FTP?

  • NowellVanHoesen

    Good point, I will have to look into it

  • wp_smith

    @billerickson @wpbeginner also include in the contract or TOS that if the user breaks the theme/site it’s their fault see http://ht.ly/6fRtm

  • wp_smith

    @billerickson still a neat trick though…lazy man’s way to design around a plugin! :)

  • wp_smith

    @billerickson mu-plugins is my friend!

  • BillErickson

    @wp_smith @wpbeginner Use mu-plugins or design the theme to not break if the plugin is disabled

  • wpbeginner

    @NowellVanHoesen Wasn’t sure if you can upgrade plugins that are in wp-content/mu-plugins without having to go through a FTP client. If you can, then dropping plugins in wp-content/mu-plugins is certainly a better option.

  • NowellVanHoesen

    Why not put the required plugins in wp-content/mu-plugins?

  • edward.caissie

    Nice little trick … although not something I have a use for right away it’s definitely going into my bookmarks for future reference.