Commit Graph

450 Commits

Author SHA1 Message Date
Yahnis Elsts f757517434 Use default cron schedules when possible.
This makes the library more resilient and less likely to break due to cron-related bugs in other plugins. See this commit for an analysis of one such bug: YahnisElsts/plugin-update-checker@5aee0d7b8b
2013-06-26 06:07:48 -07:00
Yahnis Elsts 5aee0d7b8b Add a workaround for a bug in BackupBuddy that would cause this library to run a new update check every few seconds. This affects BackupBuddy 3.2.0.2 and possibly multiple other versions.
Analysis:
- PluginUpdateChecker creates a custom cron schedule by using the cron_schedules filter. This schedule is used to run periodic update checks.
- BackupBuddy also creates a number of custom schedules using the same filter. However, its filter callback throws away any schedules defined by other filters/plugins and re-initializes $schedules with an empty array().
- As a result, if the filter that was added by BackupBuddy runs *after* the filter added by PluginUpdateChecker, our custom schedule is destroyed.
- When WordPress tries to re-schedule our event after a successful Cron run, it discovers that the required schedule no longer exists, and fails. On the next page load, the library detects that the event is not scheduled and schedules it again. Hence infinite loop.
- Fixed by moving our cron_schedules filter to a later priority.

Notes:
This is the *second* time I have to add a workaround for some arrogant oversight perpetrated by BackupBuddy developers. (The first one was the "plugins_api" thing, IIRC).
2013-02-22 09:40:15 -08:00
Yahnis Elsts 1fa27700a8 Fix: Make the "Check for updates" link work properly in Multisite.
Essentially, the library just switches to using /wp-admin/network/plugins.php instead of /wp-admin/plugins.php as necessary. Also, the "all_admin_notices" action runs in both normal and Network admin, so it's a better choice for displaying the update check result than either "admin_notices" or "network_admin_notices".
2013-01-07 03:04:16 -08:00
Yahnis Elsts e2ddd78cce Prevent the update checker from throwing a warning if the update state is not an object, yet is non-empty.
Technically it shouldn't be possible for this to happen, but at least one user has reported that it does.
2012-11-21 11:16:05 -08:00
Yahnis Elsts 93601c897d Fix the update check status message showing up twice when two plugins are using the library.
Pass the plugin slug in a separate "puc_slug" query parameter when doing a manual update check. This way displayManualCheckResult() can verify that the current "puc_update_check_result" value applies to the right plugin.
2012-11-08 02:33:29 -08:00
Yahnis Elsts 0132961c42 Add a readme for GitHub. This is just a stub; people who want to use the library should read the relevant blog post. 2012-11-06 00:42:20 -08:00
Yahnis Elsts bbd128d0e1 Add a factory class that should be used when creating instances of PluginUpdateChecker.
If several active plugins include the update checker library we might end up with a bunch of different versions being loaded. In the previous implementation, whichever version was loaded first would take precedence. This is obviously a problem if an old version gets loaded and one of the plugins relies on features that are only available in the latest version. 
   
The best way to fix this would be to delay library loading until all plugins have been loaded, then only load the latest available version. Unfortunately this approach would not be backwards-compatible  with previous versions that just load the library right away. Another good way to fix the problem would be to put the entire library in a versioned namespace. Alas, namespaces are only available in PHP 5.3 and WordPress only requires PHP 5.2.
 
 So what I've done is to put the version number in the class name and create a factory that will keep track of available versions and let you instantiate the latest one. Note that internal classes like PluginUpdate and PluginInfo still refer to specific implementations for internal consistency and backwards-compatibility.
