Make WordPress Core


Ignore:
Timestamp:
11/20/2013 02:56:52 AM (11 years ago)
Author:
dd32
Message:

Themes: Add a get_theme_update_available() function to retrieve an update link and use it on the Themes page. See #26078

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r26278 r26282  
    105105 *
    106106 * @since 2.7.0
     107 * @see get_theme_update_available()
    107108 *
    108109 * @param object $theme Theme data object.
    109  * @return bool False if no valid info was passed.
    110110 */
    111111function theme_update_available( $theme ) {
     112    echo get_theme_update_available( $theme );
     113}
     114
     115/**
     116 * Retrieve the update link if there is an update for a theme available.
     117 *
     118 * Will return a link, if there is an update available.
     119 *
     120 * @since 3.8.0
     121 *
     122 * @param object $theme Theme data object.
     123 * @return string|bool HTML for the update link, or False if no valid info was passed.
     124 */
     125function get_theme_update_available( $theme ) {
    112126    static $themes_update;
    113127
    114128    if ( !current_user_can('update_themes' ) )
    115         return;
     129        return false;
    116130
    117131    if ( !isset($themes_update) )
     
    119133
    120134    if ( ! is_a( $theme, 'WP_Theme' ) )
    121         return;
     135        return false;
    122136
    123137    $stylesheet = $theme->get_stylesheet();
     138
     139    $html = '';
    124140
    125141    if ( isset($themes_update->response[ $stylesheet ]) ) {
     
    131147
    132148        if ( !is_multisite() ) {
    133             if ( ! current_user_can('update_themes') )
    134                 printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    135             else if ( empty($update['package']) )
    136                 printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    137             else
    138                 printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update now</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
    139         }
    140     }
     149            if ( ! current_user_can('update_themes') ) {
     150                $html = sprintf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
     151            } else if ( empty( $update['package'] ) ) {
     152                $html = sprintf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
     153            } else {
     154                $html = sprintf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update now</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
     155            }
     156        }
     157    }
     158
     159    return $html;
    141160}
    142161
     
    394413            'active'       => $slug === $current_theme,
    395414            'hasUpdate'    => isset( $updates[ $slug ] ),
    396             'update'       => 'New version available', // @todo complete this
     415            'update'       => get_theme_update_available( $theme ),
    397416            'actions'      => array(
    398417                'activate' => wp_nonce_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug, 'switch-theme_' . $slug ),
Note: See TracChangeset for help on using the changeset viewer.