| @@ -9,37 +9,23 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace Templately; |
| 12 | 12 | |
| 13 | -use Templately\API\Conditions; | |
| 14 | -use Templately\API\ThemeBuilderApi; | |
| 15 | -use Templately\Builder\ThemeBuilder; | |
| 16 | -use Templately\Core\Importer\FullSiteImport; | |
| 17 | 13 | use Templately\Utils\Base; |
| 18 | 14 | use Templately\Utils\Enqueue; |
| 19 | 15 | |
| 20 | 16 | use Templately\Core\Admin; |
| 21 | -use Templately\Core\Module; | |
| 17 | +use Templately\Core\Platform_Registry; | |
| 18 | +use Templately\Core\Modules_Manager; | |
| 19 | +use Templately\Core\Capability_Seed; | |
| 22 | 20 | |
| 23 | -use Templately\API\Tags; | |
| 24 | -use Templately\API\Items; | |
| 25 | -use Templately\API\Login; | |
| 26 | -use Templately\API\SignUp; | |
| 27 | -use Templately\API\Profile; | |
| 28 | -use Templately\API\Import; | |
| 29 | -use Templately\API\MyClouds; | |
| 30 | -use Templately\API\WorkSpaces; | |
| 31 | -use Templately\API\Categories; | |
| 32 | -use Templately\API\Dependencies; | |
| 33 | -use Templately\API\TemplateTypes; | |
| 34 | -use Templately\API\SavedTemplates; | |
| 21 | +use Templately\API\Sites; | |
| 35 | 22 | use Templately\Core\Maintenance; |
| 36 | 23 | use Templately\Core\Migrator; |
| 37 | -use Templately\Core\Platform\Gutenberg; | |
| 38 | -use Templately\Core\Platform\Elementor; | |
| 24 | +use Templately\Utils\Response\RestEnvelope; | |
| 39 | 25 | |
| 40 | 26 | final class Plugin extends Base { |
| 41 | - public $version = '3.1.0'; | |
| 27 | + public $version = '3.8.0'; | |
| 42 | 28 | |
| 43 | 29 | public $admin; |
| 44 | 30 | /** |
| 45 | 31 | * Enqueue class responsible for assets |
| @@ -47,9 +33,17 @@ | ||
| 47 | 33 | */ |
| 48 | 34 | public $assets; |
| 49 | 35 | |
| 50 | 36 | /** |
| 51 | - * @var ThemeBuilder | |
| 37 | + * Set by modules/theme-builder/module.php's init_hooks() (during | |
| 38 | + * Modules_Manager::boot(), inside plugins_loaded()) — NOT here in the | |
| 39 | + * constructor. ThemeBuilder is now a module-namespaced class | |
| 40 | + * (Templately\Modules\ThemeBuilder\ThemeBuilder); eagerly instantiating it | |
| 41 | + * in the constructor (which runs before plugins_loaded even fires) would | |
| 42 | + * fatal on class-not-found, since Modules_Manager hasn't registered that | |
| 43 | + * module's autoloader yet. | |
| 44 | + * | |
| 45 | + * @var \Templately\Modules\ThemeBuilder\ThemeBuilder | |
| 52 | 46 | */ |
| 53 | 47 | public $theme_builder; |
| 54 | 48 | |
| 55 | 49 | /** |
| @@ -65,16 +59,23 @@ | ||
| 65 | 59 | Maintenance::init(); |
| 66 | 60 | |
| 67 | 61 | $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version ); |
| 68 | 62 | $this->admin = Admin::get_instance(); |
| 69 | - $this->theme_builder = ThemeBuilder::get_instance(); | |
| 70 | 63 | |
| 71 | 64 | add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 72 | 65 | add_action( 'rest_api_init', [ $this, 'register_routes' ] ); |
| 66 | + | |
| 67 | + // 043 — the single response envelope, applied on rest_post_dispatch so | |
| 68 | + // every route in the namespace is covered by construction rather than by | |
| 69 | + // each endpoint remembering to opt in. | |
| 70 | + RestEnvelope::init(); | |
| 71 | + | |
| 72 | + | |
| 73 | 73 | /** |
| 74 | 74 | * Initialize. |
| 75 | 75 | */ |
| 76 | 76 | do_action( 'templately_init' ); |
| 77 | + | |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | /** |
| 80 | 81 | * Cloning is forbidden. |
| @@ -81,9 +82,9 @@ | ||
| 81 | 82 | * |
| 82 | 83 | * @since 2.0 |
| 83 | 84 | */ |
| 84 | 85 | public function __clone() { |
| 85 | - _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' ); | |
| 86 | + _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'templately' ), '2.0' ); | |
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | /** |
| 89 | 90 | * Un-serializing instances of this class is forbidden. |
| @@ -90,9 +91,9 @@ | ||
| 90 | 91 | * |
| 91 | 92 | * @since 2.0 |
| 92 | 93 | */ |
| 93 | 94 | public function __wakeup() { |
| 94 | - _doing_it_wrong( __FUNCTION__, __( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' ); | |
| 95 | + _doing_it_wrong( __FUNCTION__, esc_html__( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' ); | |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | /** |
| 98 | 99 | * Initializing Things on Plugins Loaded |
| @@ -98,53 +99,54 @@ | ||
| 98 | 99 | * Initializing Things on Plugins Loaded |
| 99 | 100 | * @return void |
| 100 | 101 | */ |
| 101 | 102 | public function plugins_loaded() { |
| 102 | - $this->platforms(); // PLATFORMS LOADED | |
| 103 | 103 | $this->apis(); // APIs LOADED |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Migrator for Templately | |
| 106 | + * Host capability registry (spec 053): the seed set MUST exist before any | |
| 107 | + * module boots so is_active()/sub-feature gates can consult it. Registration | |
| 108 | + * is metadata-only — no probe runs here. | |
| 107 | 109 | */ |
| 108 | - Migrator::get_instance(); | |
| 110 | + Capability_Seed::register_all(); | |
| 109 | 111 | |
| 110 | 112 | /** |
| 111 | - * Full Site Import | |
| 113 | + * Feature modules (spec 004): auto-discovered from modules/*, booted after the | |
| 114 | + * legacy API registration so a module may depend on it. | |
| 112 | 115 | */ |
| 113 | - FullSiteImport::get_instance(); | |
| 114 | - } | |
| 116 | + Modules_Manager::get_instance()->boot(); | |
| 115 | 117 | |
| 116 | - /** | |
| 117 | - * Initialize all platforms | |
| 118 | - * @return void | |
| 119 | - */ | |
| 120 | - public function platforms() { | |
| 121 | - Gutenberg::get_instance(); | |
| 122 | - Elementor::get_instance(); | |
| 118 | + /** | |
| 119 | + * Migrator for Templately | |
| 120 | + */ | |
| 121 | + Migrator::get_instance(); | |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | 124 | /** |
| 126 | 125 | * All the API instantiated |
| 127 | 126 | * |
| 127 | + * Every other legacy API endpoint (ThemeBuilderApi, Tour, Conditions, ...) | |
| 128 | + * migrated to its own module's register_rest_routes(), booted lazily on | |
| 129 | + * rest_api_init (Phase 2 extraction, specs 013-037 — see | |
| 130 | + * docs/modularization-prd.md). Sites is the one REST endpoint with no | |
| 131 | + * owning feature spec (site-connection migration is cross-cutting | |
| 132 | + * infrastructure, not a bounded feature) — it stays here as core. | |
| 133 | + * | |
| 134 | + * Both Elementor and Gutenberg platform drivers are now self-registered by | |
| 135 | + * their own module's init_hooks() (modules/elementor-integration/module.php, | |
| 136 | + * modules/gutenberg-integration/module.php) — the former platforms() method | |
| 137 | + * that used to run before this one is gone; there is nothing left to boot | |
| 138 | + * before Modules_Manager::boot() runs. | |
| 139 | + * | |
| 128 | 140 | * @return void |
| 129 | 141 | */ |
| 130 | 142 | private function apis() { |
| 131 | - Conditions::get_instance(); | |
| 132 | - Categories::get_instance(); | |
| 133 | - TemplateTypes::get_instance(); | |
| 134 | - Dependencies::get_instance(); | |
| 135 | - Tags::get_instance(); | |
| 136 | - ThemeBuilderApi::get_instance(); | |
| 143 | + Sites::get_instance(); | |
| 137 | 144 | |
| 138 | - Items::get_instance(); | |
| 139 | - SavedTemplates::get_instance(); | |
| 145 | + // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled | |
| 140 | 146 | |
| 141 | - Login::get_instance(); | |
| 142 | - SignUp::get_instance(); | |
| 143 | - Import::get_instance(); | |
| 144 | - Profile::get_instance(); | |
| 145 | - MyClouds::get_instance(); | |
| 146 | - WorkSpaces::get_instance(); | |
| 147 | + // MCP Abilities (specs/041-mcp-abilities) now boots via modules/mcp-abilities/ | |
| 148 | + // module.php (Modules_Manager auto-discovery, spec 004) — see Plugin::plugins_loaded(). | |
| 147 | 149 | } |
| 148 | 150 | |
| 149 | 151 | /** |
| 150 | 152 | * Register all REST API endpoints |
| @@ -150,10 +152,17 @@ | ||
| 150 | 152 | * Register all REST API endpoints |
| 151 | 153 | * @return void |
| 152 | 154 | */ |
| 153 | 155 | public function register_routes() { |
| 154 | - if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) { | |
| 156 | + if ( ! empty( $modules = Platform_Registry::get_instance()->get( 'API' ) ) ) { | |
| 155 | 157 | foreach ( $modules as $module ) { |
| 158 | + // Module-owned endpoints (Templately\Modules\*) register explicitly via | |
| 159 | + // Modules_Manager::boot_rest_routes (constitution §VIII). They can still | |
| 160 | + // land in this legacy registry through the shared API base constructor if | |
| 161 | + // something instantiates them early — skip them so routes register once. | |
| 162 | + if ( 0 === strpos( get_class( $module->object ), 'Templately\\Modules\\' ) ) { | |
| 163 | + continue; | |
| 164 | + } | |
| 156 | 165 | $module->object->register_routes(); |
| 157 | 166 | } |
| 158 | 167 | } |
| 159 | 168 | } |
| @@ -204,5 +213,6 @@ | ||
| 204 | 213 | */ |
| 205 | 214 | public function load_textdomain() { |
| 206 | 215 | load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' ); |
| 207 | 216 | } |
| 217 | + | |
| 208 | 218 | } |