From 519af69e93328e74aa66ac40b68ec463072dde6f Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 9 May 2012 15:01:49 +0000 Subject: [PATCH] When showing already installed themes in the theme installer list, indicate in the row actions that the theme is installed and offer an update link if updates are available. Props SergeyBiryukov Fixes #20618 git-svn-id: http://core.svn.wordpress.org/trunk@20751 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-plugin-install-list-table.php | 2 +- .../class-wp-theme-install-list-table.php | 70 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/class-wp-plugin-install-list-table.php b/wp-admin/includes/class-wp-plugin-install-list-table.php index 64a1ea7cc..4cf1c1641 100644 --- a/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -203,7 +203,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { break; case 'latest_installed': case 'newer_installed': - $action_links[] = '' . __( 'Installed' ) . ''; + $action_links[] = '' . _x( 'Installed', 'plugin' ) . ''; break; } } diff --git a/wp-admin/includes/class-wp-theme-install-list-table.php b/wp-admin/includes/class-wp-theme-install-list-table.php index 842a8ffc6..be846991a 100644 --- a/wp-admin/includes/class-wp-theme-install-list-table.php +++ b/wp-admin/includes/class-wp-theme-install-list-table.php @@ -198,7 +198,27 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { 'action' => 'install-theme', 'theme' => $theme->slug, ), self_admin_url( 'update.php' ) ); - $actions[] = '' . __( 'Install Now' ) . ''; + + $update_url = add_query_arg( array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $status = $this->_get_theme_status( $theme ); + + switch ( $status ) { + default: + case 'install': + $actions[] = '' . __( 'Install Now' ) . ''; + break; + case 'update_available': + $actions[] = '' . __( 'Update' ) . ''; + break; + case 'newer_installed': + case 'latest_installed': + $actions[] = '' . _x( 'Installed', 'theme' ) . ''; + break; + } $actions[] = '' . __( 'Preview' ) . ''; @@ -290,9 +310,28 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { 'theme' => $theme->slug, ), self_admin_url( 'update.php' ) ); + $update_url = add_query_arg( array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), self_admin_url( 'update.php' ) ); + + $status = $this->_get_theme_status( $theme ); + ?> -
- +
slug ) ) . '">' . __( 'Install' ) . ''; + break; + case 'update_available': + echo '' . __( 'Update' ) . ''; + break; + case 'newer_installed': + case 'latest_installed': + echo '' . _x( 'Installed', 'theme' ) . ''; + break; + } ?>

screenshot_url ) ): ?> @@ -328,4 +367,29 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { global $tab, $type; parent::_js_vars( compact( 'tab', 'type' ) ); } + + /** + * Check to see if the theme is already installed. + * + * @since 3.4 + * @access private + * + * @param object $theme - A WordPress.org Theme API object. + * @return string Theme status. + */ + private function _get_theme_status( $theme ) { + $status = 'install'; + + $installed_theme = wp_get_theme( $theme->slug ); + if ( $installed_theme->exists() ) { + if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) ) + $status = 'latest_installed'; + elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) ) + $status = 'newer_installed'; + else + $status = 'update_available'; + } + + return $status; + } }