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