Commit Graph

112 Commits

Author SHA1 Message Date
Yahnis Elsts 2c9af31765 Add a "Resources" section.
Need a place for miscellaneous tools and tutorials.
2016-01-11 16:18:08 +02:00
Yahnis Elsts dcc0f1ce38 Refactor the render() method into multiple methods - one for each section of debug output. 2016-01-10 18:58:44 +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
Yahnis Elsts 40a65f239e Merge pull request #50 from hareesh-pillai/master
Add support for `is-dismissible` class
2016-01-01 15:02:11 +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 a9c5868910 Fix a bug in GitHub support where update installation sometimes didn't work when using a private repository. 2015-09-24 14:59:32 +03:00
Yahnis Elsts 4a415c1f33 Minor: adjust whitespace 2015-09-07 16:55:38 +03:00
Yahnis Elsts 05e97af9e1 Merge pull request #40 from dangoodman/master
Don't fail on missing debug-bar-plugin.php
2015-09-07 16:54:19 +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
Yahnis Elsts 81bbb6775b Fix automatic directory renaming not working with inline/AJAX updates. 2015-06-28 01:30:03 +03:00
Yahnis Elsts fd5feddfef Bump all version numbers to 2.1 2015-06-26 16:37:25 +03:00
Yahnis Elsts f4b013c77a Add an optional "active_installs" field. This should be an positive integer that indicates how many sites use your plugin. WordPress will show it in the "view version 1.2.3 details" pop-up. For example, if you set it to 10000, users will see "Active Installs: 10,000+".
Note that wordpress.org itself reports approximate install stats - e.g. 10000 instead of 11450. It's up to you whether you want to do the same, show the exact number of installs, or omit this field entirely.
2015-06-26 16:32:46 +03:00
Yahnis Elsts 317a45dc45 Prevent class_exists() from calling autoloaders.
The update checker uses class_exists in several ways:

- As a guard clause around `class Whatever` definitions. This ensures we don't try to define a class that has already been loaded by a different plugin. In this case, autoloading is not necessary because we already know how to load the class. Also, we *want to* load our version of that class if possible - the version that gets loaded by somebody else's autoloader might be different and incompatible.
- As a guard clause before `require` statements that include a class. This is conceptually the same as the previous example. 
- To enable optional features if Debug Bar is active. The latest compatible version of Debug Bar doesn't use autoloading, so it would again be unnecessary in this case.
2015-06-17 12:30:05 +03:00
Yahnis Elsts acb8476be2 Validate the directory structure of the update
As noted in the docs, the update ZIP file needs to have a specific directory structure. All plugin files should be inside a directory named "plugin-slug-here" and not at the root of the ZIP file. The update checker can fix the directory name if necessary, but it can't deal with the files being at the wrong level - at least not yet.

The reason this is necessary is that WordPress decides which directory to copy to /wp-content/plugins based on the contents of the update. If the ZIP contains just a single directory, WP will copy that directory. In any other case, it will copy the entire working directory where it extracted the ZIP file. This directory usually has a name like "zip-file-name.tmp". As a result, the directory name of the update won't match the directory where the old version was installed, which means WordPress will fail to reactivate the plugin.

The update checker can't rename the working directory because that would prevent WP from cleaning up temporary files in that directory (that part of the core is not hook-able and doesn't check for errors).

A potential solution would be to automatically create the requisite subdirectory and copy all update files to it. However, that would be a bit too much "magic", as well as another edge case to worry about and test. It seems better to notify the developer and let them fix their mistake.
2015-02-22 12:03:27 +02:00
Yahnis Elsts 323e80fa19 Fix fenced code blocks in lists 2015-02-10 12:00:06 +02:00
Yahnis Elsts d8a3d26b1c Indented code blocks in Markdown, arrgh. 2015-02-10 11:54:53 +02:00
Yahnis Elsts 03dd38fd71 Add support for updating plugins hosted on GitHub.
- Added experimental GitHub support. The new PucGitHubChecker subclass can check a GitHub repository for plugin updates. Depending on configuration, it will use either the latest release, the latest tag, or the specified branch. It can also automagically extract version details (description, changelog, etc) from a number of different locations - release names, plugin headers, readme.txt, changelog.md and more.
- The "slug" field of the metadata file is no longer used. The update checker will now use the slug passed to the class constructor, or generate a slug based on the plugin file name.
- Other minor changes to slug handling.
- Version bump to 2.0.
2015-02-10 11:46:46 +02:00
Yahnis Elsts 037ab7d2a4 Automatically rename update to match existing installation
Preamble:
When WordPress installs a plugin update, it assumes that the update ZIP will contain a directory that has the same name as the currently installed plugin. For example, if the plugin is installed in `/wp-content/plugins/awesome-plugin/`, WP expects that there'll be an "awesome-plugin" directory in the ZIP archive. If the update doesn't contain that directory, the installation process will either fail with a cryptic error message or produce unexpected results.
   
 The problem:
  - Some developers are either unaware of the above, or unable to format their updates accordingly. For example, they might be using GitHub to serve updates. GitHub typically names the directory in the release/branch downloads "repo-branchname" or "repo-tag-hash". WP needs it to be just "repo".
