PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.6.8
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.6.8
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 +14 -71 3.7.23.6.8 View file →
@@ -121,30 +121,8 @@
121 121 if ( empty( $response['user']['api_key'] ) ) {
122 122 return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 );
123 123 }
124 124
125 - $options = $this->utils( 'options' );
126 - $options->use_current_user( true );
127 -
128 - try {
129 - return $this->store_connection( $response, $global_signin, $_ip, $_site_url );
130 - } finally {
131 - $options->use_current_user( false );
132 - }
133 - }
134 -
135 - /**
136 - * Persist an authenticated connection against the acting user.
137 - *
138 - * @param array $response Cloud response, already validated.
139 - * @param bool $global_signin Whether the user asked to sign in globally.
140 - * @param string $_ip Request IP, echoed back into the profile.
141 - * @param string $_site_url Site URL, echoed back into the profile.
142 - *
143 - * @return array
144 - */
145 - private function store_connection( $response, $global_signin, $_ip, $_site_url ) {
146 -
147 125 if ( $global_signin && ! Login::is_globally_signed() ) {
148 126 Options::set_global_login();
149 127 }
150 128
@@ -196,28 +174,13 @@
196 174 return $response;
197 175 }
198 176
199 177 public function logout() {
200 - // Read the key off the acting user's own record. Options::get() falls back to
201 - // the global-login administrator when no target is given, so $this->api_key
202 - // resolves to the administrator's key for any linked user — disconnecting the
203 - // administrator's account on the cloud as well as locally.
204 - $api_key = $this->utils( 'options' )->get( 'api_key', '', get_current_user_id() );
205 -
206 - if ( empty( $api_key ) ) {
207 - return $this->error(
208 - 'logout_error',
209 - __( 'You are not connected to Templately.', 'templately' ),
210 - 'logout',
211 - 403
212 - );
213 - }
214 -
215 178 $response = $this->http()->mutation(
216 179 'disconnect',
217 180 'status, message, data',
218 181 [
219 - 'api_key' => $api_key,
182 + 'api_key' => $this->api_key,
220 183 "site_url" => home_url( '/' )
221 184 ]
222 185 )->post();
223 186
@@ -244,33 +207,22 @@
244 207 return $response;
245 208 }
246 209
247 210 public function delete(){
248 - $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' );
249 220
250 - // Pin the removals to the acting user. Without the pin, Options::user_id()
251 - // resolves a linked user to the global-login administrator and the delete
252 - // path wipes the administrator's connection instead of the caller's.
253 - $options->use_current_user( true );
221 + if ( $this->utils( 'options' )->who_am_i() === 'global' ) {
222 + $this->utils( 'options' )->remove_global_login();
223 + }
254 224
255 - try {
256 - $options
257 - ->remove( 'user' )
258 - ->remove( 'favourites' )
259 - ->remove( 'reviews' )
260 - ->remove( 'cloud_activity' )
261 - ->remove( 'api_key' )
262 - ->remove( 'global_login' )
263 - ->remove( 'total_download_counts' )
264 - ->remove( 'templates_in_clouds' );
265 -
266 - if ( $options->who_am_i() === 'global' ) {
267 - $options->remove_global_login();
268 - }
269 - } finally {
270 - $options->use_current_user( false );
271 - }
272 -
273 225 $global_user_id = $this->utils( 'options' )->is_global();
274 226 $global_user = null;
275 227
276 228 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
@@ -276,12 +228,8 @@
276 228 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
277 229 $global_user = $this->utils( 'options' )->get( 'user', false, $global_user_id );
278 230
279 231 if ( ! empty( $global_user ) ) {
280 - if ( is_array( $global_user ) ) {
281 - unset( $global_user['api_key'] );
282 - }
283 -
284 232 $global_user['meta'] = $this->user_meta();
285 233 }
286 234 }
287 235
@@ -295,13 +243,8 @@
295 243
296 244 $_user = ( new static )->utils( 'options' )->get( 'user', null );
297 245
298 246 if ( ! is_null( $_user ) ) {
299 - // Profiles stored before 3.7.1 may still carry the cloud API key.
300 - if ( is_array( $_user ) ) {
301 - unset( $_user['api_key'] );
302 - }
303 -
304 247 $_user['meta'] = self::get_instance()->user_meta();
305 248 }
306 249
307 250 if ( empty( $_user ) ) {
@@ -334,5 +277,5 @@
334 277
335 278 public static function signed_as_global(): bool {
336 279 return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() );
337 280 }
338 -}
281 +}