How to Disable WordPress Plugin Deactivation

Just like how clients can mess up their WordPress site by changing the theme (Learn how to Disable Theme Switching), clients can, and will, mess up their site by deactivating plugins. This problem can be easily averted by disabling the ability to deactivate WordPress Plugins.

How to Stop Users from Deactivating WordPress Plugins

Place the following code snippet in your WordPress Theme’s functions.php to disable WordPress plugin deactivation and save clients from themselves.

// how to disable plugin deactivation
add_filter( 'plugin_action_links', 'wplg_lock_plugins', 10, 4 );
function wplg_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(
		'slt-custom-fields/slt-custom-fields.php',
		'slt-file-select/slt-file-select.php',
		'slt-simple-events/slt-simple-events.php',
		'slt-widgets/slt-widgets.php'
	)))
		unset( $actions['deactivate'] );
	return $actions;
}

Just like with WordPress themes, it’s worth noting that only users with the “Administrator” level can disable WordPress plugins. So it’s also perfectly valid to give clients the “Editor” capability. More info on WordPress’ user levels.

Code Snippet via Steve Taylor

Follow wpLifeGuard

« Back to Blog