Family Encyclopedia >> Electronics

How to disable plugin deactivation from WordPress Admin Panel

One of the best parts of WordPress is the availability of plugins that makes your job easier 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. We recently ran into an issue where one of our clients' sites was broken. The sidebar was not fully loading, there were missing items on the single post page which scared them off. The takeaway from this story was that one of their new staff members who was new to WordPress disabled some of the plugins that were required for the site to function properly. We went in and activated all the plugins that were disabled, but I had to do something to avoid this problem in the future. In this article, we will show you how to disable plugin deactivation from the WordPress Admin Panel (for specific plugins only).

In theory, you should be able to use Justin Tadlock's Members plugin and create a new role for users. However, the client we had did not want to go down this route. It's a small business, and they hired this new hire to deal with their social media and his blog, so we can't restrict access. They wanted to give him the ability to turn plugins on/off at will. We had to find a way to keep our customer happy, and we also had to find a way to prevent this problem from happening in the future. Fortunately for Steve Taylor, we found a snippet that allows you to remove the "Deactivate" link from specified plugins. It also removes the Edit link for all plugins because we didn't want our client to edit any plugins through the editor.

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

 add_filter ('plugin_action_links', 'disable_plugin_deactivation', 10, 4); función disable_plugin_deactivation ($ actions, $ plugin_file, $ plugin_data, $ context) // Eliminar el enlace de edición de todos si (array_key_exists ('edit', $ actions)) unset ($ actions ['edit']); // Eliminar el enlace de desactivación para complementos cruciales si (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 ')); devuelve $ acciones; 

Now, you need to change the $plugin_file array where you see the list of specified plugins. The file path 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 facebook-open-graph-meta-in-wordpress folder which is inside the folder of accessories. You can change the list to add as many plugins as you like.

This cheat is a shortcut, and doesn't actually prevent the actual deactivation. All we're doing is hiding the Deactivate link. Anyone with a bit of WordPress knowledge can generate a deactivation URL and run it. But if your client is smart enough to do that, then they already know what FTP is, and they can just remove the plugins that way.

Are you working on a theme that absolutely requires a specific plugin to work properly? Then don't forget to drop the above code.