X

How to Disable Plugin Deactivation for Specific Plugins

Snippets by IsItWP

Are you looking for a way to remove the deactivate link from specific plugins? While there’s probably a plugin for this, we have created a quick code snippet that you can use to disable plugin deactivation for specific plugins in WordPress.

This will help you stop clients from deactivating core plugins while still providing access.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_filter( 'plugin_action_links', 'slt_lock_plugins', 10, 4 );
function slt_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;
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 8 best WordPress review plugins and how to set up author tracking in WordPress with Google Analytics.

Comments   Leave a Reply

  1. Great snippet, but this still leaves the option to deactivate it via “Bulk Actions”

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!