PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.2
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 +13 -80 3.7.43.5.2 View file →
@@ -17,11 +17,9 @@
17 17 use Templately\API\Conditions;
18 18 use Templately\API\ThemeBuilderApi;
19 19 use Templately\Builder\ThemeBuilder;
20 20 use Templately\Core\Importer\FullSiteImport;
21 -use Templately\Utils\AuthErrorCode;
22 21 use Templately\Utils\Base;
23 -use Templately\Utils\Database;
24 22 use Templately\Utils\Enqueue;
25 23
26 24 use Templately\Core\Admin;
27 25 use Templately\Core\Module;
@@ -28,11 +26,9 @@
28 26
29 27 use Templately\API\Tags;
30 28 use Templately\API\Items;
31 29 use Templately\API\Login;
32 -use Templately\API\Checkout;
33 30 use Templately\API\SignUp;
34 -use Templately\API\AiCredit;
35 31 use Templately\API\Profile;
36 32 use Templately\API\Import;
37 33 use Templately\API\MyClouds;
38 34 use Templately\API\WorkSpaces;
@@ -40,10 +36,8 @@
40 36 use Templately\API\Dependencies;
41 37 use Templately\API\TemplateTypes;
42 38 use Templately\API\SavedTemplates;
43 39 use Templately\API\Sites;
44 -use Templately\API\Tour;
45 -use Templately\Core\DeactivationSurvey;
46 40 use Templately\Core\Maintenance;
47 41 use Templately\Core\Migrator;
48 42 use Templately\Core\Platform\Gutenberg;
49 43 use Templately\Core\Platform\Elementor;
@@ -48,9 +42,9 @@
48 42 use Templately\Core\Platform\Gutenberg;
49 43 use Templately\Core\Platform\Elementor;
50 44
51 45 final class Plugin extends Base {
52 - public $version = '3.7.4';
46 + public $version = '3.5.2';
53 47
54 48 public $admin;
55 49 public $settings;
56 50 /**
@@ -79,9 +73,8 @@
79 73 $this->define_constants();
80 74 $this->set_locale();
81 75
82 76 Maintenance::init();
83 - DeactivationSurvey::init();
84 77
85 78 $this->assets = Enqueue::get_instance( TEMPLATELY_URL, TEMPLATELY_PATH, $this->version );
86 79 $this->admin = Admin::get_instance();
87 80 $this->settings = Settings::get_instance();
@@ -92,9 +85,10 @@
92 85
93 86 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
94 87 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
95 88
96 - add_action( 'init', [ $this, 'google_login_handler' ] );
89 + add_action( 'wp_ajax_templately_google_login', [ $this, 'google_login_handler' ] );
90 + add_action( 'wp_ajax_nopriv_templately_google_login', [ $this, 'google_login_handler' ] );
97 91
98 92 /**
99 93 * Initialize.
100 94 */
@@ -196,17 +190,14 @@
196 190 Items::get_instance();
197 191 SavedTemplates::get_instance();
198 192
199 193 Login::get_instance();
200 - Checkout::get_instance();
201 194 SignUp::get_instance();
202 195 Import::get_instance();
203 196 Profile::get_instance();
204 - AiCredit::get_instance();
205 197 MyClouds::get_instance();
206 198 WorkSpaces::get_instance();
207 199 Sites::get_instance();
208 - Tour::get_instance();
209 200
210 201 APISettings::get_instance();
211 202 // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled
212 203 }
@@ -271,51 +262,12 @@
271 262 load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' );
272 263 }
273 264
274 265 public function google_login_handler() {
275 - // Stop if not a templately google login request
276 - if ( empty( $_GET['templately_google_login'] ) ) {
277 - return;
278 - }
266 + $redirect_url = admin_url( 'admin.php?page=templately' );
279 267
280 - if ( wp_doing_ajax() || wp_doing_cron() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
281 - return;
282 - }
283 -
284 - // Checked before the token is consumed: the callback can land while the
285 - // auth cookie is missing (expired session, cookie not yet set), and WP
286 - // will bounce the user through wp-login and back to this same URL.
287 - // Burning the token here would fail that legitimate retry.
288 - if ( ! is_user_logged_in() ) {
289 - return;
290 - }
291 -
292 - $state = '';
293 - if ( ! empty( $_GET['templately_state'] ) ) {
294 - $state = sanitize_text_field( wp_unslash( $_GET['templately_state'] ) );
295 - } elseif ( ! empty( $_GET['state'] ) ) {
296 - $state = sanitize_text_field( wp_unslash( $_GET['state'] ) );
297 - }
298 -
299 - $state_user_id = false;
300 - if ( ! empty( $state ) ) {
301 - $state_user_id = Database::get_transient( 'google_state_' . $state );
302 - Database::delete_transient( 'google_state_' . $state );
303 - }
304 -
305 - $is_authorized = false !== $state_user_id
306 - && intval( $state_user_id ) === get_current_user_id()
307 - && current_user_can( 'delete_posts' );
308 -
309 - $redirect_url = remove_query_arg( [ 'templately_google_login', 'templately_state', 'api_key', 'error', 'state', 'redirect-to' ] );
310 -
311 - if ( ! $is_authorized ) {
312 - $error_code = AuthErrorCode::AUTH_STATE_INVALID;
313 - } elseif ( ! empty( $_GET['error'] ) ) {
314 - // Google's own reason is deliberately dropped rather than forwarded:
315 - // everything on this query string is attacker-controlled, and the
316 - // screen that displays it must never be handed prose from the URL.
317 - $error_code = AuthErrorCode::AUTH_PROVIDER_FAILED;
268 + if ( ! empty( $_GET['error'] ) ) {
269 + $error_message = sanitize_text_field( $_GET['error'] );
318 270 } elseif ( ! empty( $_GET['api_key'] ) ) {
319 271 $request = new \WP_REST_Request( 'POST', '/templately/v1/login' );
320 272 $request->set_param( 'viaAPI', true );
321 273 $request->set_param( 'api_key', sanitize_text_field( $_GET['api_key'] ) );
@@ -324,48 +276,29 @@
324 276 * @var Login $login
325 277 */
326 278 $login = Login::get_instance();
327 279 $login->permission_check( $request );
328 -
329 - // login() pins the write target to the acting user itself — no pin
330 - // here, or its finally would release ours mid-request.
331 280 $response = $login->login();
332 281
333 282 if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) {
334 - $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( wp_unslash( $_GET['redirect-to'] ) ) : '';
283 + $redirect_path = ! empty( $_GET['redirect-to'] ) ? sanitize_text_field( $_GET['redirect-to'] ) : '';
284 +
335 285 if ( ! empty( $redirect_path ) ) {
336 - if ( filter_var( $redirect_path, FILTER_VALIDATE_URL ) ) {
337 - $redirect_url = $redirect_path;
338 - } else {
339 - $is_templately = strpos( $redirect_url, 'page=templately' ) !== false;
340 - $is_elementor = strpos( $redirect_url, 'action=elementor' ) !== false;
341 - // Gutenberg editor usually has action=edit or is a block editor page
342 - $is_gutenberg = ( strpos( $redirect_url, 'action=edit' ) !== false || strpos( $redirect_url, 'post_type=' ) !== false ) && ! $is_elementor;
343 -
344 - if ( $is_templately || $is_elementor || $is_gutenberg ) {
345 - $redirect_url = add_query_arg( 'path', ltrim( $redirect_path, '/' ), $redirect_url );
346 -
347 - // Always open the modal in editors after google login
348 - if ( $is_elementor || $is_gutenberg ) {
349 - $redirect_url = add_query_arg( 'templately_open_modal', '1', $redirect_url );
350 - }
351 - }
352 - }
286 + $redirect_url = add_query_arg( 'path', $redirect_path, $redirect_url );
353 287 }
354 288
355 289 wp_safe_redirect( $redirect_url );
356 290 exit;
357 291 } else {
358 - // The cloud's own wording stays server-side; the screen resolves
359 - // its copy from the code.
360 - $error_code = AuthErrorCode::INVALID_API_KEY;
292 + $error_message = ( is_wp_error( $response ) ) ? $response->get_error_message() : __( 'Login failed.', 'templately' );
361 293 }
362 294 } else {
363 - $error_code = AuthErrorCode::AUTH_MISSING_API_KEY;
295 + $error_message = __( 'Missing API Key.', 'templately' );
364 296 }
365 297
366 298 $redirect_url = add_query_arg( [
367 - 'templately_error' => $error_code,
299 + 'path' => 'sign-in',
300 + 'error_message' => $error_message,
368 301 ], $redirect_url );
369 302
370 303 wp_safe_redirect( $redirect_url );
371 304 exit;