uninstall_plugin( string $plugin )
Uninstall a single plugin.
Description Description
Calls the uninstall hook, if it is available.
Parameters Parameters
- $plugin
-
(string) (Required) Path to the plugin file relative to the plugins directory.
Return Return
(true) True if a plugin's uninstall.php file has been found and included.
Source Source
File: wp-admin/includes/plugin.php
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | function uninstall_plugin( $plugin ) { $file = plugin_basename( $plugin ); $uninstallable_plugins = ( array ) get_option( 'uninstall_plugins' ); /** * Fires in uninstall_plugin() immediately before the plugin is uninstalled. * * @since 4.5.0 * * @param string $plugin Path to the plugin file relative to the plugins directory. * @param array $uninstallable_plugins Uninstallable plugins. */ do_action( 'pre_uninstall_plugin' , $plugin , $uninstallable_plugins ); if ( file_exists ( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) { if ( isset( $uninstallable_plugins [ $file ] ) ) { unset( $uninstallable_plugins [ $file ] ); update_option( 'uninstall_plugins' , $uninstallable_plugins ); } unset( $uninstallable_plugins ); define( 'WP_UNINSTALL_PLUGIN' , $file ); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); include ( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ); return true; } if ( isset( $uninstallable_plugins [ $file ] ) ) { $callable = $uninstallable_plugins [ $file ]; unset( $uninstallable_plugins [ $file ] ); update_option( 'uninstall_plugins' , $uninstallable_plugins ); unset( $uninstallable_plugins ); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); include ( WP_PLUGIN_DIR . '/' . $file ); add_action( "uninstall_{$file}" , $callable ); /** * Fires in uninstall_plugin() once the plugin has been uninstalled. * * The action concatenates the 'uninstall_' prefix with the basename of the * plugin passed to uninstall_plugin() to create a dynamically-named action. * * @since 2.7.0 */ do_action( "uninstall_{$file}" ); } } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |