PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.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
← All changes | includes/Plugin.php +56 -237 3.7.22.2.3 View file →
@@ -6,22 +6,11 @@
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 -use Templately\Utils\AuthErrorCode;
22 12 use Templately\Utils\Base;
23 -use Templately\Utils\Database;
24 13 use Templately\Utils\Enqueue;
25 14
26 15 use Templately\Core\Admin;
27 16 use Templately\Core\Module;
@@ -28,9 +17,8 @@
28 17
29 18 use Templately\API\Tags;
30 19 use Templately\API\Items;
31 20 use Templately\API\Login;
32 -use Templately\API\Checkout;
33 21 use Templately\API\SignUp;
34 22 use Templately\API\Profile;
35 23 use Templately\API\Import;
36 24 use Templately\API\MyClouds;
@@ -38,10 +26,8 @@
38 26 use Templately\API\Categories;
39 27 use Templately\API\Dependencies;
40 28 use Templately\API\TemplateTypes;
41 29 use Templately\API\SavedTemplates;
42 -use Templately\API\Sites;
43 -use Templately\API\Tour;
44 30 use Templately\Core\Maintenance;
45 31 use Templately\Core\Migrator;
46 32 use Templately\Core\Platform\Gutenberg;
47 33 use Templately\Core\Platform\Elementor;
@@ -46,60 +32,39 @@
46 32 use Templately\Core\Platform\Gutenberg;
47 33 use Templately\Core\Platform\Elementor;
48 34
49 35 final class Plugin extends Base {
50 - public $version = '3.7.2';
36 + public $version = '2.2.3';
51 37
52 38 public $admin;
53 - public $settings;
54 - /**
55 - * Enqueue class responsible for assets
56 - * @var Enqueue
57 - */
58 - public $assets;
39 + /**
40 + * Enqueue class responsible for assets
41 + * @var Enqueue
42 + */
43 + public $assets;
44 + /**
45 + * Plugin constructor.
46 + * Initializing Templately plugin.
47 + *
48 + * @access private
49 + */
50 + public function __construct() {
51 + $this->define_constants();
52 + $this->set_locale();
59 53
60 - /**
61 - * @var ThemeBuilder
62 - */
63 - public $theme_builder;
64 -
65 - /**
66 - * @var Developer
67 - */
68 - public $developer;
69 -
70 - /**
71 - * Plugin constructor.
72 - * Initializing Templately plugin.
73 - *
74 - * @access private
75 - */
76 - public function __construct() {
77 - $this->define_constants();
78 - $this->set_locale();
79 -
80 54 Maintenance::init();
81 55
82 - $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
83 - $this->admin = Admin::get_instance();
84 - $this->settings = Settings::get_instance();
85 - $this->theme_builder = ThemeBuilder::get_instance();
56 + $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
57 + $this->admin = Admin::get_instance();
86 58
87 - // Initialize developer functionality if available
88 - $this->init_developer_functionality();
89 -
90 - add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
91 - add_action( 'rest_api_init', [ $this, 'register_routes' ] );
92 -
93 - add_action( 'init', [ $this, 'google_login_handler' ] );
94 -
59 + add_action( 'plugins_loaded', [$this, 'plugins_loaded'] );
60 + add_action( 'rest_api_init', [$this, 'register_routes'] );
95 61 /**
96 62 * Initialize.
97 63 */
98 - do_action( 'templately_init' );
64 + do_action( 'templately_init' );
65 + }
99 66
100 - }
101 -
102 67 /**
103 68 * Cloning is forbidden.
104 69 *
105 70 * @since 2.0
@@ -108,14 +73,14 @@
108 73 _doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'templately' ), '2.0' );
109 74 }
110 75
111 76 /**
112 - * Un-serializing instances of this class is forbidden.
77 + * Unserializing instances of this class is forbidden.
113 78 *
114 79 * @since 2.0
115 80 */
116 81 public function __wakeup() {
117 - _doing_it_wrong( __FUNCTION__, __( 'Un-serializing instances of this class is forbidden.', 'templately' ), '2.0' );
82 + _doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'templately' ), '2.0' );
118 83 }
119 84
120 85 /**
121 86 * Initializing Things on Plugins Loaded
@@ -120,9 +85,9 @@
120 85 /**
121 86 * Initializing Things on Plugins Loaded
122 87 * @return void
123 88 */
124 - public function plugins_loaded() {
89 + public function plugins_loaded(){
125 90 $this->platforms(); // PLATFORMS LOADED
126 91 $this->apis(); // APIs LOADED
127 92
128 93 /**
@@ -128,53 +93,18 @@
128 93 /**
129 94 * Migrator for Templately
130 95 */
131 96 Migrator::get_instance();
132 -
133 - /**
134 - * Full Site Import
135 - */
136 - FullSiteImport::get_instance();
137 97 }
138 98
139 99 /**
140 - * Initialize developer functionality if available
141 - *
142 - * This method safely loads developer functionality only if the developer
143 - * directory and class exist, preventing fatal errors in production builds.
144 - *
145 - * @return void
146 - */
147 - private function init_developer_functionality() {
148 - $developer_file = TEMPLATELY_PATH . 'includes/Core/Developer/Developer.php';
149 -
150 - // Check if developer file exists before attempting to load
151 - if ( file_exists( $developer_file ) ) {
152 - // Include the developer class file
153 - require_once $developer_file;
154 -
155 - // Check if the class exists after including the file
156 - if ( class_exists( '\\Templately\\Core\\Developer\\Developer' ) ) {
157 - $this->developer = \Templately\Core\Developer\Developer::get_instance();
158 - }
159 - }
160 -
161 - // If developer functionality is not available, set to null
162 - if ( ! isset( $this->developer ) ) {
163 - $this->developer = null;
164 - }
165 - }
166 -
167 -
168 -
169 - /**
170 100 * Initialize all platforms
171 101 * @return void
172 102 */
173 - public function platforms() {
174 - Gutenberg::get_instance();
175 - Elementor::get_instance();
176 - }
103 + public function platforms(){
104 + Gutenberg::get_instance();
105 + Elementor::get_instance();
106 + }
177 107
178 108 /**
179 109 * All the API instantiated
180 110 *
@@ -179,33 +109,23 @@
179 109 * All the API instantiated
180 110 *
181 111 * @return void
182 112 */
183 - private function apis() {
184 - Conditions::get_instance();
113 + private function apis(){
185 114 Categories::get_instance();
186 - TemplateTypes::get_instance();
187 - Dependencies::get_instance();
188 - Tags::get_instance();
189 - ThemeBuilderApi::get_instance();
115 + TemplateTypes::get_instance();
116 + Dependencies::get_instance();
117 + Tags::get_instance();
190 118
191 - AIContent::get_instance();
192 - LogoGeneration::get_instance();
193 - Items::get_instance();
194 - SavedTemplates::get_instance();
119 + Items::get_instance();
120 + SavedTemplates::get_instance();
195 121
196 - Login::get_instance();
197 - Checkout::get_instance();
198 - SignUp::get_instance();
199 - Import::get_instance();
200 - Profile::get_instance();
201 - MyClouds::get_instance();
202 - WorkSpaces::get_instance();
203 - Sites::get_instance();
204 - Tour::get_instance();
205 -
206 - APISettings::get_instance();
207 - // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled
122 + Login::get_instance();
123 + SignUp::get_instance();
124 + Import::get_instance();
125 + Profile::get_instance();
126 + MyClouds::get_instance();
127 + WorkSpaces::get_instance();
208 128 }
209 129
210 130 /**
211 131 * Register all REST API endpoints
@@ -210,40 +130,39 @@
210 130 /**
211 131 * Register all REST API endpoints
212 132 * @return void
213 133 */
214 - public function register_routes() {
215 - if ( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) {
216 - foreach ( $modules as $module ) {
134 + public function register_routes(){
135 + if( ! empty( $modules = Module::get_instance()->get( 'API' ) ) ) {
136 + foreach( $modules as $module ) {
217 137 $module->object->register_routes();
218 138 }
219 139 }
220 - }
140 + }
221 141
222 142 /**
223 143 * Define CONSTANTS
224 144 *
145 + * @since 2.0.0
225 146 * @return void
226 - * @since 2.0.0
227 147 */
228 - public function define_constants() {
229 - $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) );
230 - $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' );
148 + public function define_constants() {
149 + $this->define( 'TEMPLATELY_URL', plugin_dir_url( TEMPLATELY_FILE ) );
150 + $this->define( 'TEMPLATELY_ASSETS', TEMPLATELY_URL . 'assets/' );
231 151 $this->define( 'TEMPLATELY_PLUGIN_BASENAME', plugin_basename( TEMPLATELY_FILE ) );
232 152 $this->define( 'TEMPLATELY_VERSION', $this->version );
233 - $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' );
234 - $this->define( 'TEMPLATELY_VIEWS_ABSPATH', TEMPLATELY_PATH . 'views/' );
235 - }
153 + $this->define( 'TEMPLATELY_API_NAMESPACE', 'templately/v1' );
154 + }
236 155
237 156 /**
238 157 * Define constant if not already set.
239 158 *
240 - * @param string $name Constant name.
159 + * @param string $name Constant name.
241 160 * @param mixed $value Constant value.
242 161 *
243 162 * @return void
244 163 */
245 - private function define( string $name, $value ) {
164 + private function define( $name, $value ) {
246 165 if ( ! defined( $name ) ) {
247 166 define( $name, $value );
248 167 }
249 168 }
@@ -249,121 +168,21 @@
249 168 }
250 169
251 170 /**
252 171 * Setting the locale for translation availability
172 + * @since 1.0.0
253 173 * @return void
254 - * @since 1.0.0
255 174 */
256 - public function set_locale() {
175 + public function set_locale(){
257 176 add_action( 'init', [ $this, 'load_textdomain' ] );
258 177 }
259 178
260 179 /**
261 180 * Loading Text Domain on init HOOK
262 - * @return void
263 181 * @since 1.0.0
264 182 *
183 + * @return void
265 184 */
266 - public function load_textdomain() {
185 + public function load_textdomain(){
267 186 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
268 - }
269 -
270 - public function google_login_handler() {
271 - // Stop if not a templately google login request
272 - if ( empty( $_GET['templately_google_login'] ) ) {
273 - return;
274 - }
275 -
276 - if ( wp_doing_ajax() || wp_doing_cron() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
277 - return;
278 - }
279 -
280 - // Checked before the token is consumed: the callback can land while the
281 - // auth cookie is missing (expired session, cookie not yet set), and WP
282 - // will bounce the user through wp-login and back to this same URL.
283 - // Burning the token here would fail that legitimate retry.
284 - if ( ! is_user_logged_in() ) {
285 - return;
286 - }
287 -
288 - $state = '';
289 - if ( ! empty( $_GET['templately_state'] ) ) {
290 - $state = sanitize_text_field( wp_unslash( $_GET['templately_state'] ) );
291 - } elseif ( ! empty( $_GET['state'] ) ) {
292 - $state = sanitize_text_field( wp_unslash( $_GET['state'] ) );
293 - }
294 -
295 - $state_user_id = false;
296 - if ( ! empty( $state ) ) {
297 - $state_user_id = Database::get_transient( 'google_state_' . $state );
298 - Database::delete_transient( 'google_state_' . $state );
299 - }
300 -
301 - $is_authorized = false !== $state_user_id
302 - && intval( $state_user_id ) === get_current_user_id()
303 - && current_user_can( 'delete_posts' );
304 -
305 - $redirect_url = remove_query_arg( [ 'templately_google_login', 'templately_state', 'api_key', 'error', 'state', 'redirect-to' ] );
306 -
307 - if ( ! $is_authorized ) {
308 - $error_code = AuthErrorCode::AUTH_STATE_INVALID;
309 - } elseif ( ! empty( $_GET['error'] ) ) {
310 - // Google's own reason is deliberately dropped rather than forwarded:
311 - // everything on this query string is attacker-controlled, and the
312 - // screen that displays it must never be handed prose from the URL.
313 - $error_code = AuthErrorCode::AUTH_PROVIDER_FAILED;
314 - } elseif ( ! empty( $_GET['api_key'] ) ) {
315 - $request = new \WP_REST_Request( 'POST', '/templately/v1/login' );
316 - $request->set_param( 'viaAPI', true );
317 - $request->set_param( 'api_key', sanitize_text_field( $_GET['api_key'] ) );
318 -
319 - /**
320 - * @var Login $login
321 - */
322 - $login = Login::get_instance();
323 - $login->permission_check( $request );
324 -
325 - // login() pins the write target to the acting user itself — no pin
326 - // here, or its finally would release ours mid-request.
327 - $response = $login->login();
328 -
329 - if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) {
330 - $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( wp_unslash( $_GET['redirect-to'] ) ) : '';
331 - if ( ! empty( $redirect_path ) ) {
332 - if ( filter_var( $redirect_path, FILTER_VALIDATE_URL ) ) {
333 - $redirect_url = $redirect_path;
334 - } else {
335 - $is_templately = strpos( $redirect_url, 'page=templately' ) !== false;
336 - $is_elementor = strpos( $redirect_url, 'action=elementor' ) !== false;
337 - // Gutenberg editor usually has action=edit or is a block editor page
338 - $is_gutenberg = ( strpos( $redirect_url, 'action=edit' ) !== false || strpos( $redirect_url, 'post_type=' ) !== false ) && ! $is_elementor;
339 -
340 - if ( $is_templately || $is_elementor || $is_gutenberg ) {
341 - $redirect_url = add_query_arg( 'path', ltrim( $redirect_path, '/' ), $redirect_url );
342 -
343 - // Always open the modal in editors after google login
344 - if ( $is_elementor || $is_gutenberg ) {
345 - $redirect_url = add_query_arg( 'templately_open_modal', '1', $redirect_url );
346 - }
347 - }
348 - }
349 - }
350 -
351 - wp_safe_redirect( $redirect_url );
352 - exit;
353 - } else {
354 - // The cloud's own wording stays server-side; the screen resolves
355 - // its copy from the code.
356 - $error_code = AuthErrorCode::INVALID_API_KEY;
357 - }
358 - } else {
359 - $error_code = AuthErrorCode::AUTH_MISSING_API_KEY;
360 - }
361 -
362 - $redirect_url = add_query_arg( [
363 - 'templately_error' => $error_code,
364 - ], $redirect_url );
365 -
366 - wp_safe_redirect( $redirect_url );
367 - exit;
368 187 }
369 188 }