PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
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
templately / includes / Plugin.php

Plugin.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! trunk, at includes/Plugin.php

219 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Templately plugin.
4 *
5 * The main plugin handler class is responsible for initializing Templately. The
6 * class registers and all the components required to run the plugin.
7 *
8 * @package Templately
9 */
10
11 namespace Templately;
12
13 use Templately\Utils\Base;
14 use Templately\Utils\Enqueue;
15
16 use Templately\Core\Admin;
17 use Templately\Core\Platform_Registry;
18 use Templately\Core\Modules_Manager;
19 use Templately\Core\Capability_Seed;
20
21 use Templately\API\Sites;
22 use Templately\Core\Maintenance;
23 use Templately\Core\Migrator;
24 use Templately\Utils\Response\RestEnvelope;
25
26 final class Plugin extends Base {
27 public $version = '3.8.0';
28
29 public $admin;
30 /**
31 * Enqueue class responsible for assets
32 * @var Enqueue
33 */
34 public $assets;
35
36 /**
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
46 */
47 public $theme_builder;
48
49 /**
50 * Plugin constructor.
51 * Initializing Templately plugin.
52 *
53 * @access private
54 */
55 public function __construct() {
56 $this->define_constants();
57 $this->set_locale();
58
59 Maintenance::init();
60
61 $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
62 $this->admin = Admin::get_instance();
63
64 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
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 /**
74 * Initialize.
75 */
76 do_action( 'templately_init' );
77
78 }
79
80 /**
81 * Cloning is forbidden.
82 *
83 * @since 2.0
84 */
85 public function __clone() {
86 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'templately' ), '2.0' );
87 }
88
89 /**
90 * Un-serializing instances of this class is forbidden.
91 *
92 * @since 2.0
93 */
94 public function __wakeup() {
95 _doing_it_wrong( __FUNCTION__, esc_html__( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' );
96 }
97
98 /**
99 * Initializing Things on Plugins Loaded
100 * @return void
101 */
102 public function plugins_loaded() {
103 $this->apis(); // APIs LOADED
104
105 /**
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.
109 */
110 Capability_Seed::register_all();
111
112 /**
113 * Feature modules (spec 004): auto-discovered from modules/*, booted after the
114 * legacy API registration so a module may depend on it.
115 */
116 Modules_Manager::get_instance()->boot();
117
118 /**
119 * Migrator for Templately
120 */
121 Migrator::get_instance();
122 }
123
124 /**
125 * All the API instantiated
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 *
140 * @return void
141 */
142 private function apis() {
143 Sites::get_instance();
144
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().
149 }
150
151 /**
152 * Register all REST API endpoints
153 * @return void
154 */
155 public function register_routes() {
156 if ( ! empty( $modules = Platform_Registry::get_instance()->get( 'API' ) ) ) {
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 }
165 $module->object->register_routes();
166 }
167 }
168 }
169
170 /**
171 * Define CONSTANTS
172 *
173 * @return void
174 * @since 2.0.0
175 */
176 public function define_constants() {
177 $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) );
178 $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' );
179 $this->define( 'TEMPLATELY_PLUGIN_BASENAME', plugin_basename( TEMPLATELY_FILE ) );
180 $this->define( 'TEMPLATELY_VERSION', $this->version );
181 $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' );
182 $this->define( 'TEMPLATELY_VIEWS_ABSPATH', TEMPLATELY_PATH . 'views/' );
183 }
184
185 /**
186 * Define constant if not already set.
187 *
188 * @param string $name Constant name.
189 * @param mixed $value Constant value.
190 *
191 * @return void
192 */
193 private function define( string $name, $value ) {
194 if ( ! defined( $name ) ) {
195 define( $name, $value );
196 }
197 }
198
199 /**
200 * Setting the locale for translation availability
201 * @return void
202 * @since 1.0.0
203 */
204 public function set_locale() {
205 add_action( 'init', [ $this, 'load_textdomain' ] );
206 }
207
208 /**
209 * Loading Text Domain on init HOOK
210 * @return void
211 * @since 1.0.0
212 *
213 */
214 public function load_textdomain() {
215 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
216 }
217
218 }
219