Make WordPress Core

Changeset 14371


Ignore:
Timestamp:
05/03/2010 01:29:15 PM (15 years ago)
Author:
westi
Message:

Move theme_update_available out of the admin page and into the admin includes.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r14370 r14371  
    242242}
    243243
     244/**
     245 * Check if there is an update for a theme available.
     246 *
     247 * Will display link, if there is an update available.
     248 *
     249 * @since 2.7.0
     250 *
     251 * @param object $theme Theme data object.
     252 * @return bool False if no valid info was passed.
     253 */
     254function theme_update_available( $theme ) {
     255    static $themes_update;
     256
     257    if ( !current_user_can('update_themes' ) )
     258        return;
     259
     260    if ( !isset($themes_update) )
     261        $themes_update = get_site_transient('update_themes');
     262
     263    if ( is_object($theme) && isset($theme->stylesheet) )
     264        $stylesheet = $theme->stylesheet;
     265    elseif ( is_array($theme) && isset($theme['Stylesheet']) )
     266        $stylesheet = $theme['Stylesheet'];
     267    else
     268        return false; //No valid info passed.
     269
     270    if ( isset($themes_update->response[ $stylesheet ]) ) {
     271        $update = $themes_update->response[ $stylesheet ];
     272        $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
     273        $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.
     274        $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
     275        $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
     276
     277        if ( ! current_user_can('update_themes') )
     278            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']);
     279        else if ( empty($update['package']) )
     280            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 upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
     281        else
     282            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>upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
     283    }
     284}
     285
    244286?>
  • trunk/wp-admin/themes.php

    r14369 r14371  
    8888
    8989$themes = array_slice( $themes, $start, $per_page );
    90 
    91 /**
    92  * Check if there is an update for a theme available.
    93  *
    94  * Will display link, if there is an update available.
    95  *
    96  * @since 2.7.0
    97  *
    98  * @param object $theme Theme data object.
    99  * @return bool False if no valid info was passed.
    100  */
    101 function theme_update_available( $theme ) {
    102     static $themes_update;
    103 
    104     if ( !current_user_can('update_themes' ) )
    105         return;
    106 
    107     if ( !isset($themes_update) )
    108         $themes_update = get_site_transient('update_themes');
    109 
    110     if ( is_object($theme) && isset($theme->stylesheet) )
    111         $stylesheet = $theme->stylesheet;
    112     elseif ( is_array($theme) && isset($theme['Stylesheet']) )
    113         $stylesheet = $theme['Stylesheet'];
    114     else
    115         return false; //No valid info passed.
    116 
    117     if ( isset($themes_update->response[ $stylesheet ]) ) {
    118         $update = $themes_update->response[ $stylesheet ];
    119         $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
    120         $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.
    121         $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
    122         $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
    123 
    124         if ( ! current_user_can('update_themes') )
    125             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']);
    126         else if ( empty($update['package']) )
    127             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 upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    128         else
    129             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>upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
    130     }
    131 }
    132 
    13390?>
    13491
Note: See TracChangeset for help on using the changeset viewer.