get_theme_update_available( WP_Theme $theme ): string|false
- Since
- 3.8.0
- Source
wp-admin/includes/theme.php:193
Description
Will return a link if there is an update available.
Compatibility
- WordPress
- since 3.8.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
$themeWP_Theme- WP_Theme object.
Return value
string|false- HTML for the update link, or false if invalid info was passed.
Performance profile
How much work a call to get_theme_update_available() 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
- Moderate
- Scaling
- Constant
- Instructions
- 7–107
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_site_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 175.
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
- transienttransient
get_site_transient()called directly - hookthird-party callbacks
apply_filters()one call below get_theme_update_available() - cacheobject cache
wp_cache_get()one call below get_theme_update_available() - optionnetwork option
get_site_option()one call below get_theme_update_available()
Further down the call graph this can also reach query and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_theme_update_available() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–11 | current_user_can() |
current_user_can() && !isset($themes_update) && !($theme instanceof) | 15 | current_user_can(), get_site_transient() |
current_user_can() && isset($themes_update) && $theme instanceof && !isset($stylesheet) | 18 | current_user_can(), ->get_stylesheet() |
current_user_can() && !isset($themes_update) && $theme instanceof && !isset($stylesheet) | 22 | current_user_can(), get_site_transient(), ->get_stylesheet() |
current_user_can() && isset($themes_update) && $theme instanceof && isset($stylesheet) && is_multisite() | 47 | current_user_can(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite() |
current_user_can() && !isset($themes_update) && $theme instanceof && isset($stylesheet) && is_multisite() | 51 | current_user_can(), get_site_transient(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite() |
current_user_can() && isset($themes_update) && $theme instanceof && isset($stylesheet) && !is_multisite() | 83–85 | current_user_can(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite(), current_user_can(), __(), esc_url(), __(), sprintf(), esc_attr(), sprintf() |
current_user_can() && !isset($themes_update) && $theme instanceof && isset($stylesheet) && !is_multisite() | 87–89 | current_user_can(), get_site_transient(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite(), current_user_can(), __(), esc_url(), __(), sprintf(), esc_attr(), sprintf() |
current_user_can() && isset($themes_update) && $theme instanceof && isset($stylesheet) && !is_multisite() && !empty($update) | 103 | current_user_can(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite(), current_user_can(), __(), esc_url(), __(), sprintf(), esc_attr(), _x(), sprintf(), esc_attr(), sprintf() |
current_user_can() && !isset($themes_update) && $theme instanceof && isset($stylesheet) && !is_multisite() && !empty($update) | 107 | current_user_can(), get_site_transient(), ->get_stylesheet(), ->display(), add_query_arg(), urlencode(), admin_url(), wp_nonce_url(), is_multisite(), current_user_can(), __(), esc_url(), __(), sprintf(), esc_attr(), _x(), sprintf(), esc_attr(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 175 | 7–107 | 7 | |
| 8.5 | 175 | 7–107 | 7 | |
| 8.4 | 175 | 7–107 | 7 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 178 | 7–108 | 7 | |
| 8.2 | 178 | 7–108 | 7 | |
| 8.1 | 178 | 7–108 | 7 | |
| 7.4 | 178 | 7–108 | 7 |
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 · 10
- current_user_can()Returns whether the current user has the specified capability.
- get_site_transient()Retrieves the value of a site transient.
- add_query_arg()Retrieves a modified URL query string.
- wp_nonce_url()Retrieves URL with nonce added to URL query.
- admin_url()Retrieves the URL to the admin area for the current site.
- is_multisite()Determines whether Multisite is enabled.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- esc_attr()Escaping for HTML attributes.
- _x()Retrieves translated string with gettext context.
Used by · 2
- theme_update_available()Check if there is an update for a theme available.
- wp_prepare_themes_for_js()Prepares themes for JavaScript.
Source code
function get_theme_update_available( $theme ) { static $themes_update = null; if ( ! current_user_can( 'update_themes' ) ) { return false; } if ( ! isset( $themes_update ) ) { $themes_update = get_site_transient( 'update_themes' ); } if ( ! ( $theme instanceof WP_Theme ) ) { return false; } $stylesheet = $theme->get_stylesheet(); $html = ''; if ( isset( $themes_update->response[ $stylesheet ] ) ) { $update = $themes_update->response[ $stylesheet ]; $theme_name = $theme->display( 'Name' ); $details_url = add_query_arg( array( 'TB_iframe' => 'true', 'width' => 1024, 'height' => 800, ), $update['url'] ); // Theme browser inside WP? Replace this. Also, theme preview JS will override this on the available list. $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); if ( ! is_multisite() ) { if ( ! current_user_can( 'update_themes' ) ) { $html = sprintf( /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */ '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'] ); } elseif ( empty( $update['package'] ) ) { $html = sprintf( /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */ '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'] ); } else { $html = sprintf( /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */ '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'], $update_url, sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"', /* translators: %s: Theme name. */ esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ), $stylesheet ) ); }Changelog
Introduced in 3.8.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.0.4 tag, from
src/wp-admin/includes/theme.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.