25d50912f6
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
92 lines
2.8 KiB
PHP
92 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity;
|
|
|
|
final class Plugin
|
|
{
|
|
private static ?Plugin $instance = null;
|
|
private bool $booted = false;
|
|
|
|
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, 'WPMultiCity\\') !== 0) return;
|
|
$relative = substr($class, strlen('WPMultiCity\\'));
|
|
$slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative));
|
|
$slug = str_replace('_', '-', $slug);
|
|
$candidates = [
|
|
dirname(__DIR__) . '/includes/class-' . $slug . '.php',
|
|
dirname(__DIR__) . '/includes/' . $slug . '.php',
|
|
dirname(__DIR__) . '/admin/class-' . $slug . '.php',
|
|
];
|
|
foreach ($candidates as $path) {
|
|
if (is_file($path)) {
|
|
require_once $path;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
if ($this->booted) {
|
|
return;
|
|
}
|
|
$this->booted = true;
|
|
|
|
if (!$this->dependencies_satisfied()) {
|
|
add_action('admin_notices', [$this, 'render_dependency_notice']);
|
|
return;
|
|
}
|
|
|
|
Taxonomy::register();
|
|
PostType::register();
|
|
FieldGroup::register();
|
|
ShortcodeDmr::register();
|
|
OptionsPage::register();
|
|
TermMeta::register();
|
|
Redirect::register();
|
|
Router::register();
|
|
TitleFilter::register();
|
|
LinkFilter::register();
|
|
RestUrlFilter::register();
|
|
self::register_update_checker();
|
|
}
|
|
|
|
private static function register_update_checker(): void
|
|
{
|
|
$loader = WPMC_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/wp-multi-city/raw/branch/main/wp-plugin-info.json',
|
|
WPMC_PLUGIN_FILE,
|
|
'wp-multi-city'
|
|
);
|
|
}
|
|
|
|
private function dependencies_satisfied(): bool
|
|
{
|
|
return class_exists('ACF') || function_exists('acf_add_local_field_group');
|
|
}
|
|
|
|
public function render_dependency_notice(): void
|
|
{
|
|
if (!current_user_can('activate_plugins')) return;
|
|
echo '<div class="notice notice-error"><p><strong>WP Multi City:</strong> требуется активный плагин Advanced Custom Fields Pro.</p></div>';
|
|
}
|
|
}
|