Commit Graph

550 Commits

Author SHA1 Message Date
Yahnis Elsts e8e53e6d98 Minor: Update copyright year 2024-02-24 11:56:49 +02:00
Yahnis Elsts 1ee425c37b Bump version number to 5.4 2024-02-24 11:54:53 +02:00
Yahnis Elsts a1445bb8dc Minor: Fix misleading doc-comment and argument name.
Previously, triggerUpdateCheckOnce() was attached to a transient filter, but that's no longer the case. Now it's passed directly to WP_CLI::add_hook().

However, it still takes and returns a value. WP-CLI documentation says that the `before_invoke:<command>` hook takes one argument and acts as a filter.
2024-02-02 16:07:07 +02:00
Yahnis Elsts 36efab0022 Minor: Fix method name in a comment 2024-02-02 15:59:22 +02:00
Yahnis Elsts a211943884 WP-CLI: Maybe check for updates when certain WP-CLI commands run
See #558. Needs testing.
2024-02-02 15:58:59 +02:00
Yahnis Elsts c1bf33e770 Fix a potential autoloading failure due to not using a FQN in class_exists()
Fixes #557
2024-01-20 21:07:24 +02:00
Yahnis Elsts 0a8fd4ad3a
Merge pull request #546 from szepeviktor/fix-exports
Stop exporting development files
2024-01-19 15:40:36 +02:00
Yahnis Elsts 5f251be064 Add more sanity checks to prevent PUC from inadvertently triggering a fatal error if one of its hook callbacks is called while the containing plugin/theme is being deleted.
PUC already used `upgrader_process_complete` to remove hooks when  the plugin version it was part of was deleted during an update. However, that did not catch more obscure situations, such as apparently being called from an unrelated AJAX request while the host plugin version was being deleted (a user sent a stack trace where it seems that was what happened).
2023-11-15 18:49:00 +02:00
Yahnis Elsts 9c1bddcd46 Fix (probably) a conflict with the "WP Last Modified Info" plugin, version 1.8.8.
When a plugin update overwrites PUC with a different version of PUC, the hook callbacks registered by the old version can trigger fatal errors when they try to autoload now-deleted PHP files. Normally, PUC avoids this by using an `upgrader_process_complete` hook to check if one of its files still exists, and removing the hooks if the file is missing.  

However, it appears that WP Last Modified Info has its own `upgrader_process_complete` callback that runs earlier. That callback tries to download plugin metadata, which indirectly triggers some PUC hooks, and leads to the fatal error(s) mentioned earlier.

Fixed by extracting the relevant part of  `upgraderProcessComplete` to a separate method and registering that method as a callback for the same hook, but with an earlier priority (1 instead of 11). It appears that WP Last Modified Info uses the default priority: 10.
2023-11-14 11:52:30 +02:00
Yahnis Elsts 0b6bd7cd32 Bump version number to 5.3 2023-11-09 10:34:00 +02:00
Viktor Szépe 90e055ecd3 Stop exporting development files 2023-10-27 13:47:19 +00:00
Yahnis Elsts 00774ef3d9 Add an additional check to the Debug Bar integration to avoid triggering a fatal error in the unusual situation where `Debug_Bar` exists and `Debug_Bar_Panel` does not.
This should never happen with the Debug Bar plugin itself. However, it's apparently possible if Query Monitor is involved. See #543
2023-10-20 16:40:52 +03:00
Yahnis Elsts 0f7296123e Minor: Fix typo 2023-08-23 20:26:40 +03:00
Yahnis Elsts b9aa17be21 Add a sanity check to reject VCS updates that don't have a version number.
This can happen when PUC is configured to use a branch (as opposed to tags or releases) and it fails to retrieve the main plugin file from the repository, e.g. due to API rate limits. Then it can't get the "Version" header from the main plugin file.

