# Restricting users from deactivating specific plugins in WordPress

> Stop users from deactivating important WordPress plugins by adding a small PHP function to your theme.

Source: https://helpcenter.ruachost.com/wordpress/guides/restricting-users-from-deactivating-specific-plugins-in-wordpress/

In some cases, you may want to prevent users (including site administrators or clients) from deactivating critical plugins on your WordPress site. For example, plugins that handle security, payments, or custom functionality should remain active at all times. On **ruachost.com**, you can restrict plugin deactivation by adding a simple PHP function.

## Why Restrict Plugin Deactivation?

- Protects essential plugins from accidental removal.
- Ensures critical site functionality (e.g., WooCommerce, forms, security) remains intact.
- Provides better control when managing client sites.

## Steps to Restrict Plugin Deactivation

1. **Log in to WordPress** with an administrator account.
2. In the dashboard, go to **Appearance → Theme Editor**.
3. From the right‑hand column, select the file named **functions.php**.
4. Scroll to the bottom of the file and add the following code:

   ```
   add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );

   function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
       // List of plugins to protect from deactivation
       $protected_plugins = array(
           'wpforms/wpforms.php',
           'woocommerce/woocommerce.php'
       );

       if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, $protected_plugins ) ) {
           unset( $actions['deactivate'] );
       }

       return $actions;
   }
   ```
5. Click **Update File** to save changes.

✅ The **Deactivate** link will no longer appear for the listed plugins in the WordPress dashboard.

## Important Notes

- Always **back up your site** before editing theme files.
- Use a **child theme** to preserve changes during updates.
- You can add or remove plugin paths in the `$protected_plugins` array to customize restrictions.
- This method only hides the **Deactivate** option in the dashboard; plugins can still be removed manually via FTP or file manager.
