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