Commit Graph

117 Commits

Author SHA1 Message Date
Yahnis Elsts a9ce2de7cf Merge remote-tracking branch 'refs/remotes/origin/master' into language-packs 2016-05-05 16:06:11 +03:00
Yahnis Elsts c6970fd883 Extract translation update filter as a method. 2016-05-03 18:32:39 +03:00
Yahnis Elsts 531c4d8247 Fix crash when running 3.x together with 2.x or lower while Debug Bar is active.
While most PUC class names use version number suffixes to avoid conflicts with older versions of the library, the classes responsible for Debug Bar integration did not (until now). This is because those classes are fairly simple and they have stayed mostly unchanged since version 1.0. Mostly, but not completely. For example, the debug bar panel depends on the getCronHookName() function, and that function was recently moved to the new PucScheduler class. 

This is a problem because when your site has two plugins using two different versions of this library (e.g. 3.0 and 1.3), you can end up in a situation where PluginUpdateChecker_3_0 unintentionally instantiates the old version of PluginUpdateCheckerPanel (1.3). Then the panel then tries to access a non-existent field or method of PluginUpdateChecker_3_0 and crashes. It produces errors like this:

[26-Apr-2016 13:34:14 UTC] PHP Fatal error:  Call to undefined method PluginUpdateChecker_3_0::getCronHookName() in [redacted]\wp-content\plugins\plugin-name-here\inc\plugin-updates\debug-bar-panel.php on line 58

Fixed by versioning debug bar panel class names.
2016-04-26 17:02:46 +03:00
Yahnis Elsts 0cfe8deaad Minor: Add a @see reference to the WP API that clears the update cache. 2016-04-19 15:42:38 +03:00
Yahnis Elsts 2c6bfc6309 Initial support for translation updates / language packs. Needs polishing and testing. 2016-04-19 13:56:54 +03:00
Yahnis Elsts 026fb99eef Initialize the $sections property with a default value (empty array).
This way we don't need to check if it's initialised.
2016-03-25 11:45:30 +02:00
Yahnis Elsts 8ec6aad7b9 Minor: whitespace 2016-03-24 22:30:11 +02:00
Yahnis Elsts b973ad6452 Simplify a couple of conditions.
In theory, $state and $state->update should always be either NULL or objects. That means isset() fully covers the possibilities and we don't need the additional empty() checks.
2016-03-24 22:27:20 +02:00
Yahnis Elsts 7a1f6d90ab Minor: Fix inconsistent indentation. 2016-03-24 21:46:07 +02:00
Yahnis Elsts de5b1d42a8 Minor: Fix incorrectly capitalized class name ("StdClass" -> "stdClass"). 2016-03-24 21:37:50 +02:00
Yahnis Elsts 43a04cca8c Extract check period calculation as a method. 2016-03-24 21:33:31 +02:00
Yahnis Elsts 6e5ebbd378 Minor: Fix some coding style issues. 2016-03-08 19:47:39 +02:00
Yahnis Elsts 67fb7c0e6b WP 4.5 compat: Add `tested` to update fields.
It appears that WordPress core developers are planning to add the `tested` and `compatibility` fields to the bulk update check API. Previously WordPress had to make a separate API request for each plugin to retrieve this information. See this Trac ticket for details:
 https://core.trac.wordpress.org/ticket/35301
 
 The `tested` field is used to generate the "Compatibility with WordPress X.Y: 100% (according to its author)" message on the "Dashboard -> Updates" page.
 
 Note: This library doesn't support the `compatibility` field, so that's not included.
2016-03-08 19:41:47 +02:00
Yahnis Elsts 109c60e8fa Remove class name aliases that were used for backwards compatibility.
The non-versioned variants of the update checker classes were removed: PluginUpdateChecker, PluginUpdate, PluginInfo. The original purpose of these aliases was to allow plugins that used the first version of PUC to easily upgrade to a newer version of the library without changing their code. However, as the update checker has evolved over time, that is no longer safe - e.g. version 3.0 might not be fully backwards-compatible with version 1.0.

If you were using the plain PluginUpdateChecker class, use this instead:

