Also fixed a related bug where calling the triggerError() method inside the update checker constructor would not trigger an error even if WP_DEBUG was enabled. The `debugMode` property didn't get initialized until the base class constructor was run. To fix that, I've added a new isDebugModeEnabled() method that performs lazy initialisation. The downside is that it duplicates one line of code from the constructor.
Closes#180
Usage: Set up the update checker instance as usual, then call the new enableReleaseAssets() method of the GitHub API class.
`$gitHubUpdateChecker->getVcsApi()->enableReleaseAssets();`
Notes:
- You can make PUC look for a specific asset by passing a regular expression to enableReleaseAssets(). For example, `$api->enableReleaseAssets('/custom-asset/')` will make PUC use the first asset where the file name contains the string "custom-asset".
- PUC always chooses the first matching asset.
- If the latest release has no assets or none of them match the regex, PUC will fall back to the old behaviour of using the automatically generated ZIP file.
- Private repositories only work with WP 3.7 or later. Older WordPress versions will throw an error when trying to download the update.
Introduces a new hook: "puc_api_error". This is an action with up to 4 callback arguments:
1) $error - A WP_Error instance that provides a brief description of the error.
2) $response - The value returned by wp_remote_get(). Can be omitted if the original response is not available at this point.
3) $url - The URL that the update checker requested. Can be omitted.
4) $slug - The plugin or theme slug. Can be omitted.
See #151
Apparently, some developers call the file "README.txt" instead of "readme.txt". Most version control systems are case-sensitive, so we need to known the exact capitalisation to successfully retrieve the readme from the repository. Let's search the plugin directory to find the local readme file and then use that name.
Closes#147
- WordPress escapes the site URL when building the "Visit plugin site" link, so we need to look for the escaped URL instead of the raw string.
- Using regexps is probably overkill. A simple string search will do.
- Add a default case to the switch in case a plugin returns an invalid link position.
- Move the "view_details_link_position" filter inside the foreach loop to eliminate an if().
- Move the slug check closer to the top. There's no point in running the "view_details_link" filter if the link isn't going to be shown anyway.
`wp_get_installed_translations()` was introduced in WP 3.7. This change returns an empty result for the translations list if the function does not exist. (Encountered in the wild, fatal error).