function silvergyll_uninstall_plugin($database_option)
{
    if (!defined('WP_UNINSTALL_PLUGIN')) {
        exit;
        //Ensure only run when WP requests an uninstall
    } else {
        switch ($database_option) {
            case 'silverghyll':
                // We only delete this when the last Silverghyll item is uninstalled
                $plugin_count = count(silverghyll_plugin_library_dirs());
                // Count the number of installed Silverghyll plugins
                if (count($plugin_count) <= 1 and !defined(KANDIE_THEME_DIR)) {
                    // Only uninstall Colophon if this is the lasy Silverghyll item
                    delete_option('silverghyll');
                    // Delete the options stored in the database.
                    if (get_option('silverghyll')) {
                        delete_option('silverghyll');
                    }
                }
                return;
        }
    }
}
function silverghyll_include_best_library($filename = 'silverghyll-admin-menu.php', $path_type = 'dir')
{
    $transient_name = '!SILVER-BEST!' . $filename . '-' . $path_type;
    global $silverghyll_transients;
    if ($silverghyll_transients->get($transient_name)) {
        return $silverghyll_transients->get($transient_name);
        // Avoid parsing the files if we can!
    }
    $path_type = strtolower(trim($path_type));
    $silverghyll_plugins = silverghyll_plugin_library_dirs();
    // Test whether we have a theme version to test as well
    $silverghyll_options = get_option('kandie-girls-theme');
    if ($silverghyll_options['theme_name'] == get_current_theme()) {
        $silverghyll_plugins[$silverghyll_options['theme_uri'] . 'silverghyll-library/'] = $silverghyll_options['theme_dir'] . 'silverghyll-library/';
    }
    $max_ver = 0;
    // The best version found
    $best_path = '';
    // The path of the best version found
    $best_date = 0;
    // The date of the best version found as ymdHi format
    foreach ($silverghyll_plugins as $plugin => $path) {
        $file_path = $path . $filename;
        if (!file_exists($file_path)) {
            if (function_exists('silverghyll_debug_log') and silverghyll_debug_status()) {
                silverghyll_debug_log("Missing library {$filename} in {$path}<br/>");
            }
            // If debugging, we need to know
            continue;
            //  Skip any old libraries which don't contain a version of the file we want
        }
        $ver = silverghyll_versioneer($file_path);
        if (!$ver and function_exists('silverghyll_debug_log')) {
            silverghyll_debug_log('No version found in ' . $file_path . ' while finding best library');
        }
        $num_ver = silverghyll_numver($ver);
        $item_date = date('ymdHi', filemtime($file_path));
        // Debugging aid - aomment out for live use
        /*		
        		echo "<h3>File: $filename</h3>";
        		echo "<p>Bagged: ver=$max_ver @{$best_date} & path=$best_path</p>";
        		echo "<p>Testing: ver=$num_ver @{$item_date} & path=$path<br/></p>"; 
        */
        // Best is highest version or, if version is identical, the newest modified
        if ($max_ver < $num_ver or $max_ver == $num_ver and $item_date > $best_date) {
            if ($path_type[0] == 'd') {
                // Update best_path which may be a folder, URL or version
                $best_path = $path . $filename;
            } elseif ($path_type[0] == 'v') {
                $best_path = $num_ver;
            } else {
                $best_path = $plugin . $filename;
            }
            $best_date = $item_date;
            $max_ver = $num_ver;
        }
    }
    // Store in a transient to avoid iterating when not needed but only once all plugins have loaded
    if (defined('SILVERGHYLL_READY')) {
        $silverghyll_transients->set($transient_name, $best_path);
    }
    return $best_path;
}