wppaste
WordPress

install_plugin_install_status( array|object $api, bool $loop = false ): array

Since
3.0.0
Source
wp-admin/includes/plugin-install.php:436
Determines the status we can perform on a plugin.

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.
  • $statusstring

    Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
  • $urlstring

    Plugin installation URL.
  • $versionstring

    The most recent version of the plugin.
  • $filestring

    Plugin 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

Reaches an outbound HTTP request via wp_remote_post().

Scaling
Scales with input

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

Instructions
27–119

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • transienttransientget_site_transient()called directly
  • filesystemfilesystem accessis_dir()called directly
  • hookthird-party callbacksapply_filters()one call below install_plugin_install_status()
  • cacheobject cachewp_cache_get()one call below install_plugin_install_status()
  • optionnetwork optionget_site_option()one call below install_plugin_install_status()
  • httpoutbound HTTP requestwp_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.

WhenInstructionsCalls it makes
$status !== "install" && !isset($value)27–34get_site_transient(), compact()
$status !== "install" && isset($value)38–45get_site_transient(), wp_unslash(), urlencode(), compact()
$status === "install" && !is_dir() && !current_user_can() && !isset($value)39–46get_site_transient(), is_dir(), current_user_can(), compact()
isset($update_plugins) && !current_user_can() && $status !== "install" && !isset($value)45–47get_site_transient(), current_user_can(), compact()
$status === "install" && is_dir() && empty($installed_plugin) && !current_user_can() && !isset($value)47–54get_site_transient(), is_dir(), get_plugins(), current_user_can(), compact()
$status === "install" && !is_dir() && !current_user_can() && isset($value)50–57get_site_transient(), is_dir(), current_user_can(), wp_unslash(), urlencode(), compact()
$status === "install" && !is_dir() && current_user_can() && !isset($value)51–58get_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–57get_site_transient(), current_user_can(), self_admin_url(), wp_nonce_url(), compact()
isset($update_plugins) && !current_user_can() && $status !== "install" && isset($value)56–58get_site_transient(), current_user_can(), wp_unslash(), urlencode(), compact()
isset($update_plugins) && !current_user_can() && $status === "install" && !is_dir() && !isset($value)57–59get_site_transient(), current_user_can(), is_dir(), current_user_can(), compact()
$status === "install" && is_dir() && empty($installed_plugin) && !current_user_can() && isset($value)58–65get_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–67get_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–69get_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–67get_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–73get_site_transient(), is_dir(), get_plugins(), array_keys(), reset(), version_compare(), compact()
isset($update_plugins) && current_user_can() && $status !== "install" && isset($value)66–68get_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–69get_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–70get_site_transient(), current_user_can(), is_dir(), current_user_can(), wp_unslash(), urlencode(), compact()
isset($update_plugins) && $status === "install" && !is_dir() && !isset($value)69–71get_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–78get_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–80get_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–85get_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–77get_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–78get_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–84get_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–80get_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–80get_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–81get_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–82get_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–86get_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–96get_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–88get_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–90get_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–91get_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–92get_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–93get_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–98get_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–96get_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–97get_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–101get_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–103get_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–108get_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–109get_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–107get_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–119get_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

Used by · 3

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 .= '&amp;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.

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