- Users can rename the plugin directory. It's very rare, but I've seen it happen.
 
Solution:
The `upgrader_source_selection` filter lets you specify the directory that will be used as the "new" version. Using it is a bit tricky because WordPress doesn't actually tell you *which* plugin or theme it's currently upgrading, but with some analysis and heuristics it's possible to figure it out (most of the time). Then you can rename the directory from the update package to match the existing plugin directory.
2015-02-06 18:01:00 +02:00
Yahnis Elsts a0ee8ca0a7 Added support for plugin banners
Usage: 
Add a new key named "banners" to the metadata file. It should be a JSON object with two string properties: "low" and "high". "low" must be a fully qualified URL pointing to a 772x250 image (PNG or JPG). "high" must point to a 1544x500 image. Only one of "low" or "high" is required. 

Example:
{
    "banners" : {
        "low" : "//example.com/assets/banner-772x250.png",
        "high" : "//example.com/assets/banner-1544x500.png"
    }
}

Banners are entirely optional.
2015-02-05 17:28:16 +02:00
Yahnis Elsts b8102edc06 Minor: Operator spacing and naming consistency
By convention, there should be a space before and after a string concatenation operator.
Also, both submit buttons should use a dash to separate the static and variable parts of the element ID.
2015-01-14 16:51:26 +02:00
Yahnis Elsts 8e7fb4a373 Merge pull request #26 from jrfnl/Less-HTML-errors
Prevent some html errors for duplicate ids
2015-01-14 16:47:08 +02:00
jrfnl 07366fff49 Prevent some html errors for duplicate ids 2015-01-14 12:51:12 +01:00
Yahnis Elsts 14466ae1bc Update copyright header 2014-12-17 12:38:48 +02:00
Yahnis Elsts a4d023e0c3 Change license to MIT/Expat 2014-12-17 12:22:29 +02:00
Yahnis Elsts 3f75005b3b Check for updates more often when the user visits the "Plugins" page, updates/installs/activates anything, or does a bulk update. This is to be more consistent with how/when WordPress checks updates in wp_update_plugins. 2014-12-09 15:09:49 +02:00
Yahnis Elsts dac23e9601 Merge pull request #23 from doublesharp/patch-1
Fix version number in library header
2014-10-27 14:00:30 +02:00
doublesharp 3564a4b045 Update plugin-update-checker.php
Fixed plugin version in header to 1.6
2014-10-26 21:10:15 -07:00
Yahnis Elsts 954aa4a192 Fixed automatic background updates not working for plugins that use this library.
Background (i.e. unattended) plugin updates require an additional $update->plugin field to be set to plugin file name relative to the /wp-content/plugins directory. Fixed by adding a $filename property to the PluginInfo and PluginUpdate classes and updating toWpFormat() to return it as "plugin". Apparently WordPress update API introduced the field a couple of minor versions back, but I didn't notice because it's used *only* by the background updater and ignored otherwise. 

I named the internal variable "filename" instead of "plugin" because "plugin" is very vague. It doesn't really tell you if the variable contains a plugin slug, plugin name, the full plugin filename, a partial filename, basename or something else. "filename" is a bit less ambiguous, though not perfect.

Bumped version to 1.6.
2014-10-24 15:53:16 +03:00
Yahnis Elsts dbe109557b Add a Composer manifest 2014-09-10 18:41:18 +03:00
Yahnis Elsts c43301056e Minor: Fix typo. 2014-05-17 11:29:33 +03:00
Yahnis Elsts 102a7b2e05 Added limited support for mu-plugins.
You can explicitly specify the MU-plugin basename (relative to "/wp-content/mu-plugins") as the last argument to PucFactory:buildUpdateChecker(). If you do, the "Check for updates" link and update notifications will show up in "Plugins -> Installed -> Must-Use". However, automatic update installation still won't  work because WordPress does not support it for mu-plugins.
2014-03-10 20:49:35 +02:00
Yahnis Elsts 8f1b7006ba Merge pull request #17 from YahnisElsts/pull_15
Pull 15
2014-02-15 13:37:19 +02:00