- `new PluginUpdateChecker_x_y(...)` - replace x_y with the library version number. This will create an instance of the specific version that's bundled with your plugin, which is best for compatibility with other plugins.
- `PucFactory::buildUpdateChecker()`. This will instantiate the newest loaded version, even if it was loaded by some other plugin and not yours. Simpler to use is some ways, but be prepared to support the latest version of the update checker.
2016-02-14 18:00:50 +02:00
Yahnis Elsts 7a5732bd21 Add an `if class_exists()` guard clause to the PucUpgraderStatus class. 2016-01-22 11:53:13 +02:00
Yahnis Elsts 512617903f Remove left-over hooks that were causing errors. 2016-01-15 18:28:51 +02:00
Yahnis Elsts 58a8a13efb Extract the "which plugin is being upgraded?" heuristics to a new class. 2016-01-14 19:32:58 +02:00
Yahnis Elsts 3006c8b736 Bump version to 3.0 because there are backwards-incompatible changes. 2016-01-14 17:26:44 +02:00
Yahnis Elsts 653161f3ae Merge remote-tracking branch 'refs/remotes/origin/master' into extract-scheduler 2016-01-14 17:07:44 +02:00
Yahnis Elsts 632ffd1e6b Minor: Fix spacing and rephrase a comment. 2016-01-14 16:58:25 +02:00
Yahnis Elsts cc6e2295ef Merge pull request #45 from icetee/master
Add i18n support
2016-01-14 16:36:49 +02:00
Yahnis Elsts 5b7498ba61 Replace another admin_url/network_admin_url pair with self_admin_url. 2016-01-13 19:42:22 +02:00
Yahnis Elsts 487df1d1d6 Minor: Bump copyright year to 2016 2016-01-13 18:45:56 +02:00
Yahnis Elsts 9931919237 Extract scheduling logic to a separate class. WIP. 2016-01-13 18:03:06 +02:00
Yahnis Elsts 55ad04d9b0 Extract the "identify a plugin given its file header" algorithm to a method. 2016-01-12 17:23:00 +02:00
Tamás András Horváth 87b0327f8c Merge remote-tracking branch 'refs/remotes/YahnisElsts/master' 2016-01-11 22:03:09 +01:00
Tamás András Horváth 30a6e01e44 Support i18n 2016-01-11 22:02:52 +01:00
Yahnis Elsts 8595d5a921 Extract directory structure validation as a method. 2016-01-11 17:25:04 +02:00
Yahnis Elsts 5f08d1135b Extract metadata validation as a method. 2016-01-10 16:53:09 +02:00
Yahnis Elsts 51be10504f Minor: Refactor injectUpdate(). 2016-01-09 22:17:24 +02:00
Yahnis Elsts 8ecc66c848 Refactor mu-plugin logic a bit by extracting a method. 2016-01-09 20:10:10 +02:00
Yahnis Elsts a26064220b Don't bother checking if WP_DEBUG is defined.
It's always defined. Checked as far back as WP 3.2. WordPress defines it in `/wp-includes/default-constants.php`.
2016-01-09 19:02:20 +02:00
Yahnis Elsts 080dc83ac5 Use self_admin_url() to simplify admin URL generation.
No need to check if is_network_admin() and switch between network_admin_url() and admin_url(). Turns out, WordPress already has a utility function that does that.
2016-01-09 18:41:56 +02:00
Yahnis Elsts d600e14f5d Minor: More IDE hints. 2016-01-09 18:27:59 +02:00
Yahnis Elsts 81f6d15828 Remove duplicate condition.
The triggerError method already checks for debugMode, there's no need to do it before.
2016-01-09 18:20:34 +02:00
Yahnis Elsts d78400e919 Minor: Suppress some IDE inspections (false positives). 2016-01-09 18:09:03 +02:00
Yahnis Elsts 6999915d36 Fix a "creating default object from empty value" notice on failed parsing.
Silly oversight. Given invalid input, fromJSON() can fail and return NULL.
2016-01-09 18:07:51 +02:00
Yahnis Elsts 7a29fda377 Fix a rare issue with same-host restriction causing updates to fail.
WordPress has a security feature where the HTTP API will reject all requests that are sent to another site hosted on the same server as the current site (IP match) or a local host/IP, unless the host exactly matches the current site. This feature is opt-in, but apparently some people (or security plugins?) enable it.

This can be a problem when the update metadata is on the same server as your site, but not on the exact same hostname. The aforementioned security restriction will cause updates to fail for no apparent reason.

The patch fixes the issue by using the "http_request_host_is_external" filter to explicitly allow the host that the metadata URL points to.
2016-01-09 17:55:53 +02:00
Yahnis Elsts c6f4e4841c Refactor PluginInfo a bit. 2016-01-08 12:15:22 +02:00
Yahnis Elsts b76fb8b3bd Extract the "is that a successful API response?" login as a private method. 2016-01-07 19:50:41 +02:00
Yahnis Elsts 65263271b7 Minor: Tell my IDE the type of $upgrader->skin. 2016-01-07 18:51:52 +02:00
Yahnis Elsts e65a1bbb8c Give fixDirectoryName explicit visibility.
It's declared `public` because it's a hook callback, but you should never call it from your plugin.
2016-01-07 18:49:08 +02:00
Yahnis Elsts 774af73d58 Refactor multiple calls to trigger_error as a new method.
There was a pattern of duplicate code in the library: `if ($this->debugMode) { trigger_error(...) }`. I've replaced it with a triggerError() method.
2016-01-07 17:23:44 +02:00
Yahnis Elsts fa231f35f3 Remove the $triggerErrors parameter from the fromJson() method.
Now PluginInfo will always trigger a PHP notice if it receives invalid JSON or the input doesn't pass some (basic) validation. In practice, you should never encounter this notice if you've set up your metadata correctly.
2016-01-07 16:50:02 +02:00
Hareesh 3dc371a8cc Add support for `is-dismissible` class
Adding the `is-dismissible` class introduced in [WordPress 4.2](https://make.wordpress.org/core/2015/04/23/spinners-and-dismissible-admin-notices-in-4-2/). The admin notice displayed after the update check can now be dismissed.

Solves [Issue #49](https://github.com/YahnisElsts/plugin-update-checker/issues/49)
2015-12-15 17:08:52 +05:30
Yahnis Elsts c3954feaa7 Expose the "is this plugin being updated right now?" logic as a public function.
Make it a public method: isPluginBeingUpgraded(). This method returns true if the plugin associated with the update checker is currently in the process of being updated. 

This can be useful for plugins that hook into WordPress core to change how WordPress installs updates. For example, if you were using the "upgrader_pre_download" filter, you could call this method to verify that the update being downloaded is for your plugin and not another one.

Caution: The method is not guaranteed to be accurate.
2015-11-12 13:07:15 +02:00
Yahnis Elsts 4a415c1f33 Minor: adjust whitespace 2015-09-07 16:55:38 +03:00
dangoodman 84c01cc523 Don't fail on missing debug-bar-plugin.php 2015-09-07 15:08:42 +03:00
Yahnis Elsts 155eff7964 Bump version number to 2.2 2015-07-28 13:43:46 +03:00
Yahnis Elsts 70011dbb52 Improve compatibility with plugins that use custom upgrader skins. 2015-07-28 11:55:44 +03:00