/** * Searches the Plugin repositories for a given plugin * * @param string $pluginfile the name of the plugin file * @param bool $skipcache If the cache'd values should be ignored * @param bool $forcecheck To Check for the update NOW, or to leave it * @return array the Plugin update information on success, array of errors on failure */ function checkPluginUpdate($pluginfile = false, $skipcache = false, $forcecheck = false) { // Does the file exist if (!$pluginfile) { return array('Errors' => array('Invalid File')); } $pluginUpdateInfo = false; //If cached requests are allowed, retrieve it if (!$skipcache) { $pluginUpdateInfo = wp_cache_get('wpupdate_' . $pluginfile, 'wpupdate'); if (!$pluginUpdateInfo) { //Check for the Option being set. $pluginUpdateInfo = get_option('wpupdate_' . $pluginfile); if ($pluginUpdateInfo) { if ($pluginUpdateInfo['Expire'] + $pluginUpdateInfo['LastChecked'] > time()) { //Check it hasnt expired (wp_cache handled expires in that case) $pluginUpdateInfo = false; } } } // end if ! $pluginUpdateInfo } //end if $skipcache //If no data is available, And we're not forcing a check, return an error if (!$pluginUpdateInfo && !$forcecheck) { return array('Errors' => array('Not Cached')); } //Get the fields from the plugin file. $pluginData = wpupdate_get_plugin_data(ABSPATH . PLUGINDIR . '/' . $pluginfile); //If no Update info, or we're forcing a recheck if (!$pluginUpdateInfo || $forcecheck) { $pluginData['Update'] = apply_filters('wpupdate_update-url', $pluginData['Update'], $pluginData); if (!empty($pluginData['Update'])) { //We have a custom update URL. $pluginUpdateInfo = $this->checkPluginUpdateCustom($pluginData['Update']); } //Else, We check the plugin searches (not } else { as the custom update url may fail) if (!$pluginUpdateInfo && get_option('update_location_search')) { //Find the plugin: $plugins = $this->search('plugins', $pluginData['Name']); if (!empty($plugins)) { foreach ((array) $plugins['results'] as $result) { if (0 === strcasecmp($result['Name'], $pluginData['Name'])) { //return information: $pluginUpdateInfo = $this->checkPluginUpdateURL($result['UpdateURL']); break; } } } } //end get_option('update_location_search') //Update cache: //If Expire is not set, or Expire is not valid if (!empty($pluginUpdateInfo) && (!isset($pluginUpdateInfo['Expire']) || !is_numeric($pluginUpdateInfo['Expire']))) { $pluginUpdateInfo['Expire'] = 7 * 24 * 60 * 60; } //If no update info is available, we cant find it. if (empty($pluginUpdateInfo)) { $pluginUpdateInfo = array('Errors' => array('Not Found'), 'Expire' => 7 * 24 * 60 * 60); } //,'(Will check again in 1 week)' $pluginUpdateInfo['LastChecked'] = time(); wp_cache_set('wpupdate_' . $pluginfile, $pluginUpdateInfo, 'wpupdate', $pluginUpdateInfo['Expire']); if (false !== get_option('update_' . $pluginfile)) { update_option('update_' . $pluginfile, $pluginUpdateInfo); } else { add_option('update_' . $pluginfile, $pluginUpdateInfo, sprintf(__('Update Information for %s'), $pluginfile), 'no'); } //We dont want to autoload this for every page, Reduce memory usage exept when needed. } //If Erorrs are set, it means we hit a snag in the update check process which has prevented checking. if (isset($pluginUpdateInfo['Errors'])) { return array('Errors' => $pluginUpdateInfo['Errors']); } //If no Plugin data available, Or the Plugin version is not specified, we cant do anything for the plugin. if (!$pluginUpdateInfo || !$pluginUpdateInfo['Version']) { return array('Errors' => array('Not Compatible', __('(No Version specified on update page)'))); } $pluginUpdateInfo = apply_filters('wpupdate_plugin-updateinfo-' . $pluginUpdateInfo, $pluginUpdateInfo); if (version_compare($pluginUpdateInfo['Version'], $pluginData['Version'], '>')) { //Theres a new version available!, Now, Check its Requirements. return array_merge($this->checkPluginCompatible($pluginUpdateInfo), array('Update' => true, 'Version' => $pluginUpdateInfo['Version'], 'PluginInfo' => $pluginUpdateInfo)); } else { //The currently installed version is the latest availaable. return array('Update' => false); } }
<?php if (!defined('ABSPATH') || !$wp_update) { die('Cannot be called directly.'); } check_admin_referer('wpupdate-upgrade-plugin'); require_once 'includes/wp-update-filesystem.php'; $installedInfo = wpupdate_get_plugin_data(ABSPATH . PLUGINDIR . '/' . $_GET['upgrade']); $action = array(); foreach ($_GET as $key => $val) { $action[] = $key . '=' . urlencode($val); } ?> <form action="<?php echo $pagenow . '?' . implode('&', $action); ?> " method="post"> <?php wp_nonce_field('wpupdate-upgrade-plugin'); $opt = array(); //Options for the filesystem. if (isset($_POST['required'])) { if (!empty($_POST['required'])) { foreach ((array) $_POST['required'] as $key => $value) { echo '<input type="hidden" name="required[' . $key . ']" value="' . attribute_escape($value) . '" />'; $opt[$key] = $value; } } } global $wp_filesystem; if (!$wp_filesystem || !is_object($wp_filesystem)) {
/** * mofidied version of get_plugins(), few performance increases * * @param string $plugin_root the basedirectory to look for plugins in, Defaults to '' which is ABSPATH . PLUGINDIR * @return array of plugin metadatas. */ function wpupdate_get_plugins($plugin_root = '') { global $wp_plugins; if (isset($wp_plugins)) { return $wp_plugins; } $wp_plugins = array(); if (empty($plugin_root)) { $plugin_root = ABSPATH . PLUGINDIR; } // Files in wp-content/plugins directory $plugins_dir = @dir($plugin_root); if ($plugins_dir) { while (($file = $plugins_dir->read()) !== false) { if ('.' == $file || '..' == $file) { continue; } if (is_dir($plugin_root . '/' . $file)) { $plugins_subdir = @dir($plugin_root . '/' . $file); if ($plugins_subdir) { while (($subfile = $plugins_subdir->read()) !== false) { if (preg_match('|\\.php$|', $subfile)) { $plugin_files[] = "{$file}/{$subfile}"; } } } } else { if (preg_match('|\\.php$|', $file)) { $plugin_files[] = $file; } } } } if (!$plugins_dir || !$plugin_files) { return $wp_plugins; } foreach ($plugin_files as $plugin_file) { $plugin_data = wpupdate_get_plugin_data("{$plugin_root}/{$plugin_file}"); if (empty($plugin_data) || empty($plugin_data['Name'])) { continue; } $wp_plugins[plugin_basename($plugin_file)] = $plugin_data; } uasort($wp_plugins, create_function('$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );')); return $wp_plugins; }