diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 9415199a78..fa0707db7b 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -104,24 +104,40 @@ function _get_template_edit_filename($fullpath, $containingfolder) { * Will display link, if there is an update available. * * @since 2.7.0 + * @see get_theme_update_available() * * @param object $theme Theme data object. - * @return bool False if no valid info was passed. */ function theme_update_available( $theme ) { + echo get_theme_update_available( $theme ); +} + +/** + * Retrieve the update link if there is an update for a theme available. + * + * Will return a link, if there is an update available. + * + * @since 3.8.0 + * + * @param object $theme Theme data object. + * @return string|bool HTML for the update link, or False if no valid info was passed. + */ +function get_theme_update_available( $theme ) { static $themes_update; if ( !current_user_can('update_themes' ) ) - return; + return false; if ( !isset($themes_update) ) $themes_update = get_site_transient('update_themes'); if ( ! is_a( $theme, 'WP_Theme' ) ) - return; + return false; $stylesheet = $theme->get_stylesheet(); + $html = ''; + if ( isset($themes_update->response[ $stylesheet ]) ) { $update = $themes_update->response[ $stylesheet ]; $theme_name = $theme->display('Name'); @@ -130,14 +146,17 @@ function theme_update_available( $theme ) { $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"'; if ( !is_multisite() ) { - if ( ! current_user_can('update_themes') ) - printf( '
' . __('There is a new version of %1$s available. View version %3$s details.') . '
', $theme_name, $details_url, $update['new_version']); - else if ( empty($update['package']) ) - printf( '' . __('There is a new version of %1$s available. View version %3$s details. Automatic update is unavailable for this theme.') . '
', $theme_name, $details_url, $update['new_version']); - else - printf( '' . __('There is a new version of %1$s available. View version %3$s details or update now.') . '
', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick ); + if ( ! current_user_can('update_themes') ) { + $html = sprintf( '' . __('There is a new version of %1$s available. View version %3$s details.') . '
', $theme_name, $details_url, $update['new_version']); + } else if ( empty( $update['package'] ) ) { + $html = sprintf( '' . __('There is a new version of %1$s available. View version %3$s details. Automatic update is unavailable for this theme.') . '
', $theme_name, $details_url, $update['new_version']); + } else { + $html = sprintf( '' . __('There is a new version of %1$s available. View version %3$s details or update now.') . '
', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick ); + } } } + + return $html; } /** @@ -393,7 +412,7 @@ function wp_prepare_themes_for_js( $themes = null ) { 'parent' => $parent, 'active' => $slug === $current_theme, 'hasUpdate' => isset( $updates[ $slug ] ), - 'update' => 'New version available', // @todo complete this + 'update' => get_theme_update_available( $theme ), 'actions' => array( 'activate' => wp_nonce_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug, 'switch-theme_' . $slug ), 'customize'=> admin_url( 'customize.php?theme=' . $encoded_slug ), diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 41bd85ac1e..c4d16b975d 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -103,6 +103,7 @@ wp_localize_script( 'theme', '_wpThemeSettings', array( ), ) ); +add_thickbox(); wp_enqueue_style( 'theme' ); wp_enqueue_script( 'theme' ); wp_enqueue_script( 'customize-loader' );