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/API/Login.php +19 -85 3.7.33.5.2 View file →
@@ -36,12 +36,9 @@
36 36 public function google_auth_url() {
37 37 // Get redirect_to parameter from request if provided
38 38 $redirect_to = $this->get_param( 'redirect-to', '' );
39 39
40 - // Use client-provided current_url instead of HTTP_REFERER for reliability
41 - $current_url = $this->get_param( 'current_url', '' );
42 -
43 - $url = $this->http()->google_auth_url( $redirect_to, $current_url );
40 + $url = $this->http()->google_auth_url( $redirect_to );
44 41 return [
45 42 'status' => 'success',
46 43 'url' => $url
47 44 ];
@@ -47,23 +44,21 @@
47 44 ];
48 45 }
49 46
50 47 public function pricing(){
51 - $data = get_transient( "templately_subscriptions_v2" );
48 + $data = get_transient( "templately_subscriptions" );
52 49
53 50 if( is_array( $data ) && ! empty( $data ) ) {
54 51 return $data;
55 52 }
56 53
57 - // Field set drives the Subscription screen's plan comparison grid, so it
58 - // carries the per-plan limits too, not just price/sites.
59 - $query = 'id, price, name, slug, discounted_price, type, sites, coupon, my_cloud_items, pro_items, workspace, fsi_limit, ai_credit, description';
54 + $query = 'id, price, name, discounted_price, type, sites, coupon';
60 55 $response = $this->http()->query(
61 56 'subscriptionPlans',
62 57 $query
63 58 )->post();
64 59
65 - set_transient( "templately_subscriptions_v2", $response, WEEK_IN_SECONDS );
60 + set_transient( "templately_subscriptions", $response, WEEK_IN_SECONDS );
66 61
67 62 return $response;
68 63 }
69 64
@@ -107,13 +102,9 @@
107 102 if ( ! empty( $errors ) ) {
108 103 return $this->error( 'login_error', $errors, 'login', 400 );
109 104 }
110 105
111 - // `ends_at`, `plan_type` and `cancel_at_period_end` drive the Subscription
112 - // screen's renewal line. They are asked for instead of leaning on
113 - // `plan_expire_at`, which the API resolves with `empty($subscription->ends_at)
114 - // ?? …` — a boolean that never falls through, so it never carries a date.
115 - $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, is_company_user, is_restricted_company_user, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating }, subscription { id, name, sites, subscription_plan_id, ends_at, plan_type, cancel_at_period_end } }';
106 + $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, is_company_user, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating }, subscription { id, name, sites } }';
116 107
117 108 $response = $this->http()->mutation(
118 109 $viaAPI ? 'connectWithApiKey' : 'connect',
119 110 $query,
@@ -127,30 +118,8 @@
127 118 if ( empty( $response['user']['api_key'] ) ) {
128 119 return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 );
129 120 }
130 121
131 - $options = $this->utils( 'options' );
132 - $options->use_current_user( true );
133 -
134 - try {
135 - return $this->store_connection( $response, $global_signin, $_ip, $_site_url );
136 - } finally {
137 - $options->use_current_user( false );
138 - }
139 - }
140 -
141 - /**
142 - * Persist an authenticated connection against the acting user.
143 - *
144 - * @param array $response Cloud response, already validated.
145 - * @param bool $global_signin Whether the user asked to sign in globally.
146 - * @param string $_ip Request IP, echoed back into the profile.
147 - * @param string $_site_url Site URL, echoed back into the profile.
148 - *
149 - * @return array
150 - */
151 - private function store_connection( $response, $global_signin, $_ip, $_site_url ) {
152 -
153 122 if ( $global_signin && ! Login::is_globally_signed() ) {
154 123 Options::set_global_login();
155 124 }
156 125
@@ -202,28 +171,13 @@
202 171 return $response;
203 172 }
204 173
205 174 public function logout() {
206 - // Read the key off the acting user's own record. Options::get() falls back to
207 - // the global-login administrator when no target is given, so $this->api_key
208 - // resolves to the administrator's key for any linked user — disconnecting the
209 - // administrator's account on the cloud as well as locally.
210 - $api_key = $this->utils( 'options' )->get( 'api_key', '', get_current_user_id() );
211 -
212 - if ( empty( $api_key ) ) {
213 - return $this->error(
214 - 'logout_error',
215 - __( 'You are not connected to Templately.', 'templately' ),
216 - 'logout',
217 - 403
218 - );
219 - }
220 -
221 175 $response = $this->http()->mutation(
222 176 'disconnect',
223 177 'status, message, data',
224 178 [
225 - 'api_key' => $api_key,
179 + 'api_key' => $this->api_key,
226 180 "site_url" => home_url( '/' )
227 181 ]
228 182 )->post();
229 183
@@ -250,33 +204,22 @@
250 204 return $response;
251 205 }
252 206
253 207 public function delete(){
254 - $options = $this->utils( 'options' );
208 + $this->utils( 'options' )
209 + ->remove( 'user' )
210 + ->remove( 'favourites' )
211 + ->remove( 'reviews' )
212 + ->remove( 'cloud_activity' )
213 + ->remove( 'api_key' )
214 + ->remove( 'global_login' )
215 + ->remove( 'total_download_counts' )
216 + ->remove( 'templates_in_clouds' );
255 217
256 - // Pin the removals to the acting user. Without the pin, Options::user_id()
257 - // resolves a linked user to the global-login administrator and the delete
258 - // path wipes the administrator's connection instead of the caller's.
259 - $options->use_current_user( true );
218 + if ( $this->utils( 'options' )->who_am_i() === 'global' ) {
219 + $this->utils( 'options' )->remove_global_login();
220 + }
260 221
261 - try {
262 - $options
263 - ->remove( 'user' )
264 - ->remove( 'favourites' )
265 - ->remove( 'reviews' )
266 - ->remove( 'cloud_activity' )
267 - ->remove( 'api_key' )
268 - ->remove( 'global_login' )
269 - ->remove( 'total_download_counts' )
270 - ->remove( 'templates_in_clouds' );
271 -
272 - if ( $options->who_am_i() === 'global' ) {
273 - $options->remove_global_login();
274 - }
275 - } finally {
276 - $options->use_current_user( false );
277 - }
278 -
279 222 $global_user_id = $this->utils( 'options' )->is_global();
280 223 $global_user = null;
281 224
282 225 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
@@ -282,12 +225,8 @@
282 225 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
283 226 $global_user = $this->utils( 'options' )->get( 'user', false, $global_user_id );
284 227
285 228 if ( ! empty( $global_user ) ) {
286 - if ( is_array( $global_user ) ) {
287 - unset( $global_user['api_key'] );
288 - }
289 -
290 229 $global_user['meta'] = $this->user_meta();
291 230 }
292 231 }
293 232
@@ -301,13 +240,8 @@
301 240
302 241 $_user = ( new static )->utils( 'options' )->get( 'user', null );
303 242
304 243 if ( ! is_null( $_user ) ) {
305 - // Profiles stored before 3.7.1 may still carry the cloud API key.
306 - if ( is_array( $_user ) ) {
307 - unset( $_user['api_key'] );
308 - }
309 -
310 244 $_user['meta'] = self::get_instance()->user_meta();
311 245 }
312 246
313 247 if ( empty( $_user ) ) {
@@ -340,5 +274,5 @@
340 274
341 275 public static function signed_as_global(): bool {
342 276 return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() );
343 277 }
344 -}
278 +}