PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.3
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 3.1.10 All 111 releases
templately / includes / Plugin.php

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

257 lines 6.0 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\Admin\API\Settings as APISettings;
14 use Templately\Admin\Settings;
15 use Templately\API\AIContent;
16 use Templately\API\Conditions;
17 use Templately\API\ThemeBuilderApi;
18 use Templately\Builder\ThemeBuilder;
19 use Templately\Core\Importer\FullSiteImport;
20 use Templately\Utils\Base;
21 use Templately\Utils\Enqueue;
22
23 use Templately\Core\Admin;
24 use Templately\Core\Module;
25
26 use Templately\API\Tags;
27 use Templately\API\Items;
28 use Templately\API\Login;
29 use Templately\API\SignUp;
30 use Templately\API\Profile;
31 use Templately\API\Import;
32 use Templately\API\MyClouds;
33 use Templately\API\WorkSpaces;
34 use Templately\API\Categories;
35 use Templately\API\Dependencies;
36 use Templately\API\TemplateTypes;
37 use Templately\API\SavedTemplates;
38 use Templately\Core\Maintenance;
39 use Templately\Core\Migrator;
40 use Templately\Core\Platform\Gutenberg;
41 use Templately\Core\Platform\Elementor;
42
43 final class Plugin extends Base {
44 public $version = '3.4.3';
45
46 public $admin;
47 public $settings;
48 /**
49 * Enqueue class responsible for assets
50 * @var Enqueue
51 */
52 public $assets;
53
54 /**
55 * @var ThemeBuilder
56 */
57 public $theme_builder;
58
59 /**
60 * @var Developer
61 */
62 public $developer;
63
64 /**
65 * Plugin constructor.
66 * Initializing Templately plugin.
67 *
68 * @access private
69 */
70 public function __construct() {
71 $this->define_constants();
72 $this->set_locale();
73
74 Maintenance::init();
75
76 $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
77 $this->admin = Admin::get_instance();
78 $this->settings = Settings::get_instance();
79 $this->theme_builder = ThemeBuilder::get_instance();
80
81 // Initialize developer functionality if available
82 $this->init_developer_functionality();
83
84 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
85 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
86 /**
87 * Initialize.
88 */
89 do_action( 'templately_init' );
90
91 }
92
93 /**
94 * Cloning is forbidden.
95 *
96 * @since 2.0
97 */
98 public function __clone() {
99 _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' );
100 }
101
102 /**
103 * Un-serializing instances of this class is forbidden.
104 *
105 * @since 2.0
106 */
107 public function __wakeup() {
108 _doing_it_wrong( __FUNCTION__, __( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' );
109 }
110
111 /**
112 * Initializing Things on Plugins Loaded
113 * @return void
114 */
115 public function plugins_loaded() {
116 $this->platforms(); // PLATFORMS LOADED
117 $this->apis(); // APIs LOADED
118
119 /**
120 * Migrator for Templately
121 */
122 Migrator::get_instance();
123
124 /**
125 * Full Site Import
126 */
127 FullSiteImport::get_instance();
128 }
129
130 /**
131 * Initialize developer functionality if available
132 *
133 * This method safely loads developer functionality only if the developer
134 * directory and class exist, preventing fatal errors in production builds.
135 *
136 * @return void
137 */
138 private function init_developer_functionality() {
139 $developer_file = TEMPLATELY_PATH . 'includes/Core/Developer/Developer.php';
140
141 // Check if developer file exists before attempting to load
142 if ( file_exists( $developer_file ) ) {
143 // Include the developer class file
144 require_once $developer_file;
145
146 // Check if the class exists after including the file
147 if ( class_exists( '\\Templately\\Core\\Developer\\Developer' ) ) {
148 $this->developer = \Templately\Core\Developer\Developer::get_instance();
149 }
150 }
151
152 // If developer functionality is not available, set to null
153 if ( ! isset( $this->developer ) ) {
154 $this->developer = null;
155 }
156 }
157
158
159
160 /**
161 * Initialize all platforms
162 * @return void
163 */
164 public function platforms() {
165 Gutenberg::get_instance();
166 Elementor::get_instance();
167 }
168
169 /**
170 * All the API instantiated
171 *
172 * @return void
173 */
174 private function apis() {
175 Conditions::get_instance();
176 Categories::get_instance();
177 TemplateTypes::get_instance();
178 Dependencies::get_instance();
179 Tags::get_instance();
180 ThemeBuilderApi::get_instance();
181
182 AIContent::get_instance();
183 Items::get_instance();
184 SavedTemplates::get_instance();
185
186 Login::get_instance();
187 SignUp::get_instance();
188 Import::get_instance();
189 Profile::get_instance();
190 MyClouds::get_instance();
191 WorkSpaces::get_instance();
192
193 APISettings::get_instance();
194 // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled
195 }
196
197 /**
198 * Register all REST API endpoints
199 * @return void
200 */
201 public function register_routes() {
202 if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) {
203 foreach ( $modules as $module ) {
204 $module->object->register_routes();
205 }
206 }
207 }
208
209 /**
210 * Define CONSTANTS
211 *
212 * @return void
213 * @since 2.0.0
214 */
215 public function define_constants() {
216 $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) );
217 $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' );
218 $this->define( 'TEMPLATELY_PLUGIN_BASENAME', plugin_basename( TEMPLATELY_FILE ) );
219 $this->define( 'TEMPLATELY_VERSION', $this->version );
220 $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' );
221 $this->define( 'TEMPLATELY_VIEWS_ABSPATH', TEMPLATELY_PATH . 'views/' );
222 }
223
224 /**
225 * Define constant if not already set.
226 *
227 * @param string $name Constant name.
228 * @param mixed $value Constant value.
229 *
230 * @return void
231 */
232 private function define( string $name, $value ) {
233 if ( ! defined( $name ) ) {
234 define( $name, $value );
235 }
236 }
237
238 /**
239 * Setting the locale for translation availability
240 * @return void
241 * @since 1.0.0
242 */
243 public function set_locale() {
244 add_action( 'init', [ $this, 'load_textdomain' ] );
245 }
246
247 /**
248 * Loading Text Domain on init HOOK
249 * @return void
250 * @since 1.0.0
251 *
252 */
253 public function load_textdomain() {
254 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
255 }
256 }
257