wppaste
WordPress

uninstall_plugin( string $plugin ): true|void

Since
2.7.0
Source
wp-admin/includes/plugin.php:1289
Uninstalls a single plugin.

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

Reads or writes the filesystem via file_exists().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
27–54

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 79.

Plugin surface
2 hooks

Third-party callbacks on 'pre_uninstall_plugin', 'uninstall_{$file}' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksdo_action()called directly
  • filesystemfilesystem accessfile_exists()called directly
  • cacheobject cachewp_cache_get()one call below uninstall_plugin()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!file_exists() && !isset($uninstallable_plugins[$file])27plugin_basename(), get_option(), do_action(), file_exists()
file_exists() && !isset($uninstallable_plugins[$file])44plugin_basename(), get_option(), do_action(), file_exists(), define(), wp_register_plugin_realpath()
file_exists() && isset($uninstallable_plugins[$file])49plugin_basename(), get_option(), do_action(), file_exists(), update_option(), define(), wp_register_plugin_realpath()
!file_exists() && isset($uninstallable_plugins[$file])54plugin_basename(), get_option(), do_action(), file_exists(), update_option(), wp_register_plugin_realpath(), add_action(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7927–543
8.57927–543
8.47927–5434 fewer instructions than PHP 8.3
8.38329–563
8.28329–563
8.18329–563
7.48329–563

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:

  1. do_action( pre_uninstall_plugin )actionline 1302 (+13 into the body)

    Fires in uninstall_plugin() immediately before the plugin is uninstalled.

  2. do_action( uninstall_{$file} )actionline 1338 (+49 into the body)

    Fires in uninstall_plugin() once the plugin has been uninstalled.

Uses · 6

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from true|void to true|null.verified against source
2.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.