delete_plugins( string[] $plugins, string $deprecated = '' ): bool|null|WP_Error
- Since
- 2.6.0
- Source
wp-admin/includes/plugin.php:904
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
$pluginsis empty,WP_Erroron failure.
nullif 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
- Scaling
- Scales with input
- Instructions
- 6–97
- Plugin surface
- 2 hooks
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 273.
Third-party callbacks on 'delete_plugin', 'deleted_plugin' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly - transienttransient
get_site_transient()called directly - optionoption read or write
get_option()one call below delete_plugins() - cacheobject cache
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($plugins) | 6 | none |
!empty($plugins) && $credentials === false && empty($data) | 29–30 | wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean() |
!empty($plugins) && $credentials === false && !empty($data) | 38–39 | wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), exit() |
!empty($plugins) && $credentials !== false && WP_Filesystem() && !is_object($wp_filesystem) | 40–41 | wp_nonce_url(), ob_start(), request_filesystem_credentials(), ob_get_clean(), WP_Filesystem(), __() |
!empty($plugins) && $credentials !== false && !WP_Filesystem() && empty($data) | 43–44 | wp_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–52 | wp_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–53 | wp_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–54 | wp_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–56 | wp_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–64 | wp_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–68 | wp_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–76 | wp_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–80 | wp_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–81 | wp_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–85 | wp_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–93 | wp_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–97 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 273 | 6–97 | 28 | |
| 8.5 | 273 | 6–97 | 28 | |
| 8.4 | 273 | 6–97 | 28 | 11 fewer instructions than PHP 8.3 |
| 8.3 | 284 | 6–103 | 28 | |
| 8.2 | 284 | 6–103 | 28 | |
| 8.1 | 284 | 6–103 | 28 | |
| 7.4 | 284 | 6–103 | 28 |
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:
- do_action( delete_plugin )actionline 980 (+76 into the body)
Fires immediately before a plugin deletion attempt.
- do_action( deleted_plugin )actionline 1002 (+98 into the body)
Fires immediately after a plugin deletion attempt.
Uses · 13
- wp_nonce_url()Retrieves URL with nonce added to URL query.
- request_filesystem_credentials()Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
- WP_Filesystem()Initializes and connects the WordPress Filesystem Abstraction classes.
- __()Retrieves the translation of $text.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- trailingslashit()Appends a trailing slash.
- wp_get_installed_translations()Gets installed translations.
- is_uninstallable_plugin()Determines whether the plugin can be uninstalled.
- uninstall_plugin()Uninstalls a single plugin.
- do_action()Calls the callback functions that have been added to an action hook.
- get_site_transient()Retrieves the value of a site transient.
- set_site_transient()Sets/updates the value of a site transient.
Show all 13
- WP_Error::__construct()Initializes the error.
Used by · 2
- WP_REST_Plugins_Controller::delete_item()Deletes one plugin from the site.
- wp_ajax_delete_plugin()Handles deleting a plugin via AJAX.
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; } 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; } 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.
Signature, return type and hooks compared across 5 parsed releases.
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.