2012-11-04 12:40:44 +00:00
Yahnis Elsts a0c1dfa732 Add the update checker class name to the Debug Bar output. Useful when trying to figure out which library version was loaded. 2012-11-04 11:46:55 +00:00
Yahnis Elsts 0c5f9863f0 Ensure the internal WP update structure is initialized before trying to modify it. For example, it can be `false` if WordPress has just cleared its update cache. 2012-10-31 14:57:14 +00:00
Yahnis Elsts a793bb1906 * get_submit_button() is only available in the WP admin, so make sure it exists before trying to output a button.
* HOUR_IN_SECONDS is only defined in WP 3.5+. Use the literal value instead.
2012-10-31 14:34:24 +00:00
Yahnis Elsts dd309a7310 Rename debug-bar-support.php to debug-bar-plugin.php 2012-10-29 09:13:23 +00:00
Yahnis Elsts 4a24752fce Encode special HTML characters when dumping plugin or update info to the debug bar. 2012-10-27 12:39:30 +00:00
Yahnis Elsts ae084bd3be Actually, lets prefix our custom Debug Bar IDs with "puc" to be completely sure we'll avoid name collisions. 2012-10-27 12:30:35 +00:00
Yahnis Elsts 5a3c214836 Fix duplicate IDs in the Debug Bar.
When multiple instances of the update checker are active at the same time, each will have its own PluginUpdateCheckerPanel instance and its own entry in the Debug Bar. However, since all instances have the same class name, and Debug Bar uses this name to generate link and wrapper IDs, we will end up with duplicate IDs and a semi-broken debug bar. 
 
 I've added a bit of JS that will find update checker panels and replace the relevant IDs with new ones based on the plugin slug, not class.
2012-10-27 12:26:24 +00:00
Yahnis Elsts 8260c0e712 Add explicit access modifiers to methods that didn't have them. 2012-10-27 11:48:25 +00:00
Yahnis Elsts c42810ab70 Add a Debug Bar panel that displays all kinds of debugging information about each update checker instance. You can also trigger an update check and request info/metadata through the panel. 2012-10-26 18:15:09 +00:00
Yahnis Elsts 9f1e52f6d4 This shall be the upcoming version 1.2 2012-10-26 07:42:36 +00:00
Yahnis Elsts d715f0d1d6 Minor: whitespace 2012-10-26 07:40:29 +00:00
Yahnis Elsts fa4896e7ea Automatically enable debug mode if WP_DEBUG is on. 2012-10-26 07:34:18 +00:00
Yahnis Elsts 912bac1d4b * Update copyright year and version number where necessary.
* Add "public" to functions that didn't have an explicit access modifier.
2012-10-26 07:32:09 +00:00
Yahnis Elsts 76019713e8 If there's no external update to display, remove any cached update info WordPress might have about the plugin.
This is a significant change from previous behaviour where the library would leave the value of the "update_transients" unmodified if there were no updates available. That worked fine at the time because WP wouldn't re-save the injected update to the DB. So when no updates were available, old cached updates wouldn't show up either. However, this appears to have changed - in some cases, the injected update sticks around even if the plugin is no longer injecting it. This patch counters that.

Drawback: If you use this library in a plugin that's hosted on wordpress.org, it will overwrite any update data from wordpress.org with its own and effectively disable wordpress.org updates for your plugin (doesn't affect other plugins).
2012-10-23 16:35:35 +00:00
Yahnis Elsts 850a0f18be Ensure the update (if there is one) shows up right away when the user clicks "Check for updates". Prior to this change they would need to reload the page to see the update.
Cause: Originally the update check routine was attached to the admin_notices hook. However, the plugin list is populated long before that action. 

