• en
  • sv
WordPress Code

Stop Clients From Disabling Plugins in WordPress

You’ve build this great website for a client in WordPress that is dependent on a number of plugins for it to work and a few weeks after you launch the website, you get a call or email saying that the site you’ve build doesn’t work anymore. You go to the site only to find out that your client has disabled some of these necessary plugins.

Does that sound like a reality for you? Even if it doesn’t yet you can take some precautions to prevent this from happening. While you could use another plugin and create a custom role for your client to use, many of our clients like their accounts to be the full administrator account and they also want to be able to install new plugins and disable them at their wish.

Luckily, there is another way to go about this. Below is a small snippet of code thanks to Steve Taylor, that removes the disable link from the plugins you insert. Let’s have a look at the code:

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
	// Removes edit link for all plugins
	if ( array_key_exists( 'edit', $actions ) )
		unset( $actions['edit'] );
	// Removes the deactivate link for the plugins you specify
	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;
}

The snippet, which should be placed in your functions.php file will go through and remove the deactivate link if the files specified in the latter array exists in the plugin list.

The paths to the main plugin files are relative from the /wp-content/plugins/ directory and you can just add to the array as needed.

Note: Naturally, this does not prevent the client from finding out the deactivation link by him-/herself and running it anyway, or just signing in to the FTP and removing the plugin from there. However this has never been an issue for me personally.

About the author

Erik Bernskiold is the owner of XLD Studios and software education company Bernskiold Media. He is a WordPress lover, speaker and self-proclaimed tech geek, located in Gothenburg, Sweden.