
If you use WordPress to build websites for others, after the website is set up and handed over to the client, if the client accidentally disables necessary plugins, it will inevitably cause some unnecessary trouble. Therefore, we can disable the deactivation function of certain plugins.
Below is an introduction on how to use code to disable the deactivation function of specific plugins.
Remove the deactivation function for specific plugins
Similar to the method from the previous „WordPress Disable Update Notifications for Specific Plugins", add the following code to the theme's functions file. Friends who don't know how to add it are advised to use:Safe Method to Add Code to the functions.php File: Code Snippets
//删除特定插件的禁用功能
add_filter( 'plugin_action_links', 'wpkj_disable_plugin_deactivation', 10, 4 );
function wpkj_disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
'wpforms/wpforms.php',
'woocommerce/woocommerce.php'
)))
unset( $actions['deactivate'] );
return $actions;
}In the above code,
'wpforms/wpforms.php', 'woocommerce/woocommerce.php'
These two lines are the plugin locations where the deactivation code is to be removed. You can find the folder of each plugin in the server plugin directory (wp-content/plugins). After entering the plugin folder, the file with the same name as the plugin is usually the one.
After adding, the website plugins will no longer have a deactivation button, so you don't have to worry about the client messing around and increasing your workload.
Method source:WP University