59

How to Disable Plugin Deactivation in WordPress

Powered by WPCodeBox

Learn how to disable plugin deactivation in WordPress to prevent essential plugins from being deactivated. This snippet provides the code and instructions you need to keep your WordPress site running smoothly.


<?php

function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
 
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'advanced-custom-fields/acf.php',
        'gp-premium/gp-premium.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

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

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.