chore: init wp-multi-city v0.1.0 with S1 skeleton + S2 design spec
S1 skeleton (cp-8ci, already done): - wp-multi-city.php with header, constants, hooks bootstrap - includes/class-plugin.php with PSR-4-ish autoloader, ACF dependency guard - includes/class-activator.php placeholder - composer.json (PHP 8.0, phpunit dev) - README.md with roadmap - uninstall.php placeholder S2 design (cp-q7g): - docs/superpowers/specs/2026-05-12-s2-taxonomy-cpt-acf-design.md
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WPMultiCity;
|
||||
|
||||
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, '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->dependencies_satisfied()) {
|
||||
add_action('admin_notices', [$this, 'render_dependency_notice']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Stage 2-5 hooks register here. Stage 1 (skeleton) intentionally empty.
|
||||
}
|
||||
|
||||
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>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user