get_theme_update_available
Retrieve the update link if there is a theme update available.
Description
(false|string) get_theme_update_available( (WP_Theme) $theme );
Will return a link if there is an update available.
Returns (false|string)
HTML for the update link, or false if invalid info was passed.
Parameters (1)
- 0. $theme (WP_Theme)
-
WP_Theme
object.
Usage
if ( !function_exists( 'get_theme_update_available' ) ) { require_once ABSPATH . '/wp-admin/includes/theme.php'; } // WP_Theme object. $theme = null; // NOTICE! Understand what this does before running. $result = get_theme_update_available($theme);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/theme.php
- 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') ) {
- /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
- $html = sprintf( '<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 */
- ),
- $update['new_version']
- );
- } elseif ( empty( $update['package'] ) ) {
- /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
- $html = sprintf( '<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 */
- ),
- $update['new_version']
- );
- } else {
- /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
- $html = sprintf( '<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 */
- ),
- $update['new_version'],
- $update_url,
- sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"',
- /** translators: %s: theme name */
- $stylesheet
- )
- );
- }
- }
- }
- return $html;
- }