Support » Fixing WordPress » Disable Delete Option for Plugins

  • parveenbhadoo

    (@parveenbhadoo)


    After searching some things, i got to know define('DISALLOW_FILE_MODS',true); can be used to disable modification of all plugins in WP, while wordpress.com has custom feature where they disabled some of their plugins to be deleted. How can i achieve this.

    I want to disable delete option for some plugins from my wp dashboard.

    • This topic was modified 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • Nikhil Bhansi

    (@nikhilbhansi)

    To remove disable action for specific plugins please use the following code snippet in your theme’s function file.
    replace ‘plugin-folder-name/plugin.php’ with the plugin name you want to remove action for.
    For Ex. 'plugin-folder-name/plugin.php' => 'akismet/akismet.php'

    /**
     * Remove Delete Action for Plugins
     * https://wordpress.org/support/topic/disable-delete-option-for-plugins/
     * @param $actions
     * @param $plugin_file
     * @param $plugin_data
     * @param $context
     * @return mixed
     */
    function chailabz_disable_plugin_deletion( $actions, $plugin_file, $plugin_data, $context ) {
    
        // Remove delete link for plugins
        if ( array_key_exists( 'delete', $actions ) && in_array( $plugin_file, array(
            'akismet/akismet.php',
            'plugin-folder-name/plugin.php'
        ) ) )
            unset( $actions['delete'] );
    
        return $actions;
    }
    add_filter( 'plugin_action_links', 'chailabz_disable_plugin_deletion', 10, 4 );

    If you want to remove the action for every plugin, please use the following code snippet.

    /**
     * Remove Delete Action for Plugins
     * https://wordpress.org/support/topic/disable-delete-option-for-plugins/
     * @param $actions
     * @param $plugin_file
     * @param $plugin_data
     * @param $context
     * @return mixed
     */
    function chailabz_disable_plugin_deletion( $actions, $plugin_file, $plugin_data, $context ) {
    
        // Remove delete link for all installed plugins
            unset( $actions['delete'] );
    
        return $actions;
    }
    add_filter( 'plugin_action_links', 'chailabz_disable_plugin_deletion', 10, 4 );

    @parveenbhadoo I hope this will help you.

    parveenbhadoo

    (@parveenbhadoo)

    Yeah, it worked very well, Is it also possible to disable the deactivate button and display a message as in this picture.
    https://imgur.com/DzFSQTI

    Edit: I changed delete to deactivate and it worked. Just need to know how to add that text.

    Nikhil Bhansi

    (@nikhilbhansi)

    That message can be added with the help of action hook after_plugin_row. 🙂

    parveenbhadoo

    (@parveenbhadoo)

    @nikhilbhansi Can you provide the exact code to do that in any plugin.
    Also, can we add * Remove Delete Action for Plugins somewhere else more private in WP to avoid removal from functions.php file.

    Edit: Solved the first problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.