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
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.
$slugstringThe plugin slug.$requires_pluginsstring[]An array of plugin dependency slugs.$versionstringThe 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
- Scaling
- Scales with input
- Instructions
- 37–146
- Plugin surface
- None
- 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 333.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - transienttransient
get_site_transient()one call below wp_get_plugin_action_button() - cacheobject cache
wp_cache_get()one call below wp_get_plugin_action_button() - hookthird-party callbacks
apply_filters()one call below wp_get_plugin_action_button() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
current_user_can() | 37–48 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can() |
!current_user_can() | 38–52 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can() |
current_user_can() && $status | 49–57 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), _x() |
current_user_can() && is_plugin_active() | 52–62 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), _x() |
$status | 53–61 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), _x() |
is_plugin_active() | 56–66 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), is_plugin_active(), _x() |
!is_plugin_active() | 58–68 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), _x() |
!is_plugin_active() | 62–72 | install_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–77 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), is_plugin_active(), current_user_can(), is_network_admin(), _x() |
!is_plugin_active() | 68–81 | install_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–89 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x() |
current_user_can() && $status | 89–95 | install_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–93 | install_plugin_install_status(), get_plugins(), get_option(), current_user_can(), current_user_can(), esc_attr(), esc_url(), _x(), sprintf(), esc_attr(), esc_attr(), _x() |
$status | 93–99 | install_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–127 | install_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–131 | install_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–142 | install_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–146 | install_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 331 | 37–146 | 33 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 333 | 37–146 | 33 | |
| 8.4 | 333 | 37–146 | 33 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 337 | 37–146 | 33 | |
| 8.2 | 337 | 37–146 | 33 | 1 more instruction than PHP 8.1 |
| 8.1 | 336 | 37–146 | 33 | |
| 7.4 | 336 | 37–146 | 33 |
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
- install_plugin_install_status()Determines the status we can perform on a plugin.
- get_plugins()Checks the plugins directory and retrieve all plugin files with plugin data.
- get_option()Retrieves an option value based on an option name.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- current_user_can()Returns whether the current user has the specified capability.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
- _x()Retrieves translated string with gettext context.
- is_plugin_active()Determines whether a plugin is active.
- add_query_arg()Retrieves a modified URL query string.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- network_admin_url()Retrieves the URL to the admin area for the network.
Show all 13
- is_network_admin()Determines whether the current request is for the network administrative interface.
Used by · 2
- WP_Plugin_Install_List_Table::display_rows()Generates the list table rows.
- install_plugin_information()Displays plugin information in dialog box form.
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.
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.