How ourfreewp/wp2 works
Project Type & Purpose
• WP2 Framework is a modular, PHP-centric WordPress boilerplate that lives alongside a normal WordPress install.
• Its goal is to simplify building advanced, block-driven sites by auto-registering modules (blocks, models, integrations) based on file location.
High-Level Architecture
a. WordPress Core & Database
• Core PHP entry points, hooks, plugin API
• MySQL (or compatible) storing posts, metadata, options, custom tables
b. File-System Layers (all under wp-content/)
• MU-Plugins (“Daemons” loaded first):
– wp2-core: registers CPTs, taxonomies, statuses, patterns
– wp2-new: site cloning & auto-install routines
– wp2-studio: asset loading (CSS/JS), Twig support, block rendering controller
– wp2-run: WP-CLI integration, lifecycle commands, webhook services
– wp2-build: schema definitions, code generation, build helpers
• Standard Plugins:
– wp2s, wp2-factory, wp2-new (non-MU version), etc.
• Themes:
– wp2s theme with parts, templates, static assets
• Uploads: user media, documentation, optional modules
c. Modular Components (“Zones,” “Integrations,” “Libraries,” “Plugins”)
• Zones: pre-bundled collections of modules by purpose (e.g., wp2-directory), accelerate project setup
• Integrations: connectors to third-party APIs/SaaS (Cloudflare, Shopify, Marker.io)
• Libraries: shared utilities & assets (Floating-UI, Micromodal) under mu-plugins or theme
• Plugins: core WP2 functionality delivered MU-style or via regular plugin installs
Module Registration Flow
1. WP2 Daemons scan their own directories at init (init.php, init-helpers.php, init-flows.php)
2. Each module folder with block.json is auto-registered as a Gutenberg block (PHP index.php + assets)
3. Models folders register custom post types, taxonomies, and REST endpoints
4. Integrations register hooks/services to external APIs
5. Assets (CSS/JS) auto-enqueued via file naming conventions and WP2_NAMESPACE constants
6. Theme parts/templates are served by Twig or PHP for front-end rendering
Key Architectural Patterns
• File-System-Based Registration: directory structure drives registration logic (convention over configuration)
• MVC-Like Separation:
• Models: custom post types & taxonomies under /src/models
• Views: block.json + PHP/Twig templates under /src/blocks and theme parts
• Controllers: init-flows.php, init-helpers.php registering hooks & filters
• Dependency Injection via constants (WP2_NAMESPACE, WP2_PREFIX) for multi-tenant setups
• Zero-Setup Asset Pipeline: Blockstudio compiles SCSS/JS, auto-discovers build scripts
a. Frontend Layer
• WP2 Theme ← consumes blocks & parts ← Registered by WP2 Daemons
• Browser ← JS/CSS assets from wp2-studio via enqueue hooks
b. Backend Layer
• MU-Plugins (wp2-core, wp2-studio, etc.) ← initialize modules, register REST routes, CLI commands
• Standard WP2 Plugins ← optional extensions, integrate with core daemons
• WordPress Core ← hook system, database API
c. Data Layer
• MySQL Database ← stores core & module data (posts, custom tables, taxonomies)
d. External Services
• Integrations (Shopify, Cloudflare, etc.) ← WP2 modules call APIs, webhooks
• Blockstudio Build Process (local or CI) ← compiles assets, generates block.json
Essential Details to Capture
• Module load order (MU-Plugins → Plugins → Themes)
• Convention-driven registration (block.json + index.php + init scripts)
• Role of wp2-studio as orchestration layer
• Integration points: REST endpoints, CLI commands, webhooks
• Asset pipeline: Blockstudio build → enqueued CSS/JS