forked from Solo-Web-Works/Projects-Portfolio
Update bundled plugin-update-checker to v5.7 and remove broken setBranch() call
The bundled PUC was missing the setBranch() method on the main UpdateChecker class (it's only on Vcs\PluginUpdateChecker via the VcsCheckerMethods trait). When called with a non-VCS URL like the Gitea update URL, this caused a fatal error at plugin activation. Updating to PUC v5.7 (May 2026) which is the latest upstream release. The setBranch() call is removed because PUC doesn't recognize Gitea as a VCS host; the plugin falls back to PUC's plain JSON metadata mode, which is fine for a plugin hosted on a self-managed repo.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p7;
|
||||
|
||||
use WP_CLI;
|
||||
|
||||
/**
|
||||
* Triggers an update check when relevant WP-CLI commands are executed.
|
||||
*
|
||||
* When WP-CLI runs certain commands like "wp plugin status" or "wp theme list", it calls
|
||||
* wp_update_plugins() and wp_update_themes() to refresh update information. This class hooks into
|
||||
* the same commands and triggers an update check when they are executed.
|
||||
*
|
||||
* Note that wp_update_plugins() and wp_update_themes() do not perform an update check *every* time
|
||||
* they are called. They use a context-dependent delay between update checks. Similarly, this class
|
||||
* calls Scheduler::maybeCheckForUpdates(), which also dynamically decides whether to actually
|
||||
* run a check. If you want to force an update check, call UpdateChecker::checkForUpdates() instead.
|
||||
*/
|
||||
class WpCliCheckTrigger {
|
||||
/**
|
||||
* @var Scheduler
|
||||
*/
|
||||
private $scheduler;
|
||||
|
||||
/**
|
||||
* @var string 'plugin' or 'theme'
|
||||
*/
|
||||
private $componentType;
|
||||
|
||||
/**
|
||||
* @var bool Whether an update check was already triggered during the current request
|
||||
* or script execution.
|
||||
*/
|
||||
private $wasCheckTriggered = false;
|
||||
|
||||
public function __construct($componentType, Scheduler $scheduler) {
|
||||
if ( !in_array($componentType, ['plugin', 'theme']) ) {
|
||||
throw new \InvalidArgumentException('Invalid component type. Must be "plugin" or "theme".');
|
||||
}
|
||||
|
||||
$this->componentType = $componentType;
|
||||
$this->scheduler = $scheduler;
|
||||
|
||||
if ( !defined('WP_CLI') || !class_exists(WP_CLI::class, false) ) {
|
||||
return; //Nothing to do if WP-CLI is not available.
|
||||
}
|
||||
|
||||
/*
|
||||
* We can't hook directly into wp_update_plugins(), but we can hook into the WP-CLI
|
||||
* commands that call it. We'll use the "before_invoke:xyz" hook to trigger update checks.
|
||||
*/
|
||||
foreach ($this->getRelevantCommands() as $command) {
|
||||
WP_CLI::add_hook('before_invoke:' . $command, [$this, 'triggerUpdateCheckOnce']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getRelevantCommands() {
|
||||
$result = [];
|
||||
foreach (['status', 'list', 'update'] as $subcommand) {
|
||||
$result[] = $this->componentType . ' ' . $subcommand;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a potential update check once.
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return mixed The input value, unchanged.
|
||||
* @internal This method is public so that it can be used as a WP-CLI hook callback.
|
||||
* It should not be called directly.
|
||||
*
|
||||
*/
|
||||
public function triggerUpdateCheckOnce($input = null) {
|
||||
if ( $this->wasCheckTriggered ) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
$this->wasCheckTriggered = true;
|
||||
$this->scheduler->maybeCheckForUpdates();
|
||||
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user