wppaste
WordPress

wp_get_plugin_action_button( string $name, array|object $data, bool $compatible_php, bool $compatible_wp ): string

Since
6.5.0
Source
wp-admin/includes/plugin-install.php:909
Gets the markup for the plugin install action button.

Compatibility

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

$namestring
Plugin name.
$dataarray|object
An array or object of plugin data. Can be retrieved from the API.
  • $slugstring

    The plugin slug.
  • $requires_pluginsstring[]

    An array of plugin dependency slugs.
  • $versionstring

    The plugin's version string. Used when getting the install status.
$compatible_phpbool
The result of a PHP compatibility check.
$compatible_wpbool
The result of a WP compatibility check.

Return value

string
The markup for the dependency row button. An empty string if the user does not have capabilities.

Performance profile

How much work a call to wp_get_plugin_action_button() 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
37–146

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places 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
  • transienttransientget_site_transient()one call below wp_get_plugin_action_button()
  • cacheobject cachewp_cache_get()one call below wp_get_plugin_action_button()
  • hookthird-party callbacksapply_filters()one call below wp_get_plugin_action_button()
  • serializeserialisationmaybe_unserialize()one call below wp_get_plugin_action_button()

Further down the call graph this can also reach http 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 · 18 distinct outcomes

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

WhenInstructionsCalls it makes
current_user_can()37–48install_plugin_install_status(), get_plugins(), get_option(), current_user_can()
!current_user_can()38–52install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can()
current_user_can() && $status49–57install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), _x()
current_user_can() && is_plugin_active()52–62install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), _x()
$status53–61install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), _x()
is_plugin_active()56–66install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), _x()
!is_plugin_active()58–68install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), _x()
!is_plugin_active()62–72install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), current_user_can(), _x()
current_user_can() && !is_plugin_active()64–77install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), is_network_admin(), _x()
!is_plugin_active()68–81install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), current_user_can(), is_network_admin(), _x()
current_user_can() && $status && $installed_plugin_dependencies_count === false && !empty($data)85–89install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x()
current_user_can() && $status89–95install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), esc_attr(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x()
6 further outcomes, up to 146 instructions
$status && $installed_plugin_dependencies_count === false && !empty($data)89–93install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x()
$status93–99install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), esc_attr(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x()
current_user_can() && !is_plugin_active() && $active_plugin_dependencies_count === false && !is_network_admin()117–127install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), _x(), _x(), wp_create_nonce(), network_admin_url(), _wpnonce(), is_network_admin(), esc_url(), esc_attr(), esc_attr(), esc_attr(), sprintf(), esc_attr(), sprintf()
!is_plugin_active() && $active_plugin_dependencies_count === false && !is_network_admin()121–131install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), current_user_can(), _x(), _x(), wp_create_nonce(), network_admin_url(), _wpnonce(), is_network_admin(), esc_url(), esc_attr(), esc_attr(), esc_attr(), sprintf(), esc_attr(), sprintf()
current_user_can() && !is_plugin_active() && $active_plugin_dependencies_count === false && is_network_admin()132–142install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), _x(), _x(), wp_create_nonce(), network_admin_url(), _wpnonce(), is_network_admin(), _x(), _x(), add_query_arg(), esc_url(), esc_attr(), esc_attr(), esc_attr(), sprintf(), esc_attr(), sprintf()
!is_plugin_active() && $active_plugin_dependencies_count === false && is_network_admin()136–146install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), current_user_can(), _x(), _x(), wp_create_nonce(), network_admin_url(), _wpnonce(), is_network_admin(), _x(), _x(), add_query_arg(), esc_url(), esc_attr(), esc_attr(), esc_attr(), sprintf(), esc_attr(), sprintf()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev33137–146332 fewer instructions than PHP 8.5
8.533337–14633
8.433337–146334 fewer instructions than PHP 8.3
8.333737–14633
8.233737–146331 more instruction than PHP 8.1
8.133637–14633
7.433637–14633

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 · 13

Show all 13
  • is_network_admin()Determines whether the current request is for the network administrative interface.

Used by · 2

Source code

function wp_get_plugin_action_button( $name, $data, $compatible_php, $compatible_wp ) {	$button           = '';	$data             = (object) $data;	$status           = install_plugin_install_status( $data );	$requires_plugins = $data->requires_plugins ?? array(); 	// Determine the status of plugin dependencies.	$installed_plugins                   = get_plugins();	$active_plugins                      = get_option( 'active_plugins', array() );	$plugin_dependencies_count           = count( $requires_plugins );	$installed_plugin_dependencies_count = 0;	$active_plugin_dependencies_count    = 0;	foreach ( $requires_plugins as $dependency ) {		foreach ( array_keys( $installed_plugins ) as $installed_plugin_file ) {			if ( str_contains( $installed_plugin_file, '/' ) && explode( '/', $installed_plugin_file )[0] === $dependency ) {				++$installed_plugin_dependencies_count;			}		} 		foreach ( $active_plugins as $active_plugin_file ) {			if ( str_contains( $active_plugin_file, '/' ) && explode( '/', $active_plugin_file )[0] === $dependency ) {				++$active_plugin_dependencies_count;			}		}	}	$all_plugin_dependencies_installed = $installed_plugin_dependencies_count === $plugin_dependencies_count;	$all_plugin_dependencies_active    = $active_plugin_dependencies_count === $plugin_dependencies_count; 	if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {		switch ( $status['status'] ) {			case 'install':				if ( $status['url'] ) {					if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) {						$button = sprintf(							'<a class="install-now button button-compact" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',							esc_attr( $data->slug ),							esc_url( $status['url'] ),							/* translators: %s: Plugin name and version. */							esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),							esc_attr( $name ),							_x( 'Install Now', 'plugin' )						);					} else {						$button = sprintf(							'<button type="button" class="install-now button button-compact button-disabled" disabled="disabled">%s</button>',							_x( 'Install Now', 'plugin' )						);					}				}				break; 			case 'update_available':				if ( $status['url'] ) {					if ( $compatible_php && $compatible_wp ) {						$button = sprintf(							'<a class="update-now button button-compact aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',							esc_attr( $status['file'] ),							esc_attr( $data->slug ),							esc_url( $status['url'] ),							/* translators: %s: Plugin name and version. */							esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),							esc_attr( $name ),							_x( 'Update Now', 'plugin' )						);					} else {						$button = sprintf(							'<button type="button" class="button button-compact button-disabled" disabled="disabled">%s</button>',							_x( 'Update Now', 'plugin' )						);					}				}				break; 			case 'latest_installed':			case 'newer_installed':				if ( is_plugin_active( $status['file'] ) ) {					$button = sprintf(						'<button type="button" class="button button-compact button-disabled" disabled="disabled">%s</button>',						_x( 'Active', 'plugin' )					);

Changelog

Introduced in 6.5.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.1.0 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.