wppaste
WordPress

delete_plugins( string[] $plugins, string $deprecated = '' ): bool|null|WP_Error

Since
2.6.0
Source
wp-admin/includes/plugin.php:904
Removes directory and files of a plugin for a list of plugins.

Compatibility

WordPress
since 2.6.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

$pluginsstring[]
List of plugin paths to delete, relative to the plugins directory.
$deprecatedstringoptional
Not used.Default: ''

Return value

bool|null|WP_Error
True on success, false if $plugins is empty, WP_Error on failure.
null if filesystem credentials are required to proceed.

Performance profile

How much work a call to delete_plugins() 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 stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
6–97

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

Plugin surface
2 hooks

Third-party callbacks on 'delete_plugin', 'deleted_plugin' run inside this call, and their cost is not bounded by anything here.

Called by
2

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

What it touches

  • hookthird-party callbacksdo_action()called directly
  • transienttransientget_site_transient()called directly
  • optionoption read or writeget_option()one call below delete_plugins()
  • cacheobject cachewp_cache_get()one call below delete_plugins()

Further down the call graph this can also reach serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 17 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost delete_plugins() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($plugins)6none
!empty($plugins) && $credentials === false && empty($data)29–30wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean()
!empty($plugins) && $credentials === false && !empty($data)38–39wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), exit()
!empty($plugins) && $credentials !== false && WP_Filesystem() && !is_object($wp_filesystem)40–41wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), __()
!empty($plugins) && $credentials !== false && !WP_Filesystem() && empty($data)43–44wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), ob_start(), request_filesystem_credentials(), ob_get_clean()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && empty($plugins_dir)51–52wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir(), __()
!empty($plugins) && $credentials !== false && !WP_Filesystem() && !empty($data)52–53wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), ob_start(), request_filesystem_credentials(), ob_get_clean(), exit()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && ->has_errors()53–54wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), __()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && empty($plugins_dir)55–56wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir(), __()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !empty($plugins_dir) && empty($errors)62–64wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !empty($plugins_dir) && empty($errors)66–68wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !empty($plugins_dir) && empty($errors)73–76wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), array_diff(), set_site_transient()
5 further outcomes, up to 97 instructions
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !empty($plugins_dir) && empty($errors)77–80wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), array_diff(), set_site_transient()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !empty($plugins_dir) && !empty($errors)78–81wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), __(), sprintf(), array_map()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !empty($plugins_dir) && !empty($errors)82–85wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), __(), sprintf(), array_map()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !empty($plugins_dir) && !empty($errors)89–93wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), array_diff(), set_site_transient(), __(), sprintf(), array_map()
!empty($plugins) && $credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !empty($plugins_dir) && !empty($errors)93–97wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir(), trailingslashit(), wp_get_installed_translations(), get_site_transient(), array_diff(), set_site_transient(), __(), sprintf(), array_map()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2736–9728
8.52736–9728
8.42736–972811 fewer instructions than PHP 8.3
8.32846–10328
8.22846–10328
8.12846–10328
7.42846–10328

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 delete_plugins() runs, in this order:

  1. do_action( delete_plugin )actionline 980 (+76 into the body)

    Fires immediately before a plugin deletion attempt.

  2. do_action( deleted_plugin )actionline 1002 (+98 into the body)

    Fires immediately after a plugin deletion attempt.

Uses · 13

Show all 13

Used by · 2

Source code

function delete_plugins( $plugins, $deprecated = '' ) {	global $wp_filesystem; 	if ( empty( $plugins ) ) {		return false;	} 	$checked = array();	foreach ( $plugins as $plugin ) {		$checked[] = 'checked[]=' . $plugin;	} 	$url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' ); 	ob_start();	$credentials = request_filesystem_credentials( $url );	$data        = ob_get_clean(); 	if ( false === $credentials ) {		if ( ! empty( $data ) ) {			require_once ABSPATH . 'wp-admin/admin-header.php';			echo $data;			require_once ABSPATH . 'wp-admin/admin-footer.php';			exit;		}		return null;	} 	if ( ! WP_Filesystem( $credentials ) ) {		ob_start();		// Failed to connect. Error and request again.		request_filesystem_credentials( $url, '', true );		$data = ob_get_clean(); 		if ( ! empty( $data ) ) {			require_once ABSPATH . 'wp-admin/admin-header.php';			echo $data;			require_once ABSPATH . 'wp-admin/admin-footer.php';			exit;		}		return null;	} 	if ( ! is_object( $wp_filesystem ) ) {		return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );	} 	if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {		return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );	} 	// Get the base plugin folder.	$plugins_dir = $wp_filesystem->wp_plugins_dir();	if ( empty( $plugins_dir ) ) {		return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) );	} 	$plugins_dir = trailingslashit( $plugins_dir ); 	$plugin_translations = wp_get_installed_translations( 'plugins' ); 	$errors = array(); 	foreach ( $plugins as $plugin_file ) {		// Run Uninstall hook.		if ( is_uninstallable_plugin( $plugin_file ) ) {			uninstall_plugin( $plugin_file );		} 		/**		 * Fires immediately before a plugin deletion attempt.		 *		 * @since 4.4.0		 *		 * @param string $plugin_file Path to the plugin file relative to the plugins directory.		 */		do_action( 'delete_plugin', $plugin_file ); 		$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );

Changelog

Introduced in 2.6.0. Unchanged from 6.7.7 through 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.

About 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.