Home / admin / Disable plugin deactivation for specific plugins
  • How to Disable plugin deactivation for specific plugins

    disable-plugin-deactivation-for-specific-plugins

    Adding this snippet to the functions.php of your wordpress theme will enable you to remove the deactivate link from specific plugins. This will help you stop clients from deactivating core plugins while still providing access.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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;
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    add_filter, _e, _ex,
  • Robert

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