install_plugin_install_status( array|object $api, bool $loop = false ): array
- Since
- 3.0.0
- Source
wp-admin/includes/plugin-install.php:440
Compatibility
- WordPress
- since 3.0.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
$apiarray|object- Data about the plugin retrieved from the API.
$loopbooloptional- Disable further loops. Default false.Default:
false
Return value
array- Plugin installation status data.
$statusstringStatus of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.$urlstringPlugin installation URL.$versionstringThe most recent version of the plugin.$filestringPlugin filename relative to the plugins directory.
Performance profile
How much work a call to install_plugin_install_status() 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
- Expensive
- Scaling
- Scales with input
- Instructions
- 27–119
- Plugin surface
- None
- Called by
- 3
Reaches an outbound HTTP request via wp_remote_post().
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 165.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- transienttransient
get_site_transient()called directly - filesystemfilesystem access
is_dir()called directly - hookthird-party callbacks
apply_filters()one call below install_plugin_install_status() - cacheobject cache
wp_cache_get()one call below install_plugin_install_status() - optionnetwork option
get_site_option()one call below install_plugin_install_status() - httpoutbound HTTP request
wp_remote_post()one call below install_plugin_install_status()
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 · 45 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost install_plugin_install_status() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$status !== "install" && !isset($value) | 27–34 | get_site_transient(), compact() |
$status !== "install" && isset($value) | 38–45 | get_site_transient(), wp_unslash(), urlencode(), compact() |
$status === "install" && !is_dir() && !current_user_can() && !isset($value) | 39–46 | get_site_transient(), is_dir(), current_user_can(), compact() |
isset($update_plugins) && !current_user_can() && $status !== "install" && !isset($value) | 45–47 | get_site_transient(), current_user_can(), compact() |
$status === "install" && is_dir() && empty($installed_plugin) && !current_user_can() && !isset($value) | 47–54 | get_site_transient(), is_dir(), get_plugins(), current_user_can(), compact() |
$status === "install" && !is_dir() && !current_user_can() && isset($value) | 50–57 | get_site_transient(), is_dir(), current_user_can(), wp_unslash(), urlencode(), compact() |
$status === "install" && !is_dir() && current_user_can() && !isset($value) | 51–58 | get_site_transient(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
isset($update_plugins) && current_user_can() && $status !== "install" && !isset($value) | 55–57 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
isset($update_plugins) && !current_user_can() && $status !== "install" && isset($value) | 56–58 | get_site_transient(), current_user_can(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && !is_dir() && !isset($value) | 57–59 | get_site_transient(), current_user_can(), is_dir(), current_user_can(), compact() |
$status === "install" && is_dir() && empty($installed_plugin) && !current_user_can() && isset($value) | 58–65 | get_site_transient(), is_dir(), get_plugins(), current_user_can(), wp_unslash(), urlencode(), compact() |
$status === "install" && is_dir() && empty($installed_plugin) && current_user_can() && !isset($value) | 60–67 | get_site_transient(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
33 further outcomes, up to 119 instructions
$status === "install" && !is_dir() && current_user_can() && isset($value) | 62–69 | get_site_transient(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && empty($installed_plugin) && !isset($value) | 65–67 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), current_user_can(), compact() |
$status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && !isset($value) | 66–73 | get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), compact() |
isset($update_plugins) && current_user_can() && $status !== "install" && isset($value) | 66–68 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && $status === "install" && !is_dir() && !isset($value) | 67–69 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), current_user_can(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && !is_dir() && isset($value) | 68–70 | get_site_transient(), current_user_can(), is_dir(), current_user_can(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && $status === "install" && !is_dir() && !isset($value) | 69–71 | get_site_transient(), current_user_can(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
$status === "install" && is_dir() && empty($installed_plugin) && current_user_can() && isset($value) | 71–78 | get_site_transient(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
$status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() | 73–80 | get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), delete_site_transient(), wp_update_plugins(), install_plugin_install_status() |
$status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && !isset($value) | 74–85 | get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), compact() |
isset($update_plugins) && $status === "install" && is_dir() && empty($installed_plugin) && !isset($value) | 75–77 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), current_user_can(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && empty($installed_plugin) && isset($value) | 76–78 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), current_user_can(), wp_unslash(), urlencode(), compact() |
$status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && isset($value) | 77–84 | get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && $status === "install" && is_dir() && empty($installed_plugin) && !isset($value) | 78–80 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
isset($update_plugins) && $status === "install" && !is_dir() && isset($value) | 78–80 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), current_user_can(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && !is_dir() && !isset($value) | 79–81 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
isset($update_plugins) && $status === "install" && !is_dir() && isset($value) | 80–82 | get_site_transient(), current_user_can(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && !isset($value) | 84–86 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), compact() |
$status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && isset($value) | 85–96 | get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && $status === "install" && is_dir() && empty($installed_plugin) && isset($value) | 86–88 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), current_user_can(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && empty($installed_plugin) && !isset($value) | 88–90 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), compact() |
isset($update_plugins) && $status === "install" && is_dir() && empty($installed_plugin) && isset($value) | 89–91 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && !is_dir() && isset($value) | 90–92 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() | 91–93 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), delete_site_transient(), wp_update_plugins(), install_plugin_install_status() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && !isset($value) | 92–98 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && !isset($value) | 94–96 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && isset($value) | 95–97 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && empty($installed_plugin) && isset($value) | 99–101 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), current_user_can(), self_admin_url(), wp_nonce_url(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() | 101–103 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), delete_site_transient(), wp_update_plugins(), install_plugin_install_status() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && !isset($value) | 102–108 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), compact() |
isset($update_plugins) && !current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && isset($value) | 103–109 | get_site_transient(), current_user_can(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && version_compare() && isset($value) | 105–107 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), wp_unslash(), urlencode(), compact() |
isset($update_plugins) && current_user_can() && $status === "install" && is_dir() && !empty($installed_plugin) && !version_compare() && isset($value) | 113–119 | get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), version_compare(), wp_unslash(), urlencode(), compact() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 165 instructions, 27–119 executed per call, 15 branches. The work does not change between versions.
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.
Uses · 9
- get_site_transient()Retrieves the value of a site transient.
- current_user_can()Returns whether the current user has the specified capability.
- wp_nonce_url()Retrieves URL with nonce added to URL query.
- self_admin_url()Retrieves the URL to the admin area for either the current site or the network depending on context.
- get_plugins()Checks the plugins directory and retrieve all plugin files with plugin data.
- delete_site_transient()Deletes a site transient.
- wp_update_plugins()Checks for available updates to plugins based on the latest versions hosted on WordPress.org.
- install_plugin_install_status()Determines the status we can perform on a plugin.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
Used by · 3
- install_plugin_install_status()Determines the status we can perform on a plugin.
- wp_ajax_install_plugin()Handles installing a plugin via AJAX.
- wp_get_plugin_action_button()Gets the markup for the plugin install action button.
Source code
function install_plugin_install_status( $api, $loop = false ) { // This function is called recursively, $loop prevents further loops. if ( is_array( $api ) ) { $api = (object) $api; } // Default to a "new" plugin. $status = 'install'; $url = false; $update_file = false; $version = ''; /* * Check to see if this plugin is known to be installed, * and has an update awaiting it. */ $update_plugins = get_site_transient( 'update_plugins' ); if ( isset( $update_plugins->response ) ) { foreach ( (array) $update_plugins->response as $file => $plugin ) { if ( $plugin->slug === $api->slug ) { $status = 'update_available'; $update_file = $file; $version = $plugin->new_version; if ( current_user_can( 'update_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); } break; } } } if ( 'install' === $status ) { if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { $installed_plugin = get_plugins( '/' . $api->slug ); if ( empty( $installed_plugin ) ) { if ( current_user_can( 'install_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } } else { $key = array_keys( $installed_plugin ); /* * Use the first plugin regardless of the name. * Could have issues for multiple plugins in one directory if they share different version numbers. */ $key = reset( $key ); $update_file = $api->slug . '/' . $key; if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { $status = 'latest_installed'; } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { $status = 'newer_installed'; $version = $installed_plugin[ $key ]['Version']; } else { // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. if ( ! $loop ) { delete_site_transient( 'update_plugins' ); wp_update_plugins(); return install_plugin_install_status( $api, true ); } } } } else { // "install" & no directory with that slug. if ( current_user_can( 'install_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } } } if ( isset( $_GET['from'] ) ) { $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); } $file = $update_file; return compact( 'status', 'url', 'version', 'file' );}Changelog
Introduced in 3.0.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-install.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.