As seasoned WordPress developers, we've relied on plugins to deliver robust functionality for client sites. Recently, a client's website malfunctioned: the sidebar failed to load completely, and single post pages lacked key elements. The culprit? A new team member unfamiliar with WordPress deactivated essential plugins.
We quickly reactivated them, but to safeguard against future mishaps, we hid the "Deactivate" link for specific plugins in the admin panel. This targeted approach protects critical components without limiting overall access.
While tools like Justin Tadlock's Members plugin enable custom roles, our small business client needed their social media manager to toggle plugins freely. Our solution: a reliable code snippet that removes "Deactivate" links for vital plugins and "Edit" links for all, preventing unintended changes via the built-in editor.
Add this code to your active 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 plugins
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;
}Customize the $plugin_file array to include your essential plugins. Paths are relative to /wp-content/plugins/. For example, 'facebook-open-graph-meta-in-wordpress/fbogmeta.php' targets the main file in that plugin folder.
This method hides links rather than fully blocking deactivation—knowledgeable users could bypass it via direct URLs or FTP. But for most scenarios, it's an effective safeguard. Ideal for themes dependent on specific plugins.