Fixed by running the update check earlier in the request process and redirecting back to plugins.php to display the success message. As a side-effect, this will also prevent unwanted extra checks when the user reloads the page.
2012-10-20 16:54:32 +00:00
Yahnis Elsts 80a644e329 Store update state in a site option, instead of a normal, per-site field. WordPress itself stores updates in a site transient, and there's really no point in maintaining separate update states for each site in a network. 2012-10-20 15:19:47 +00:00
Yahnis Elsts aceb9e62a5 Add a resetUpdateState() method for clearing update cache, last check timestamp and last checked version. 2012-10-20 14:24:04 +00:00
Yahnis Elsts 9a9c6c2b53 Minor: Stop IDE complaining about "unknown method toStdClass()" because it doesn't realize that $state->update is a PluginUpdate. 2012-10-20 11:54:40 +00:00
Yahnis Elsts c8f04ce4d7 "callback" => "callable" (new PHP 5.3 convention) 2012-10-20 11:52:30 +00:00
Yahnis Elsts ea25c4366a * Add a "Check for updates" link to the plugin row.
* checkForUpdates() now returns the update or null.
* Added a new getUpdate() method. Use it to retrieve update details (if there is an update available). It uses the internal cache, so use checkForUpdates() instead if you want the most recent info. Also, if no update is available, or if its older than the installed version, it will return null.
* Changed our plugins_api filter priority to 20 to fix a compatibility problem caused by a bug in the WooThemes plugin updater. In short, the WooThemes updater also has a plugins_api filter, and their implementation will throw away the response returned by other filters.
2012-10-20 11:32:19 +00:00
Yahnis Elsts 242622214d Make it possible to filter update/plugin info just before it's passed to WordPress.
Also adds another convenience method for registering filter callbacks.
2012-10-19 18:10:46 +00:00
Yahnis Elsts c085ce28e8 Check if an update actually exists before converting to StdClass (what if $state was null?). 2012-10-19 17:01:16 +00:00
Yahnis Elsts 6206797e75 Add a lot more error logging - for debugging purposes. Enable by setting $debugMode to TRUE. 2012-07-19 07:47:31 +00:00
Yahnis Elsts 655b93a3bb Fail silently if we can't find the plugin in /wp-content/plugins/ or can't read its header. Note that this will also fail if the plugin is installed in mu-plugins.
This could be improved.
2012-07-11 12:12:51 +00:00
Yahnis Elsts b440d1662a * Fix stupid copy & paste errors. 2012-05-29 09:41:10 +00:00
Yahnis Elsts fa9172b477 Can't use $this in a static method, you fool. 2012-05-27 12:14:24 +00:00
Yahnis Elsts 14fcf30366 Hopefully prevent problems with caching plugins 2012-05-25 14:28:23 +00:00
Yahnis Elsts dad7e6da64 When converting plugin info to WP format, set missing fields to null instead of completely omitting them. Fixes a notice in WP core when displaying the info. 2011-09-01 11:49:48 +00:00
Yahnis Elsts 33a19853d3 Removed unnecessary &'s from callback setup routines; objects are pass-by-reference anyway in newer PHP versions. 2011-09-01 11:46:42 +00:00
Yahnis Elsts 854a9854f1 Automatically clear the cron event used by the library when the associated plugin is deactivated.
Library version 1.1
2011-09-01 10:53:07 +00:00
Yahnis Elsts b6ca731702 * Fixed several incorrect comments
* The default wp_remote_get() options are now correctly filtered, not completely discarded.
* Fixed a bunch of IDE warnings about incorrectly inferred variable types.
2011-09-01 10:28:05 +00:00
Yahnis Elsts 55a9e86e1a Added licensing information (GPL). 2011-07-04 21:31:20 +00:00
Yahnis Elsts dfffd3cef2 * Fixed the "get_plugins() not found" error when running via Cron. 2010-09-28 06:46:07 +00:00
Yahnis Elsts 79097ff988 * Specify the full URL to info.json right away instead of assembling it from an "API" URL, the slug and constants. 2010-09-01 17:02:20 +00:00
Yahnis Elsts 98dc6dbe51 * Extra comments. 2010-08-31 15:47:27 +00:00
Yahnis Elsts 4dcbbfa83e * Kill debug code. 2010-08-30 19:00:21 +00:00
Yahnis Elsts 13ed8c3e8f * Add checking_for_updates=1 to the URL when loading info.json with the purpose of checking for updates.
* Increased info.json download timeout to 10 seconds.
* Be a good netizen and send the "Accept: application/json" header when asking for the info.json file.
* Don't check the plugin's version on every pageload. Too slow (get_plugins() scans all likely-looking .php files, which can be a lot). 
* Pass the return value of wp_remote_get() as the second arg. of the result filter callback.
2010-08-30 18:50:22 +00:00
Yahnis Elsts be3210884d * Added convenience functions for registering updater-related hooks.
* Use "&" as query argument separator (instead of the oft-default "&").
* Added the missing $slug suffix to the puc_request_info_result hook.
2010-08-30 09:39:13 +00:00
Yahnis Elsts d258708e87 * Disabled (not removed) some debug output. 2010-08-29 18:06:04 +00:00
Yahnis Elsts b45e825f58 * Forgot to call installHooks, shame on me.
* Fixed update retrieval.
2010-08-29 17:56:59 +00:00
Yahnis Elsts c9d2f5e2bb 2010-08-29 17:13:18 +00:00
Yahnis Elsts e7693bf832 2010-08-29 17:10:04 +00:00
Yahnis Elsts ba64f05f12 2010-08-29 17:09:58 +00:00