Improve latest version detection in plugin updater. Props DD32. fixes #8129

git-svn-id: http://svn.automattic.com/wordpress/trunk@9793 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-11-19 19:25:53 +00:00
parent 961a173fd3
commit f5d551efe0
2 changed files with 23 additions and 2 deletions

View File

@ -425,8 +425,23 @@ function install_plugin_information() {
break;
}
}
if ( 'install' == $type && file_exists( WP_PLUGIN_DIR . '/' . $api->slug ) ) //TODO: Make more.. searchable?
$type = 'latest_installed';
if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
$installed_plugin = get_plugins('/' . $api->slug);
if ( ! empty($installed_plugin) ) {
$key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '>') ){
$type = 'latest_installed';
} elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
$type = 'newer_installed';
$newer_version = $installed_plugin[ $key ]['Version'];
} else {
//If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
delete_option('update_plugins');
$update_file = $api->slug . '/' . $key; //This code branch only deals with a plugin which is in a folder the same name as its slug, Doesnt support plugins which have 'non-standard' names
$type = 'update_available';
}
}
}
switch ( $type ) :
default:
@ -440,6 +455,11 @@ function install_plugin_information() {
?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php
endif;
break;
case 'newer_installed':
if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
endif;
break;
case 'latest_installed':
if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
?><a><?php _e('Latest Version Installed') ?></a><?php

View File

@ -272,6 +272,7 @@ function _maybe_update_themes( ) {
}
add_action( 'load-plugins.php', 'wp_update_plugins' );
add_action( 'load-update.php', 'wp_update_plugins' );
add_action( 'admin_init', '_maybe_update_plugins' );
add_action( 'wp_update_plugins', 'wp_update_plugins' );