From 893262f742cd7ad26cc8a517d9d0cd18d67705f2 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 20 Nov 2013 02:57:10 +0000 Subject: [PATCH] Themes: Add a get_theme_update_available() function to retrieve an update link and use it on the Themes page. See #26078 Built from https://develop.svn.wordpress.org/trunk@26282 git-svn-id: http://core.svn.wordpress.org/trunk@26187 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/theme.php | 39 +++++++++++++++++++++++++++---------- wp-admin/themes.php | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index 9415199a78..fa0707db7b 100644 --- a/wp-admin/includes/theme.php +++ b/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/wp-admin/themes.php b/wp-admin/themes.php index 41bd85ac1e..c4d16b975d 100644 --- a/wp-admin/themes.php +++ b/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' );