function silverghyll_girls_admin_menu_init() { // Find the best silverghyll admin stylesheet (highest version) $silverghyll_admin_stylesheet_path = silverghyll_include_best_library('silverghyll-admin-style.css'); $silverghyll_admin_stylesheet_url = silverghyll_include_best_library('silverghyll-admin-style.css', 'url'); if ($silverghyll_admin_stylesheet_path == '' and function_exists('silverghyll_debug_log')) { silverghyll_debug_log('Failed to locate silverghyll-admin-style.css<b/>'); } // In debug mode, report failure, otherwise silent // Register it, adding in filedate as a modifier $last_modified = date('ymdHi', filemtime($silverghyll_admin_stylesheet_path)); wp_register_style('silverghyll_admin_stylesheet', $silverghyll_admin_stylesheet_url, false, $last_modified); }
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; }
function silverghyll_log_backtrace($item, $key) { $func = $item['function']; $line = $item['line']; $file = $item['file']; $tidy = trim(basename(dirname($file)) . '/' . basename($file)); if ($tidy == '/') { $tidy = ''; } else { $tidy = $tidy . "[" . $line . "]"; } silverghyll_debug_log("{$tidy} - {$func}", "log"); }