| @@ -26,9 +26,8 @@ | ||
| 26 | 26 | |
| 27 | 27 | use Templately\API\Tags; |
| 28 | 28 | use Templately\API\Items; |
| 29 | 29 | use Templately\API\Login; |
| 30 | -use Templately\API\Checkout; | |
| 31 | 30 | use Templately\API\SignUp; |
| 32 | 31 | use Templately\API\Profile; |
| 33 | 32 | use Templately\API\Import; |
| 34 | 33 | use Templately\API\MyClouds; |
| @@ -37,9 +36,8 @@ | ||
| 37 | 36 | use Templately\API\Dependencies; |
| 38 | 37 | use Templately\API\TemplateTypes; |
| 39 | 38 | use Templately\API\SavedTemplates; |
| 40 | 39 | use Templately\API\Sites; |
| 41 | -use Templately\API\Tour; | |
| 42 | 40 | use Templately\Core\Maintenance; |
| 43 | 41 | use Templately\Core\Migrator; |
| 44 | 42 | use Templately\Core\Platform\Gutenberg; |
| 45 | 43 | use Templately\Core\Platform\Elementor; |
| @@ -44,9 +42,9 @@ | ||
| 44 | 42 | use Templately\Core\Platform\Gutenberg; |
| 45 | 43 | use Templately\Core\Platform\Elementor; |
| 46 | 44 | |
| 47 | 45 | final class Plugin extends Base { |
| 48 | - public $version = '3.6.7'; | |
| 46 | + public $version = '3.5.2'; | |
| 49 | 47 | |
| 50 | 48 | public $admin; |
| 51 | 49 | public $settings; |
| 52 | 50 | /** |
| @@ -87,9 +85,10 @@ | ||
| 87 | 85 | |
| 88 | 86 | add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 89 | 87 | add_action( 'rest_api_init', [ $this, 'register_routes' ] ); |
| 90 | 88 | |
| 91 | - 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' ] ); | |
| 92 | 91 | |
| 93 | 92 | /** |
| 94 | 93 | * Initialize. |
| 95 | 94 | */ |
| @@ -191,9 +190,8 @@ | ||
| 191 | 190 | Items::get_instance(); |
| 192 | 191 | SavedTemplates::get_instance(); |
| 193 | 192 | |
| 194 | 193 | Login::get_instance(); |
| 195 | - Checkout::get_instance(); | |
| 196 | 194 | SignUp::get_instance(); |
| 197 | 195 | Import::get_instance(); |
| 198 | 196 | Profile::get_instance(); |
| 199 | 197 | MyClouds::get_instance(); |
| @@ -198,9 +196,8 @@ | ||
| 198 | 196 | Profile::get_instance(); |
| 199 | 197 | MyClouds::get_instance(); |
| 200 | 198 | WorkSpaces::get_instance(); |
| 201 | 199 | Sites::get_instance(); |
| 202 | - Tour::get_instance(); | |
| 203 | 200 | |
| 204 | 201 | APISettings::get_instance(); |
| 205 | 202 | // Note: DeveloperSettings::get_instance() is called in Developer::init_modules() when developer functionality is available and enabled |
| 206 | 203 | } |
| @@ -265,15 +262,10 @@ | ||
| 265 | 262 | load_plugin_textdomain( 'templately', false, dirname( TEMPLATELY_PLUGIN_BASENAME ) . '/languages' ); |
| 266 | 263 | } |
| 267 | 264 | |
| 268 | 265 | public function google_login_handler() { |
| 269 | - // Stop if not a templately google login request | |
| 270 | - if ( empty( $_GET['templately_google_login'] ) ) { | |
| 271 | - return; | |
| 272 | - } | |
| 266 | + $redirect_url = admin_url( 'admin.php?page=templately' ); | |
| 273 | 267 | |
| 274 | - $redirect_url = remove_query_arg( [ 'templately_google_login', 'api_key', 'error', 'state', 'redirect-to' ] ); | |
| 275 | - | |
| 276 | 268 | if ( ! empty( $_GET['error'] ) ) { |
| 277 | 269 | $error_message = sanitize_text_field( $_GET['error'] ); |
| 278 | 270 | } elseif ( ! empty( $_GET['api_key'] ) ) { |
| 279 | 271 | $request = new \WP_REST_Request( 'POST', '/templately/v1/login' ); |
| @@ -287,27 +279,12 @@ | ||
| 287 | 279 | $login->permission_check( $request ); |
| 288 | 280 | $response = $login->login(); |
| 289 | 281 | |
| 290 | 282 | if ( ! is_wp_error( $response ) && ! empty( $response['user'] ) ) { |
| 291 | - $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 | + | |
| 292 | 285 | 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 | - } | |
| 286 | + $redirect_url = add_query_arg( 'path', $redirect_path, $redirect_url ); | |
| 310 | 287 | } |
| 311 | 288 | |
| 312 | 289 | wp_safe_redirect( $redirect_url ); |
| 313 | 290 | exit; |
| @@ -318,10 +295,10 @@ | ||
| 318 | 295 | $error_message = __( 'Missing API Key.', 'templately' ); |
| 319 | 296 | } |
| 320 | 297 | |
| 321 | 298 | $redirect_url = add_query_arg( [ |
| 322 | - 'templately_error' => 'login_failed', | |
| 323 | - 'error_message' => urlencode( $error_message ), | |
| 299 | + 'path' => 'sign-in', | |
| 300 | + 'error_message' => $error_message, | |
| 324 | 301 | ], $redirect_url ); |
| 325 | 302 | |
| 326 | 303 | wp_safe_redirect( $redirect_url ); |
| 327 | 304 | exit; |