PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.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/API/Login.php +18 -81 3.7.33.5.3 View file →
@@ -47,23 +47,21 @@
47 47 ];
48 48 }
49 49
50 50 public function pricing(){
51 - $data = get_transient( "templately_subscriptions_v2" );
51 + $data = get_transient( "templately_subscriptions" );
52 52
53 53 if( is_array( $data ) && ! empty( $data ) ) {
54 54 return $data;
55 55 }
56 56
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';
57 + $query = 'id, price, name, discounted_price, type, sites, coupon';
60 58 $response = $this->http()->query(
61 59 'subscriptionPlans',
62 60 $query
63 61 )->post();
64 62
65 - set_transient( "templately_subscriptions_v2", $response, WEEK_IN_SECONDS );
63 + set_transient( "templately_subscriptions", $response, WEEK_IN_SECONDS );
66 64
67 65 return $response;
68 66 }
69 67
@@ -107,13 +105,9 @@
107 105 if ( ! empty( $errors ) ) {
108 106 return $this->error( 'login_error', $errors, 'login', 400 );
109 107 }
110 108
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 } }';
109 + $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 110
117 111 $response = $this->http()->mutation(
118 112 $viaAPI ? 'connectWithApiKey' : 'connect',
119 113 $query,
@@ -127,30 +121,8 @@
127 121 if ( empty( $response['user']['api_key'] ) ) {
128 122 return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 );
129 123 }
130 124
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 125 if ( $global_signin && ! Login::is_globally_signed() ) {
154 126 Options::set_global_login();
155 127 }
156 128
@@ -202,28 +174,13 @@
202 174 return $response;
203 175 }
204 176
205 177 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 178 $response = $this->http()->mutation(
222 179 'disconnect',
223 180 'status, message, data',
224 181 [
225 - 'api_key' => $api_key,
182 + 'api_key' => $this->api_key,
226 183 "site_url" => home_url( '/' )
227 184 ]
228 185 )->post();
229 186
@@ -250,33 +207,22 @@
250 207 return $response;
251 208 }
252 209
253 210 public function delete(){
254 - $options = $this->utils( 'options' );
211 + $this->utils( 'options' )
212 + ->remove( 'user' )
213 + ->remove( 'favourites' )
214 + ->remove( 'reviews' )
215 + ->remove( 'cloud_activity' )
216 + ->remove( 'api_key' )
217 + ->remove( 'global_login' )
218 + ->remove( 'total_download_counts' )
219 + ->remove( 'templates_in_clouds' );
255 220
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 );
221 + if ( $this->utils( 'options' )->who_am_i() === 'global' ) {
222 + $this->utils( 'options' )->remove_global_login();
223 + }
260 224
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 225 $global_user_id = $this->utils( 'options' )->is_global();
280 226 $global_user = null;
281 227
282 228 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
@@ -282,12 +228,8 @@
282 228 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
283 229 $global_user = $this->utils( 'options' )->get( 'user', false, $global_user_id );
284 230
285 231 if ( ! empty( $global_user ) ) {
286 - if ( is_array( $global_user ) ) {
287 - unset( $global_user['api_key'] );
288 - }
289 -
290 232 $global_user['meta'] = $this->user_meta();
291 233 }
292 234 }
293 235
@@ -301,13 +243,8 @@
301 243
302 244 $_user = ( new static )->utils( 'options' )->get( 'user', null );
303 245
304 246 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 247 $_user['meta'] = self::get_instance()->user_meta();
311 248 }
312 249
313 250 if ( empty( $_user ) ) {
@@ -340,5 +277,5 @@
340 277
341 278 public static function signed_as_global(): bool {
342 279 return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() );
343 280 }
344 -}
281 +}