feat(updates): wire PUC v5 registration into Plugin::boot()
register_update_checker() guards on is_file + class_exists so the plugin degrades cleanly on installs that ship without the vendored lib (no update notices, but plugin core remains functional).
This commit is contained in:
@@ -50,10 +50,30 @@ final class Plugin
|
||||
Dispatcher::register_hooks();
|
||||
(new CF7Source())->register();
|
||||
|
||||
self::register_update_checker();
|
||||
|
||||
// Admin
|
||||
if (is_admin()) {
|
||||
(new Settings_Page())->register();
|
||||
(new Dashboard_Widget())->register();
|
||||
}
|
||||
}
|
||||
|
||||
private static function register_update_checker(): void
|
||||
{
|
||||
$loader = CF7STG_PLUGIN_DIR . 'includes/lib/plugin-update-checker/plugin-update-checker.php';
|
||||
if (!is_file($loader)) {
|
||||
return;
|
||||
}
|
||||
require_once $loader;
|
||||
if (!class_exists('YahnisElsts\\PluginUpdateChecker\\v5\\PucFactory')) {
|
||||
return;
|
||||
}
|
||||
|
||||
\YahnisElsts\PluginUpdateChecker\v5\PucFactory::buildUpdateChecker(
|
||||
'https://git.netranking.ru/bryzgalov/cf7-spam-to-telegram/raw/branch/main/wp-plugin-info.json',
|
||||
CF7STG_PLUGIN_FILE,
|
||||
'cf7-spam-to-telegram'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,4 +64,15 @@ final class UpdateCheckerIntegrationTest extends Cf7stgTestCase
|
||||
"download_url must contain expected asset name $expectedAssetName"
|
||||
);
|
||||
}
|
||||
|
||||
public function test_plugin_class_has_register_update_checker_method(): void
|
||||
{
|
||||
self::assertTrue(
|
||||
method_exists('\\Cf7stg\\Plugin', 'register_update_checker'),
|
||||
'Plugin class must expose register_update_checker()'
|
||||
);
|
||||
$ref = new \ReflectionMethod('\\Cf7stg\\Plugin', 'register_update_checker');
|
||||
self::assertTrue($ref->isStatic(), 'register_update_checker must be static');
|
||||
self::assertTrue($ref->isPrivate(), 'register_update_checker must be private');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user