5b8eeffecb
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).
80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Cf7stg;
|
|
|
|
final class Plugin
|
|
{
|
|
private static ?Plugin $instance = null;
|
|
|
|
public static function instance(): Plugin
|
|
{
|
|
if (self::$instance === null) self::$instance = new self();
|
|
return self::$instance;
|
|
}
|
|
|
|
public static function register_autoloader(): void
|
|
{
|
|
spl_autoload_register(static function (string $class): void {
|
|
if (strpos($class, 'Cf7stg\\') !== 0) return;
|
|
$relative = substr($class, strlen('Cf7stg\\'));
|
|
$slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative));
|
|
// Class names may use underscores (Settings_Page, Interface_Spam_Source);
|
|
// normalize both word-boundary conventions to hyphens.
|
|
$slug = str_replace('_', '-', $slug);
|
|
$candidates = [
|
|
dirname(__DIR__) . '/includes/class-' . $slug . '.php',
|
|
dirname(__DIR__) . '/includes/sources/class-' . $slug . '.php',
|
|
dirname(__DIR__) . '/admin/class-' . $slug . '.php',
|
|
// Fallback: treat slug as full filename (for Interface_* classes
|
|
// whose slug already becomes 'interface-xxx').
|
|
dirname(__DIR__) . '/includes/' . $slug . '.php',
|
|
dirname(__DIR__) . '/includes/sources/' . $slug . '.php',
|
|
dirname(__DIR__) . '/admin/' . $slug . '.php',
|
|
];
|
|
foreach ($candidates as $path) {
|
|
if (is_file($path)) {
|
|
require_once $path;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
// Inject silent-drop options into Classifier filter chain
|
|
Settings::register_classifier_filters();
|
|
|
|
// Register runtime hooks
|
|
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'
|
|
);
|
|
}
|
|
}
|