See #526
2023-08-23 20:24:28 +03:00
Yahnis Elsts 5a270988c5 Minor: Update copyright year in the license 2023-08-17 15:44:32 +03:00
Yahnis Elsts 565a071b59 Bump version number to 5.2 2023-08-17 15:42:19 +03:00
Yahnis Elsts ad59ffe9a3 Add `__get`/`__set`/etc methods to the Metadata class.
Update metadata can include additional, arbitrary fields such as request statistics, licence information, and so on. This data was stored as dynamic properties on Metadata subclasses, which triggered a deprecation notice in PHP 8.2. Fixed by explicitly storing dynamic fields in a new protected property and adding magic methods to access/modify those fields.

Fixes #536
2023-06-16 14:11:14 +03:00
Yahnis Elsts 48b03e93c9 Bump version number to 5.1 2023-05-20 14:55:43 +03:00
Yahnis Elsts 98f17e4d14 Fix bad directory name 2023-05-20 14:49:27 +03:00
Yahnis Elsts 8e2e6a3b34 Minor: Quote file names passed to git 2023-05-20 14:47:06 +03:00
Yahnis Elsts fcf85abaec Fix version number not being updated in the main file 2023-05-20 14:45:30 +03:00
Yahnis Elsts ddce4cd388 Update the loader file name in composer.json 2023-05-20 14:40:30 +03:00
Yahnis Elsts 53535fd83a Fix version numbers (not) being changed in places
JSON files in the `examples` directory should not change, but the .pot file should,
2023-05-20 14:28:21 +03:00
Yahnis Elsts 10404db947 Minor: Line endings CRLF -> LF 2023-05-20 14:26:46 +03:00
Yahnis Elsts 345778385c Minor: Add a version bump completion message 2023-05-20 14:20:34 +03:00
Yahnis Elsts eddade3ebb Hopefully fix some cmd argument quoting bugs 2023-05-20 14:18:10 +03:00
Yahnis Elsts 01c1565344 Add a script for bumping the version number
WIP, needs more testing.
2023-05-20 14:13:43 +03:00
Yahnis Elsts 579d537926 Add a PHPCS configuration and fix or silence all current warnings/errors
The main functional change is that PUC will now use shorter HTTP request timeouts when not running inside a Cron task. This is to comply with the WP VIP coding standard that strongly recommends a maximum timeout of 3 seconds.

Prompted by #107
2023-05-01 12:28:55 +03:00
Yahnis Elsts a42e1e7346 Use wp_strip_all_tags() instead of strip_tags() when available
Supposedly, it's better at stripping the contents of <script> and <style> tags.
2023-05-01 12:22:04 +03:00
Yahnis Elsts ebf5bc21a0 Revert accidentally committed TODO
This reverts commit 573467a543.
2023-03-08 19:29:08 +02:00
Yahnis Elsts 573467a543 Use the same KO component for CheckBox and the toggle checkbox. 2023-03-08 19:23:53 +02:00
Yahnis Elsts c86ce6ef9f Better check to see if the update creation method exists.
Based on a user report, there are cases where just checking if the *class* exists is not sufficient.
2023-01-17 21:15:38 +02:00
Yahnis Elsts 7457e85680
Merge pull request #513 from liedekef/patch-1
Fix release asset filtering bug and treat `main` as a default branch.
2023-01-03 17:05:04 +02:00
Franky Van Liedekerke 75c05617ec
Also allow "main" as branch for github assets
When setting
$myUpdateChecker->setBranch('main');
the setting enableReleaseAssets was ignored. But since on newer versions "main" is the default (and not "master"), it should allow it.
2023-01-01 22:34:49 +01:00
Franky Van Liedekerke 2fb701089d
Fix GitHub assets
array_filter keeps the index, so if the asset matching has index 1, an array with key 1 is returned. However, further down, $matchingAssets[0] is always used. This will then fail. Using array_values after array_filter resets the indexes on the array from 0, solving the problem.
2023-01-01 22:26:25 +01:00
Yahnis Elsts 304020175d Minor: Fix grammar mistake in an error message 2022-12-01 17:38:30 +02:00
Yahnis Elsts c4bf64eca4 Add a way to filter GitHub and Gitlab releases.
The filter is applied when trying to get the latest release from a VCS repository. Inspired by #506.

