uninstall_plugin

Uninstall a single plugin.

Description

uninstall_plugin( (string) $plugin ); 

Calls the uninstall hook, if it is available.

Parameters (1)

0. $plugin (string)
Relative plugin path from Plugin Directory.

Usage

  1. if ( !function_exists( 'uninstall_plugin' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  3.  
  4. // Relative plugin path from Plugin Directory. 
  5. $plugin = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = uninstall_plugin($plugin); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/plugin.php  
  1. function uninstall_plugin($plugin) { 
  2. $file = plugin_basename($plugin); 
  3.  
  4. $uninstallable_plugins = (array) get_option('uninstall_plugins'); 
  5.  
  6. /** 
  7. * Fires in uninstall_plugin() immediately before the plugin is uninstalled. 
  8. * @since 4.5.0 
  9. * @param string $plugin Relative plugin path from plugin directory. 
  10. * @param array $uninstallable_plugins Uninstallable plugins. 
  11. */ 
  12. do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); 
  13.  
  14. if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { 
  15. if ( isset( $uninstallable_plugins[$file] ) ) { 
  16. unset($uninstallable_plugins[$file]); 
  17. update_option('uninstall_plugins', $uninstallable_plugins); 
  18. unset($uninstallable_plugins); 
  19.  
  20. define('WP_UNINSTALL_PLUGIN', $file); 
  21. include( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ); 
  22.  
  23. return true; 
  24.  
  25. if ( isset( $uninstallable_plugins[$file] ) ) { 
  26. $callable = $uninstallable_plugins[$file]; 
  27. unset($uninstallable_plugins[$file]); 
  28. update_option('uninstall_plugins', $uninstallable_plugins); 
  29. unset($uninstallable_plugins); 
  30.  
  31. include( WP_PLUGIN_DIR . '/' . $file ); 
  32.  
  33.  
  34. /** 
  35. * Fires in uninstall_plugin() once the plugin has been uninstalled. 
  36. * The action concatenates the 'uninstall_' prefix with the basename of the 
  37. * plugin passed to uninstall_plugin() to create a dynamically-named action. 
  38. * @since 2.7.0 
  39. */