WordPress.org

Make WordPress Core

Changeset 9793


Ignore:
Timestamp:
11/19/2008 07:25:53 PM (10 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
2 edited

Legend:

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

    r9746 r9793  
    426426                }
    427427            }
    428             if ( 'install' == $type && file_exists( WP_PLUGIN_DIR  . '/' . $api->slug ) ) //TODO: Make more.. searchable?
    429                 $type = 'latest_installed';
     428            if ( 'install' == $type && is_dir( WP_PLUGIN_DIR  . '/' . $api->slug ) ) {
     429                $installed_plugin = get_plugins('/' . $api->slug);
     430                if ( ! empty($installed_plugin) ) {
     431                    $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
     432                    if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '>') ){
     433                        $type = 'latest_installed';
     434                    } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
     435                        $type = 'newer_installed';
     436                        $newer_version = $installed_plugin[ $key ]['Version'];
     437                    } else {
     438                        //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
     439                        delete_option('update_plugins');
     440                        $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
     441                        $type = 'update_available';
     442                    }
     443                }
     444            }
    430445
    431446            switch ( $type ) :
     
    439454                    if ( current_user_can('update_plugins') ) :
    440455                        ?><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
     456                    endif;
     457                break;
     458                case 'newer_installed':
     459                    if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
     460                    ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
    441461                    endif;
    442462                break;
  • trunk/wp-includes/update.php

    r9544 r9793  
    273273
    274274add_action( 'load-plugins.php', 'wp_update_plugins' );
     275add_action( 'load-update.php', 'wp_update_plugins' );
    275276add_action( 'admin_init', '_maybe_update_plugins' );
    276277add_action( 'wp_update_plugins', 'wp_update_plugins' );
Note: See TracChangeset for help on using the changeset viewer.