install_plugin_install_status

The timeline below displays how wordpress function install_plugin_install_status has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Determines the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param array|object $api  Data about the plugin retrieved from the API.
 * @param bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin.
    $status = 'install';
    $url = false;
    $update_file = false;
    $version = '';
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' === $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $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.
                 */
                $key = reset($key);
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 6.1

/**
 * Determines the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param array|object $api  Data about the plugin retrieved from the API.
 * @param bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin.
    $status = 'install';
    $url = false;
    $update_file = false;
    $version = '';
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' === $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $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.
                $key = reset($key);
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 5.5

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param array|object $api  Data about the plugin retrieved from the API.
 * @param bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin.
    $status = 'install';
    $url = false;
    $update_file = false;
    $version = '';
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' === $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $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.
                $key = reset($key);
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 5.4

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param  array|object $api  Data about the plugin retrieved from the API.
 * @param  bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin.
    $status = 'install';
    $url = false;
    $update_file = false;
    $version = '';
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $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.
                $key = reset($key);
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: .10

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param  array|object $api  Data about the plugin retrieved from the API.
 * @param  bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin
    $status = 'install';
    $url = false;
    $update_file = false;
    $version = '';
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = reset($key);
                //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 4.7

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param  array|object $api  Data about the plugin retrieved from the API.
 * @param  bool         $loop Optional. Disable further loops. Default false.
 * @return array {
 *     Plugin installation status data.
 *
 *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
 *     @type string $url     Plugin installation URL.
 *     @type string $version The most recent version of the plugin.
 *     @type string $file    Plugin filename relative to the plugins directory.
 * }
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin
    $status = 'install';
    $url = false;
    $update_file = false;
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = reset($key);
                //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 4.3

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 *
 * @param array|object $api
 * @param bool        $loop
 * @return type
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin
    $status = 'install';
    $url = false;
    $update_file = false;
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = reset($key);
                //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 4.2

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin
    $status = 'install';
    $url = false;
    $update_file = false;
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = reset($key);
                //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
                $update_file = $api->slug . '/' . $key;
                if (version_compare($api->version, $installed_plugin[$key]['Version'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    $file = $update_file;
    return compact('status', 'url', 'version', 'file');
}

WordPress Version: 4.0

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 */
function install_plugin_install_status($api, $loop = false)
{
    // This function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    // Default to a "new" plugin
    $status = 'install';
    $url = false;
    /*
     * Check to see if this plugin is known to be installed,
     * and has an update awaiting it.
     */
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = array_shift($key);
                //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'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    return compact('status', 'url', 'version');
}

WordPress Version: 3.7

/**
 * Determine the status we can perform on a plugin.
 *
 * @since 3.0.0
 */
function install_plugin_install_status($api, $loop = false)
{
    // this function is called recursively, $loop prevents further loops.
    if (is_array($api)) {
        $api = (object) $api;
    }
    //Default to a "new" plugin
    $status = 'install';
    $url = false;
    //Check to see if this plugin is known to be installed, and has an update awaiting it.
    $update_plugins = get_site_transient('update_plugins');
    if (isset($update_plugins->response)) {
        foreach ((array) $update_plugins->response as $file => $plugin) {
            if ($plugin->slug === $api->slug) {
                $status = 'update_available';
                $update_file = $file;
                $version = $plugin->new_version;
                if (current_user_can('update_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
                }
                break;
            }
        }
    }
    if ('install' == $status) {
        if (is_dir(WP_PLUGIN_DIR . '/' . $api->slug)) {
            $installed_plugin = get_plugins('/' . $api->slug);
            if (empty($installed_plugin)) {
                if (current_user_can('install_plugins')) {
                    $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
                }
            } else {
                $key = array_keys($installed_plugin);
                $key = array_shift($key);
                //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'], '=')) {
                    $status = 'latest_installed';
                } elseif (version_compare($api->version, $installed_plugin[$key]['Version'], '<')) {
                    $status = 'newer_installed';
                    $version = $installed_plugin[$key]['Version'];
                } else if (!$loop) {
                    delete_site_transient('update_plugins');
                    wp_update_plugins();
                    return install_plugin_install_status($api, true);
                }
            }
        } else if (current_user_can('install_plugins')) {
            $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
        }
    }
    if (isset($_GET['from'])) {
        $url .= '&amp;from=' . urlencode(wp_unslash($_GET['from']));
    }
    return compact('status', 'url', 'version');
}