PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
← All changes | includes/Plugin.php +56 -165 3.6.13.8.0 View file →
@@ -9,46 +9,25 @@
9 9 */
10 10
11 11 namespace Templately;
12 12
13 -use Templately\Admin\API\Settings as APISettings;
14 -use Templately\Admin\Settings;
15 -use Templately\API\AIContent;
16 -use Templately\API\LogoGeneration;
17 -use Templately\API\Conditions;
18 -use Templately\API\ThemeBuilderApi;
19 -use Templately\Builder\ThemeBuilder;
20 -use Templately\Core\Importer\FullSiteImport;
21 13 use Templately\Utils\Base;
22 14 use Templately\Utils\Enqueue;
23 15
24 16 use Templately\Core\Admin;
25 -use Templately\Core\Module;
17 +use Templately\Core\Platform_Registry;
18 +use Templately\Core\Modules_Manager;
19 +use Templately\Core\Capability_Seed;
26 20
27 -use Templately\API\Tags;
28 -use Templately\API\Items;
29 -use Templately\API\Login;
30 -use Templately\API\SignUp;
31 -use Templately\API\Profile;
32 -use Templately\API\Import;
33 -use Templately\API\MyClouds;
34 -use Templately\API\WorkSpaces;
35 -use Templately\API\Categories;
36 -use Templately\API\Dependencies;
37 -use Templately\API\TemplateTypes;
38 -use Templately\API\SavedTemplates;
39 21 use Templately\API\Sites;
40 -use Templately\API\Tour;
41 22 use Templately\Core\Maintenance;
42 23 use Templately\Core\Migrator;
43 -use Templately\Core\Platform\Gutenberg;
44 -use Templately\Core\Platform\Elementor;
24 +use Templately\Utils\Response\RestEnvelope;
45 25
46 26 final class Plugin extends Base {
47 - public $version = '3.6.1';
27 + public $version = '3.8.0';
48 28
49 29 public $admin;
50 - public $settings;
51 30 /**
52 31 * Enqueue class responsible for assets
53 32 * @var Enqueue
54 33 */
@@ -54,18 +33,21 @@
54 33 */
55 34 public $assets;
56 35
57 36 /**
58 - * @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
59 46 */
60 47 public $theme_builder;
61 48
62 49 /**
63 - * @var Developer
64 - */
65 - public $developer;
66 -
67 - /**
68 50 * Plugin constructor.
69 51 * Initializing Templately plugin.
70 52 *
71 53 * @access private
@@ -77,19 +59,18 @@
77 59 Maintenance::init();
78 60
79 61 $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
80 62 $this->admin = Admin::get_instance();
81 - $this->settings = Settings::get_instance();
82 - $this->theme_builder = ThemeBuilder::get_instance();
83 63
84 - // Initialize developer functionality if available
85 - $this->init_developer_functionality();
86 -
87 64 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
88 65 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
89 66
90 - add_action( 'init', [ $this, 'google_login_handler' ] );
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();
91 71
72 +
92 73 /**
93 74 * Initialize.
94 75 */
95 76 do_action( 'templately_init' );
@@ -101,9 +82,9 @@
101 82 *
102 83 * @since 2.0
103 84 */
104 85 public function __clone() {
105 - _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' );
86 + _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'templately' ), '2.0' );
106 87 }
107 88
108 89 /**
109 90 * Un-serializing instances of this class is forbidden.
@@ -110,9 +91,9 @@
110 91 *
111 92 * @since 2.0
112 93 */
113 94 public function __wakeup() {
114 - _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' );
115 96 }
116 97
117 98 /**
118 99 * Initializing Things on Plugins Loaded
@@ -118,90 +99,54 @@
118 99 * Initializing Things on Plugins Loaded
119 100 * @return void
120 101 */
121 102 public function plugins_loaded() {
122 - $this->platforms(); // PLATFORMS LOADED
123 103 $this->apis(); // APIs LOADED
124 104
125 105 /**
126 - * 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.
127 109 */
128 - Migrator::get_instance();
110 + Capability_Seed::register_all();
129 111
130 112 /**
131 - * 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.
132 115 */
133 - FullSiteImport::get_instance();
116 + Modules_Manager::get_instance()->boot();
117 +
118 + /**
119 + * Migrator for Templately
120 + */
121 + Migrator::get_instance();
134 122 }
135 123
136 124 /**
137 - * Initialize developer functionality if available
125 + * All the API instantiated
138 126 *
139 - * This method safely loads developer functionality only if the developer
140 - * directory and class exist, preventing fatal errors in production builds.
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.
141 133 *
142 - * @return void
143 - */
144 - private function init_developer_functionality() {
145 - $developer_file = TEMPLATELY_PATH . 'includes/Core/Developer/Developer.php';
146 -
147 - // Check if developer file exists before attempting to load
148 - if ( file_exists( $developer_file ) ) {
149 - // Include the developer class file
150 - require_once $developer_file;
151 -
152 - // Check if the class exists after including the file
153 - if ( class_exists( '\\Templately\\Core\\Developer\\Developer' ) ) {
154 - $this->developer = \Templately\Core\Developer\Developer::get_instance();
155 - }
156 - }
157 -
158 - // If developer functionality is not available, set to null
159 - if ( ! isset( $this->developer ) ) {
160 - $this->developer = null;
161 - }
162 - }
163 -
164 -
165 -
166 - /**
167 - * Initialize all platforms
168 - * @return void
169 - */
170 - public function platforms() {
171 - Gutenberg::get_instance();
172 - Elementor::get_instance();
173 - }
174 -
175 - /**
176 - * All the API instantiated
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.
177 139 *
178 140 * @return void
179 141 */
180 142 private function apis() {
181 - Conditions::get_instance();
182 - Categories::get_instance();
183 - TemplateTypes::get_instance();
184 - Dependencies::get_instance();
185 - Tags::get_instance();
186 - ThemeBuilderApi::get_instance();
187 -
188 - AIContent::get_instance();
189 - LogoGeneration::get_instance();
190 - Items::get_instance();
191 - SavedTemplates::get_instance();
192 -
193 - Login::get_instance();
194 - SignUp::get_instance();
195 - Import::get_instance();
196 - Profile::get_instance();
197 - MyClouds::get_instance();
198 - WorkSpaces::get_instance();
199 143 Sites::get_instance();
200 - Tour::get_instance();
201 144
202 - APISettings::get_instance();
203 145 // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled
146 +
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().
204 149 }
205 150
206 151 /**
207 152 * Register all REST API endpoints
@@ -207,10 +152,17 @@
207 152 * Register all REST API endpoints
208 153 * @return void
209 154 */
210 155 public function register_routes() {
211 - if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) {
156 + if ( ! empty( $modules = Platform_Registry::get_instance()->get( 'API' ) ) ) {
212 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 + }
213 165 $module->object->register_routes();
214 166 }
215 167 }
216 168 }
@@ -262,66 +214,5 @@
262 214 public function load_textdomain() {
263 215 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
264 216 }
265 217
266 - public function google_login_handler() {
267 - // Stop if not a templately google login request
268 - if ( empty( $_GET['templately_google_login'] ) ) {
269 - return;
270 - }
271 -
272 - $redirect_url = remove_query_arg( [ 'templately_google_login', 'api_key', 'error', 'state', 'redirect-to' ] );
273 -
274 - if ( ! empty( $_GET['error'] ) ) {
275 - $error_message = sanitize_text_field( $_GET['error'] );
276 - } elseif ( ! empty( $_GET['api_key'] ) ) {
277 - $request = new \WP_REST_Request( 'POST', '/templately/v1/login' );
278 - $request->set_param( 'viaAPI', true );
279 - $request->set_param( 'api_key', sanitize_text_field( $_GET['api_key'] ) );
280 -
281 - /**
282 - * @var Login $login
283 - */
284 - $login = Login::get_instance();
285 - $login->permission_check( $request );
286 - $response = $login->login();
287 -
288 - if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) {
289 - $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( wp_unslash( $_GET['redirect-to'] ) ) : '';
290 - if ( ! empty( $redirect_path ) ) {
291 - if ( filter_var( $redirect_path, FILTER_VALIDATE_URL ) ) {
292 - $redirect_url = $redirect_path;
293 - } else {
294 - $is_templately = strpos( $redirect_url, 'page=templately' ) !== false;
295 - $is_elementor = strpos( $redirect_url, 'action=elementor' ) !== false;
296 - // Gutenberg editor usually has action=edit or is a block editor page
297 - $is_gutenberg = ( strpos( $redirect_url, 'action=edit' ) !== false || strpos( $redirect_url, 'post_type=' ) !== false ) && ! $is_elementor;
298 -
299 - if ( $is_templately || $is_elementor || $is_gutenberg ) {
300 - $redirect_url = add_query_arg( 'path', ltrim( $redirect_path, '/' ), $redirect_url );
301 -
302 - // Always open the modal in editors after google login
303 - if ( $is_elementor || $is_gutenberg ) {
304 - $redirect_url = add_query_arg( 'templately_open_modal', '1', $redirect_url );
305 - }
306 - }
307 - }
308 - }
309 -
310 - wp_safe_redirect( $redirect_url );
311 - exit;
312 - } else {
313 - $error_message = ( is_wp_error( $response ) ) ? $response->get_error_message() : __( 'Login failed.', 'templately' );
314 - }
315 - } else {
316 - $error_message = __( 'Missing API Key.', 'templately' );
317 - }
318 -
319 - $redirect_url = add_query_arg( [
320 - 'templately_error' => 'login_failed',
321 - 'error_message' => urlencode( $error_message ),
322 - ], $redirect_url );
323 -
324 - wp_safe_redirect( $redirect_url );
325 - exit;
326 - }
327 218 }