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

  1. if ( !function_exists( 'get_theme_update_available' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/theme.php'; 
  3.  
  4. // WP_Theme object. 
  5. $theme = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_theme_update_available($theme); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/theme.php  
  1. function get_theme_update_available( $theme ) { 
  2. static $themes_update = null; 
  3.  
  4. if ( !current_user_can('update_themes' ) ) 
  5. return false; 
  6.  
  7. if ( !isset($themes_update) ) 
  8. $themes_update = get_site_transient('update_themes'); 
  9.  
  10. if ( ! ( $theme instanceof WP_Theme ) ) { 
  11. return false; 
  12.  
  13. $stylesheet = $theme->get_stylesheet(); 
  14.  
  15. $html = ''; 
  16.  
  17. if ( isset($themes_update->response[ $stylesheet ]) ) { 
  18. $update = $themes_update->response[ $stylesheet ]; 
  19. $theme_name = $theme->display('Name'); 
  20. $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. 
  21. $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); 
  22.  
  23. if ( !is_multisite() ) { 
  24. if ( ! current_user_can('update_themes') ) { 
  25. /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ 
  26. $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>',  
  27. $theme_name,  
  28. esc_url( $details_url ),  
  29. sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',  
  30. /** translators: 1: theme name, 2: version number */ 
  31. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) 
  32. ),  
  33. $update['new_version'] 
  34. ); 
  35. } elseif ( empty( $update['package'] ) ) { 
  36. /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ 
  37. $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>',  
  38. $theme_name,  
  39. esc_url( $details_url ),  
  40. sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',  
  41. /** translators: 1: theme name, 2: version number */ 
  42. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) 
  43. ),  
  44. $update['new_version'] 
  45. ); 
  46. } else { 
  47. /** translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */ 
  48. $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>',  
  49. $theme_name,  
  50. esc_url( $details_url ),  
  51. sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',  
  52. /** translators: 1: theme name, 2: version number */ 
  53. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) 
  54. ),  
  55. $update['new_version'],  
  56. $update_url,  
  57. sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"',  
  58. /** translators: %s: theme name */ 
  59. esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ),  
  60. $stylesheet 
  61. ); 
  62.  
  63. return $html;