Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save knilkantha/0de61ce2645d80a3d8fa4edb6e8a6fec to your computer and use it in GitHub Desktop.

Select an option

Save knilkantha/0de61ce2645d80a3d8fa4edb6e8a6fec to your computer and use it in GitHub Desktop.
Hide deactivation option in specific WordPress plugin
//Add this code on plugin's main file. This will hide current plugin's deactivation option
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'disable_plugin_deactivation' );
function disable_plugin_deactivation ($actions) {
unset( $actions['deactivate'] );
return $actions;
}
//Add this code on plugin's main file. This will hide current plugin's deactivation option
add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 2 );
function disable_plugin_deactivation( $actions, $plugin_file) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
unset( $actions['deactivate'] );
}
return $actions;
}
//This will hide deactivate option on specific plugin, We can add this code on site-specific plugin or function.php
add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 2 );
function disable_plugin_deactivation( $actions, $plugin_file ) {
//To hide deactivate option on abc and xyz plugin.
if ( in_array( $plugin_file, array('abc/abc.php','xyz/xyz.php') ) ){
unset( $actions['deactivate'] );
}
return $actions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment