As a WordPress Developer, Sometimes you dont want the user to deactivate certain plugins which are very essential for the site and the deactivation can also break up the entire site
In such cases you can either explain the importance of those plugins to your client or to hide “Installed Plugins settings” from the dashboard so that user won’t be able to deactivate it.
Here is a WordPress code snippet which will hide the plugin from “Installed Plugins settings” once the plugin is activated.For example,once the WordPress SEO by Yoast Plugin is installed and activated user cannot able to see the Plugin from Installed Plugins settings (Dashboard >> Plugins >> Installed Plugins) thus user canot deactivate the plugin.
You need to add the following code in functions.php
file of your active WordPress Theme.
add_filter( 'all_plugins', 'hide_plugins'); function hide_plugins($plugins) { // Hide hello dolly plugin if(is_plugin_active('hello.php')) { unset( $plugins['hello.php'] ); } // Hide disqus plugin if(is_plugin_active('disqus-comment-system/disqus.php')) { unset( $plugins['disqus-comment-system/disqus.php'] ); } return $plugins; }
The above code will hide Hello Dolly plugin and Disqus comment system.Similarly you can deactivate WordPress SEO by Yoast and Akismet by adding following code.
add_filter( 'all_plugins', 'hide_plugins'); function hide_plugins($plugins) { // Hide WordPress SEO by Yoast Plugin if(is_plugin_active('wordpress-seo/wp-seo.php')) { unset( $plugins['wordpress-seo/wp-seo.php'] ); } // Hide Akismet Plugin if(is_plugin_active('akismet/akismet.php')) { unset( $plugins['akismet/akismet.php'] ); } return $plugins; }
I have tested the code in my local WordPress setup and it works really out of box.Pretty cool,Try it out atleast once.
The only drawback is if user removes the coded from functions.php
then it will be visible again.