uninstall_plugin( string $plugin ): true|void
- Since
- 2.7.0
- Source
wp-admin/includes/plugin.php:1302
Description
Calls the uninstall hook, if it is available.
Compatibility
- WordPress
- since 2.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pluginstring- Path to the plugin file relative to the plugins directory.
Return value
true|void- True if a plugin's uninstall.php file has been found and included.
Void otherwise.
Performance profile
How much work a call to uninstall_plugin() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 27–54
- Plugin surface
- 2 hooks
- Called by
- 1
Reads or writes the filesystem via file_exists().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 79.
Third-party callbacks on 'pre_uninstall_plugin', 'uninstall_{$file}' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
do_action()called directly - filesystemfilesystem access
file_exists()called directly - cacheobject cache
wp_cache_get()one call below uninstall_plugin() - serializeserialisation
maybe_unserialize()one call below uninstall_plugin()
Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost uninstall_plugin() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!file_exists() && !isset($uninstallable_plugins[$file]) | 27 | plugin_basename(), get_option(), do_action(), file_exists() |
file_exists() && !isset($uninstallable_plugins[$file]) | 44 | plugin_basename(), get_option(), do_action(), file_exists(), define(), wp_register_plugin_realpath() |
file_exists() && isset($uninstallable_plugins[$file]) | 49 | plugin_basename(), get_option(), do_action(), file_exists(), update_option(), define(), wp_register_plugin_realpath() |
!file_exists() && isset($uninstallable_plugins[$file]) | 54 | plugin_basename(), get_option(), do_action(), file_exists(), update_option(), wp_register_plugin_realpath(), add_action(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 79 | 27–54 | 3 | |
| 8.5 | 79 | 27–54 | 3 | |
| 8.4 | 79 | 27–54 | 3 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 83 | 29–56 | 3 | |
| 8.2 | 83 | 29–56 | 3 | |
| 8.1 | 83 | 29–56 | 3 | |
| 7.4 | 83 | 29–56 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while uninstall_plugin() runs, in this order:
- do_action( pre_uninstall_plugin )actionline 1315 (+13 into the body)
Fires in uninstall_plugin() immediately before the plugin is uninstalled.
- do_action( uninstall_{$file} )actionline 1351 (+49 into the body)
Fires in uninstall_plugin() once the plugin has been uninstalled.
Uses · 6
- plugin_basename()Gets the basename of a plugin.
- get_option()Retrieves an option value based on an option name.
- do_action()Calls the callback functions that have been added to an action hook.
- update_option()Updates the value of an option that was already added.
- wp_register_plugin_realpath()Register a plugin's real path.
- add_action()Adds a callback function to an action hook.
Used by · 1
- delete_plugins()Removes directory and files of a plugin for a list of plugins.
Source code
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_once 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_once 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}" ); }}Changelog
Introduced in 2.7.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
true|void to true|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/plugin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.