Example of filtering releases by the version number: 
```php
//Allow only beta versions (e.g. for testing).
$updateChecker->getVcsApi()->setReleaseVersionFilter(
    '/beta/i', //Regex for the version number.
    Api::RELEASE_FILTER_ALL, //Disables the default filter(s).
    30 //Max number of recent releases to scan for matches.
);
```

Alternatively, you can use a callback to implement custom filtering rules. 
```php
//Set an arbitrary custom filter.
$updateChecker->getVcsApi()->setReleaseFilter(
    function($versionNumber, $releaseObject) {
        /* 
        Put your custom logic here. The $releaseObject variable contains
        the release data returned by the GitHub/GitLab API. The format
        will vary depending on which service you're using.
        */
        return true;
    },
    Api::RELEASE_FILTER_ALL
);
```

Setting a new filter will override any previous filters, so you can't add a regex-based version filter and a custom callback at the same time.
2022-11-17 18:26:23 +02:00
Yahnis Elsts affb44665f Refactor release asset support.
The GitLab release asset implementation was unnecessarily complex and did not match the coding style of the rest of the project (it was provided by an external contributor, and I didn't feel like rewriting it at the time). With the recent change of requiring PHP 5.6 as the minimum version, it's now possible to extract most of the asset logic into a new trait.

This also provided the opportunity to add an undocumented way to *require* that a release have assets:
`enableReleaseAssets('optional-regex', Vcs\Api::REQUIRE_RELEASE_ASSETS)`  

Prompted by #505
2022-11-08 18:29:37 +02:00
Yahnis Elsts 81be284da7 Fix inconsistent directory separators in the autoloader.
It looks like this was the cause of a version 5.0 bug reported in #378.
2022-10-28 20:46:32 +03:00
Yahnis Elsts 32f0079038 Minor: Fix incorrect class name in a doc comment 2022-10-28 14:01:49 +03:00
Yahnis Elsts 9bb19e44e2 Minor: Update ToC 2022-10-16 22:13:03 +03:00
Yahnis Elsts 594ea2012b Add basic migration instructions and fix incorrect class name in a couple of code samples. 2022-10-16 22:11:55 +03:00
Yahnis Elsts c5d9af3480 Minor: Switch multiple URLs to HTTPS 2022-10-15 21:00:58 +03:00
Yahnis Elsts b85b82f82d Fixed deprecation notice related to htmlentities.
The notice: "Passing null to parameter #1 ($string) of type string is deprecated". This could be triggered because some update fields can be null, like the upgrade notice field.
2022-10-15 20:58:18 +03:00
Yahnis Elsts a680a49789 Replace old class name with namespaced class name.
Also, we don't need the explicit "use" statement in this file because relative names work fine.
2022-10-15 00:27:46 +03:00
Yahnis Elsts e25b45339e Fix minor alignment issues with code sample 2022-10-15 00:18:00 +03:00
Yahnis Elsts 30f6fe7875 WIP: Update readme to use namespaces 2022-10-15 00:12:48 +03:00
Yahnis Elsts 3960de8391 Minor: Change URL to HTTPS 2022-10-14 19:48:52 +03:00
Yahnis Elsts 749f33c5c4 Fixed many WPCS warnings
This fixes or explicitly ignores most - but not all - coding standard issues that are reported when running PHP_CodeSniffer with the basic WordPress ruleset and the WordPress-VIP ruleset. 

Notably, one of the issues that remain is the request timeout for update requests and VCS API requests. The current default is 10 seconds, but the WordPress-VIP standards appear to require 3 seconds or less. Personally, I'm not sure if that low limit is appropriate for requests that are intended to mostly run in Cron jobs.
2022-10-14 19:37:00 +03:00
Yahnis Elsts 6c9fce0887 Minor: Remove unnecessary PHP version check.
PHP 5.6 is now the minimum supported version.
2022-10-13 20:12:41 +03:00