Instagram Widget by WPZOOM - Version 1.6.4

Version Description

  • Minor bug fixes for PHP 7.4
Download this release

Release Info

Developer WPZOOM
Plugin Icon 128x128 Instagram Widget by WPZOOM
Version 1.6.4
Comparing to
See all releases

Code changes from version 1.5.0 to 1.6.4

class-wpzoom-instagram-widget-api.php CHANGED
@@ -42,10 +42,17 @@ class Wpzoom_Instagram_Widget_API {
42
  }
43
 
44
  protected function __construct() {
45
- $options = get_option( 'wpzoom-instagram-widget-settings' );
46
- $this->access_token = $options['access-token'];
 
 
 
 
 
 
 
 
47
  $this->username = !empty($options['username']) ? $options['username'] : '';
48
- $this->request_type = !empty($options['request_type']) ? $options['request_type'] : '';
49
  $this->transient_lifetime_type = !empty($options['transient-lifetime-type']) ? $options['transient-lifetime-type'] : 'days';
50
  $this->transient_lifetime_value = !empty($options['transient-lifetime-value']) ? $options['transient-lifetime-value'] : 1;
51
  $this->is_embed_stream = ! empty( $options['is-embed-stream'] ) ? wp_validate_boolean( $options['is-embed-stream'] ) : false;
@@ -178,6 +185,29 @@ class Wpzoom_Instagram_Widget_API {
178
 
179
  }
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  function get_response_without_token_from_json( $user ) {
182
 
183
  $user = trim( $user );
@@ -259,6 +289,52 @@ class Wpzoom_Instagram_Widget_API {
259
  return $result;
260
  }
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  function get_items_without_token( $user ) {
263
 
264
  $result = $this->get_response_without_token( $user );
@@ -350,10 +426,10 @@ class Wpzoom_Instagram_Widget_API {
350
 
351
  $injected_username = trim( $injected_username );
352
 
353
- if ( ! empty( $injected_username ) ) {
354
- $injected_username = str_replace( '@', '', $injected_username );
355
- $transient = $transient . '_' . $injected_username;
356
- }
357
 
358
  if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
359
 
@@ -364,51 +440,48 @@ class Wpzoom_Instagram_Widget_API {
364
  $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
365
 
366
 
367
- if ( ! empty( $this->access_token ) ) {
368
- $api_image_limit = 30;
369
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/self/media/recent/?access_token=%s&count=%s', $this->access_token, $api_image_limit ), $this->headers );
370
 
371
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
372
- set_transient( $transient, false, MINUTE_IN_SECONDS );
373
 
374
- $error_data = $this->get_error('items-with-token-invalid-response');
375
- $this->errors->add($error_data['code'], $error_data['message']);
 
 
 
 
 
376
 
377
- return false;
378
- }
379
-
380
- $data = json_decode( wp_remote_retrieve_body( $response ) );
381
 
382
- $token_username = ! empty( $data->data[0]->user->username ) ? $data->data[0]->user->username : '';
 
383
 
 
 
384
 
385
- if ( ! empty( $token_username ) && ! empty( $is_external_username ) ) {
 
386
 
387
- if ( $external_username !== $token_username ) {
388
 
389
- $data = $this->get_items_without_token( $external_username );
390
-
391
- if ( is_wp_error( $data ) ) {
392
- set_transient( $transient, false, MINUTE_IN_SECONDS );
393
-
394
- return false;
395
- }
396
- }
397
- }
398
- }
399
 
400
- if ( empty( $this->access_token ) && ! empty( $is_external_username ) ) {
401
 
402
 
403
- $data = $this->get_items_without_token( $external_username );
404
 
405
- if ( is_wp_error( $data ) ) {
406
- set_transient( $transient, false, MINUTE_IN_SECONDS );
407
 
408
- return false;
409
- }
410
 
411
- }
412
 
413
  if ( ! empty( $data->data ) ) {
414
  set_transient( $transient, $data, $this->get_transient_lifetime() );
@@ -469,10 +542,10 @@ class Wpzoom_Instagram_Widget_API {
469
 
470
  $injected_username = rtrim( $injected_username );
471
 
472
- if ( ! empty( $injected_username ) ) {
473
- $injected_username = str_replace( '@', '', $injected_username );
474
- $transient = $transient . '_' . $injected_username;
475
- }
476
 
477
  if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
478
 
@@ -482,50 +555,48 @@ class Wpzoom_Instagram_Widget_API {
482
  $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
483
  $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
484
 
485
- if ( ! empty( $this->access_token ) ) {
486
-
487
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $this->access_token ), $this->headers );
488
 
489
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
490
- set_transient( $transient, false, MINUTE_IN_SECONDS );
491
 
492
- $error_data = $this->get_error('user-with-token-invalid-response');
493
- $this->errors->add($error_data['code'], $error_data['message']);
 
 
 
 
 
494
 
495
- return false;
496
- }
497
 
498
- $data = json_decode( wp_remote_retrieve_body( $response ) );
 
499
 
500
- $token_username = ! empty( $data->data->username ) ? $data->data->username : '';
 
501
 
502
- if ( ! empty( $token_username ) && ! empty( $is_external_username ) ) {
 
503
 
504
- if ( $external_username !== $token_username ) {
505
 
506
- $data = $this->get_user_info_without_token( $external_username );
 
 
507
 
508
- if ( is_wp_error( $data ) ) {
509
- set_transient( $transient, false, MINUTE_IN_SECONDS );
510
 
511
- return false;
512
- }
513
- }
514
- }
515
 
516
- }
517
 
518
- if ( empty( $this->access_token ) && ! empty( $is_external_username ) ) {
 
519
 
520
- $data = $this->get_user_info_without_token( $external_username );
 
521
 
522
- if ( is_wp_error( $data ) ) {
523
- set_transient( $transient, false, MINUTE_IN_SECONDS );
524
-
525
- return false;
526
- }
527
-
528
- }
529
 
530
  if ( ! empty( $data->data ) ) {
531
  set_transient( $transient, $data, $this->get_transient_lifetime() );
@@ -623,24 +694,39 @@ class Wpzoom_Instagram_Widget_API {
623
  return $embed_url;
624
  }
625
 
626
- /**
627
- * Check if given access token is valid for Instagram Api.
628
- */
629
- public static function is_access_token_valid( $access_token ) {
630
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $access_token ) );
631
 
632
- if ( is_wp_error( $response ) ) {
633
- return $response;
634
- }
635
 
636
- if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
637
- return false;
638
- }
639
 
640
- return true;
641
- }
 
 
 
 
 
642
 
643
- public function is_configured() {
 
 
 
 
 
 
 
 
 
 
 
 
 
644
  $transient = 'zoom_instagram_is_configured';
645
 
646
  if ( false !== ( $result = get_transient( $transient ) ) ) {
@@ -651,10 +737,14 @@ class Wpzoom_Instagram_Widget_API {
651
  if ( 'no' === $result ) {
652
  return false;
653
  }
 
 
 
 
654
  }
655
 
656
  if(empty($this->username)){
657
- $condition = $this->is_access_token_valid( $this->access_token );
658
 
659
  } else{
660
  $condition = true;
42
  }
43
 
44
  protected function __construct() {
45
+ $options = get_option( 'wpzoom-instagram-widget-settings' , wpzoom_instagram_get_default_settings());
46
+
47
+ $this->request_type = !empty($options['request-type']) ? $options['request-type'] : '';
48
+ $this->access_token = $options['access-token'];
49
+
50
+ if('with-basic-access-token' === $this->request_type){
51
+ $this->access_token = $options['basic-access-token'];
52
+ }
53
+
54
+
55
  $this->username = !empty($options['username']) ? $options['username'] : '';
 
56
  $this->transient_lifetime_type = !empty($options['transient-lifetime-type']) ? $options['transient-lifetime-type'] : 'days';
57
  $this->transient_lifetime_value = !empty($options['transient-lifetime-value']) ? $options['transient-lifetime-value'] : 1;
58
  $this->is_embed_stream = ! empty( $options['is-embed-stream'] ) ? wp_validate_boolean( $options['is-embed-stream'] ) : false;
185
 
186
  }
187
 
188
+ function convert_user_info_to_old_structure( $user_info ) {
189
+
190
+ $converted = new stdClass;
191
+
192
+ $converted->data = (object) array(
193
+ 'bio' => null,
194
+ 'counts' => (object) array(
195
+ 'followed_by' => null,
196
+ 'follows' => null,
197
+ 'media' => null,
198
+ ),
199
+ 'full_name' => ! empty( $user_info->username ) ? $user_info->username : '',
200
+ 'id' => ! empty( $user_info->id ) ? $user_info->id : '',
201
+ 'is_business' => null,
202
+ 'profile_picture' => null,
203
+ 'username' => ! empty( $user_info->username ) ? $user_info->username : '',
204
+ 'website' => null
205
+ );
206
+
207
+ return $converted;
208
+
209
+ }
210
+
211
  function get_response_without_token_from_json( $user ) {
212
 
213
  $user = trim( $user );
289
  return $result;
290
  }
291
 
292
+ function convert_items_to_old_structure( $data ) {
293
+ $converted = new stdClass;
294
+ $converted->data = array();
295
+
296
+ foreach ( $data->data as $key => $item ) {
297
+
298
+ $converted->data[] = (object) array(
299
+ 'id' => $item->id,
300
+ 'user' => (object) array(
301
+ 'id' => null,
302
+ 'fullname' => null,
303
+ 'profile_picture' => null,
304
+ 'username' => $item->username
305
+ ),
306
+ 'images' => (object) array(
307
+ 'thumbnail' => (object) array(
308
+ 'url' => $this->convert_to_embed_url( 'thumbnail', $item->permalink ),
309
+ 'width' => 150,
310
+ 'height' => 150
311
+ ),
312
+ 'low_resolution' => (object) array(
313
+ 'url' => $this->convert_to_embed_url( 'low_resolution', $item->permalink ),
314
+ 'width' => 320,
315
+ 'height' => 320
316
+ ),
317
+ 'standard_resolution' => (object) array(
318
+ 'url' => $this->convert_to_embed_url( 'standard_resolution', $item->permalink ),
319
+ 'width' => 640,
320
+ 'height' => 640
321
+ ),
322
+ ),
323
+ 'type' => ($item->media_type === 'IMAGE' || $item->media_type === 'CAROUSEL_ALBUM') ? 'image' : 'video',
324
+ 'likes' => null,
325
+ 'comments' => null,
326
+ 'created_time' => null,
327
+ 'link' => $item->permalink,
328
+ 'caption' => (object) array(
329
+ 'text' => isset( $item->caption ) ? $item->caption : ''
330
+ )
331
+ );
332
+
333
+ }
334
+
335
+ return $converted;
336
+ }
337
+
338
  function get_items_without_token( $user ) {
339
 
340
  $result = $this->get_response_without_token( $user );
426
 
427
  $injected_username = trim( $injected_username );
428
 
429
+ if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
430
+ $injected_username = str_replace( '@', '', $injected_username );
431
+ $transient = $transient . '_' . $injected_username;
432
+ }
433
 
434
  if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
435
 
440
  $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
441
 
442
 
443
+ if ( ! empty( $this->access_token ) ) {
 
 
444
 
445
+ $request_url = sprintf( 'https://api.instagram.com/v1/users/self/media/recent/?access_token=%s&count=%s', $this->access_token, 30 );
 
446
 
447
+ if ( 'with-basic-access-token' === $this->request_type ) {
448
+ $request_url = add_query_arg( [
449
+ 'fields' => 'media_url,media_type,caption,username,permalink,thumbnail_url',
450
+ 'access_token' => $this->access_token
451
+ ],
452
+ 'https://graph.instagram.com/me/media' );
453
+ }
454
 
455
+ $response = wp_remote_get( $request_url, $this->headers );
 
 
 
456
 
457
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
458
+ set_transient( $transient, false, MINUTE_IN_SECONDS );
459
 
460
+ $error_data = $this->get_error( 'items-with-token-invalid-response' );
461
+ $this->errors->add( $error_data['code'], $error_data['message'] );
462
 
463
+ return false;
464
+ }
465
 
466
+ $data = json_decode( wp_remote_retrieve_body( $response ) );
467
 
468
+ if ( 'with-basic-access-token' === $this->request_type ) {
469
+ $data = $this->convert_items_to_old_structure( $data );
470
+ }
471
+ }
 
 
 
 
 
 
472
 
473
+ if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
474
 
475
 
476
+ $data = $this->get_items_without_token( $external_username );
477
 
478
+ if ( is_wp_error( $data ) ) {
479
+ set_transient( $transient, false, MINUTE_IN_SECONDS );
480
 
481
+ return false;
482
+ }
483
 
484
+ }
485
 
486
  if ( ! empty( $data->data ) ) {
487
  set_transient( $transient, $data, $this->get_transient_lifetime() );
542
 
543
  $injected_username = rtrim( $injected_username );
544
 
545
+ if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
546
+ $injected_username = str_replace( '@', '', $injected_username );
547
+ $transient = $transient . '_' . $injected_username;
548
+ }
549
 
550
  if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
551
 
555
  $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
556
  $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
557
 
558
+ if ( ! empty( $this->access_token ) ) {
 
 
559
 
560
+ $request_url = sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $this->access_token );
 
561
 
562
+ if ( 'with-basic-access-token' === $this->request_type ) {
563
+ $request_url = add_query_arg( [
564
+ 'access_token' => $this->access_token,
565
+ 'fields' => 'account_type,id,media_count,username'
566
+ ],
567
+ 'https://graph.instagram.com/me' );
568
+ }
569
 
570
+ $response = wp_remote_get( $request_url, $this->headers );
 
571
 
572
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
573
+ set_transient( $transient, false, MINUTE_IN_SECONDS );
574
 
575
+ $error_data = $this->get_error( 'user-with-token-invalid-response' );
576
+ $this->errors->add( $error_data['code'], $error_data['message'] );
577
 
578
+ return false;
579
+ }
580
 
581
+ $data = json_decode( wp_remote_retrieve_body( $response ) );
582
 
583
+ if ( 'with-basic-access-token' === $this->request_type ) {
584
+ $data = $this->convert_user_info_to_old_structure( $data );
585
+ }
586
 
587
+ }
 
588
 
589
+ if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
 
 
 
590
 
591
+ $data = $this->get_user_info_without_token( $external_username );
592
 
593
+ if ( is_wp_error( $data ) ) {
594
+ set_transient( $transient, false, MINUTE_IN_SECONDS );
595
 
596
+ return false;
597
+ }
598
 
599
+ }
 
 
 
 
 
 
600
 
601
  if ( ! empty( $data->data ) ) {
602
  set_transient( $transient, $data, $this->get_transient_lifetime() );
694
  return $embed_url;
695
  }
696
 
697
+ /**
698
+ * Check if given access token is valid for Instagram Api.
699
+ */
700
+ public static function is_access_token_valid( $access_token, $request_type = '' ) {
 
701
 
702
+ $request_url = sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $access_token );
 
 
703
 
704
+ if ( empty( $access_token ) ) {
705
+ return false;
706
+ }
707
 
708
+ if ( 'with-basic-access-token' === $request_type ) {
709
+ $request_url = add_query_arg( [
710
+ 'fields' => 'username',
711
+ 'access_token' => $access_token
712
+
713
+ ], 'https://graph.instagram.com/me' );
714
+ }
715
 
716
+ $response = wp_remote_get( $request_url );
717
+
718
+ if ( is_wp_error( $response ) ) {
719
+ return $response;
720
+ }
721
+
722
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
723
+ return false;
724
+ }
725
+
726
+ return true;
727
+ }
728
+
729
+ public function is_configured() {
730
  $transient = 'zoom_instagram_is_configured';
731
 
732
  if ( false !== ( $result = get_transient( $transient ) ) ) {
737
  if ( 'no' === $result ) {
738
  return false;
739
  }
740
+
741
+ if ( ! empty( $result ) ) {
742
+ return true;
743
+ }
744
  }
745
 
746
  if(empty($this->username)){
747
+ $condition = $this->is_access_token_valid( $this->access_token, $this->request_type );
748
 
749
  } else{
750
  $condition = true;
class-wpzoom-instagram-widget-settings.php CHANGED
@@ -59,6 +59,10 @@ class Wpzoom_Instagram_Widget_Settings {
59
  array('class' => 'wpzoom-instagram-widget-with-token-group')
60
  );
61
 
 
 
 
 
62
  add_settings_field(
63
  'wpzoom-instagram-widget-access-token-button',
64
  __( '', 'wpzoom-instagram-widget' ),
@@ -79,6 +83,29 @@ class Wpzoom_Instagram_Widget_Settings {
79
 
80
  );
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  add_settings_field(
83
  'wpzoom-instagram-widget-username-description',
84
  __( '', 'wpzoom-instagram-widget' ),
@@ -134,29 +161,59 @@ class Wpzoom_Instagram_Widget_Settings {
134
 
135
  }
136
 
137
- public function settings_field_access_token_button() {
138
- $oauth_url = 'https://instagram.com/oauth/authorize/?client_id=955bdb2319484968b93de8d6a1032c66&response_type=token&redirect_uri=https://www.wpzoom.com/instagram/';
139
- $oauth_url .= '?auth_site=' . esc_url( admin_url( 'options-general.php?page=wpzoom-instagram-widget' ) );
140
- $oauth_url.='&hl=en';
141
- ?>
 
 
142
 
143
  <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
144
 
145
  <br />
146
 
147
  <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
148
- <?php if ( ! Wpzoom_Instagram_Widget_API::getInstance()->is_configured() ) : ?>
149
  <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
150
- <?php else: ?>
151
  <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
152
- <?php endif; ?>
153
  </a>
154
  </p>
155
- <?php
156
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  public function settings_field_transient_lifetime() {
159
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
160
  $lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
161
  $lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
162
  ?>
@@ -178,7 +235,7 @@ class Wpzoom_Instagram_Widget_Settings {
178
  }
179
 
180
  public function settings_field_is_embed_stream() {
181
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
182
  $is_embed_stream = ! empty( $settings['is-embed-stream'] ) ? wp_validate_boolean($settings['is-embed-stream']) : false;
183
  ?>
184
  <input class="regular-text code"
@@ -192,7 +249,7 @@ class Wpzoom_Instagram_Widget_Settings {
192
  }
193
 
194
  public function settings_field_is_forced_timeout() {
195
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
196
  $is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean($settings['is-forced-timeout']) : false;
197
  ?>
198
  <input class="regular-text code"
@@ -206,7 +263,7 @@ class Wpzoom_Instagram_Widget_Settings {
206
  }
207
 
208
  public function settings_field_request_timeout() {
209
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
210
  $timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
211
  ?>
212
  <input class="regular-text code"
@@ -220,9 +277,11 @@ class Wpzoom_Instagram_Widget_Settings {
220
  }
221
 
222
  public function settings_field_access_token_input() {
223
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
224
- ?>
225
- <input class="regular-text code" id="wpzoom-instagram-widget-settings_access-token" name="wpzoom-instagram-widget-settings[access-token]" value="<?php echo esc_attr( $settings['access-token'] ) ?>" type="text">
 
 
226
  <p class="description">
227
  <?php
228
  printf(
@@ -237,6 +296,25 @@ class Wpzoom_Instagram_Widget_Settings {
237
  <?php
238
  }
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  public function settings_field_username_description() {
241
  ?>
242
  <p class="description"><?php _e( 'Using this method, a public feed, limited to <strong>12 photos</strong>, will be displayed in the widget.<br/>This option is useful if you want to display the feed of an Instagram account which you don\'t own or you have troubles getting your Access Token.', 'wpzoom-instagram-widget' ); ?></p>
@@ -246,7 +324,7 @@ class Wpzoom_Instagram_Widget_Settings {
246
  }
247
 
248
  public function settings_field_username() {
249
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
250
  ?>
251
  <input class="regular-text code" id="wpzoom-instagram-widget-settings_username" name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ) ?>" type="text">
252
  <p class="description">
@@ -263,18 +341,44 @@ class Wpzoom_Instagram_Widget_Settings {
263
  }
264
 
265
  public function settings_field_request_type() {
266
- $settings = get_option( 'wpzoom-instagram-widget-settings' );
267
  $request_type = empty( $settings['request-type'] ) ? 'with-access-token' : $settings['request-type'];
268
  ?>
269
 
270
  <div class="wpzoom-instagram-widget-settings-request-type-wrapper">
271
- <p><label for="wpzoom-instagram-widget-settings_with-access-token"><input class="code" id="wpzoom-instagram-widget-settings_with-access-token"
272
- name="wpzoom-instagram-widget-settings[request-type]"
273
- value="with-access-token" <?php checked( $request_type, 'with-access-token' ) ?> type="radio"> <?php _e('With Access Token', 'wpzoom-instagram-widget')?>&nbsp;&nbsp;</label>
274
- <label for="wpzoom-instagram-widget-settings_without-access-token"><input class="code" id="wpzoom-instagram-widget-settings_without-access-token"
275
- name="wpzoom-instagram-widget-settings[request-type]" value="without-access-token"
276
- <?php checked( $request_type, 'without-access-token' ) ?>type="radio"><?php _e('Public Feed (12 photos)', 'wpzoom-instagram-widget')?></label>
277
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  </div>
279
 
280
  <?php
@@ -325,8 +429,8 @@ class Wpzoom_Instagram_Widget_Settings {
325
  return;
326
  }
327
 
328
- wp_enqueue_style( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/admin-instagram-widget.css', array(), '1.4.2' );
329
- wp_enqueue_script( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/admin-instagram-widget.js', array( 'jquery' ), '1.4.2' );
330
  wp_localize_script( 'zoom-instagram-widget-admin', 'zoom_instagram_widget_admin', array(
331
  'i18n_connect_confirm' => __( "Instagram Widget is already connected to Instagram.\r\n\r\nDo you want to connect again?", 'wpzoom-instagram-widget' ),
332
  ) );
@@ -336,12 +440,14 @@ class Wpzoom_Instagram_Widget_Settings {
336
  $result = array();
337
 
338
  $result['access-token'] = sanitize_text_field( $input['access-token'] );
 
 
339
 
340
- if ( ! empty( $result['access-token'] ) ) {
341
- $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['access-token'] );
342
 
343
  if ( $validation_result !== true ) {
344
- $access_token_error_message = __( 'Provided Access Token has been rejected by Instagram API. Please try again or use the other option.', 'wpzoom-instagram-widget' );
345
 
346
  if ( is_wp_error( $validation_result ) ) {
347
  $access_token_error_message = $validation_result->get_error_message();
@@ -360,8 +466,30 @@ class Wpzoom_Instagram_Widget_Settings {
360
  }
361
  }
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  $result['username'] = sanitize_text_field( $input['username'] );
364
- $result['request-type'] = sanitize_text_field( $input['request-type'] );
365
  $result['transient-lifetime-value'] = sanitize_text_field( $input['transient-lifetime-value'] );
366
  $result['transient-lifetime-type'] = sanitize_text_field( $input['transient-lifetime-type'] );
367
  $result['is-embed-stream']= ! empty( $input['is-embed-stream'] ) ? wp_validate_boolean($input['is-embed-stream']) : false;
59
  array('class' => 'wpzoom-instagram-widget-with-token-group')
60
  );
61
 
62
+
63
+ /**
64
+ * Instagram with old token.
65
+ */
66
  add_settings_field(
67
  'wpzoom-instagram-widget-access-token-button',
68
  __( '', 'wpzoom-instagram-widget' ),
83
 
84
  );
85
 
86
+ /**
87
+ * Instagram with basic api token.
88
+ */
89
+ add_settings_field(
90
+ 'wpzoom-instagram-widget-basic-access-token-button',
91
+ __( '', 'wpzoom-instagram-widget' ),
92
+ array( $this, 'settings_field_basic_access_token_button' ),
93
+ 'wpzoom-instagram-widget-settings-group',
94
+ 'wpzoom-instagram-widget-settings-general',
95
+ array('class' => 'wpzoom-instagram-widget-with-basic-access-token-group')
96
+
97
+ );
98
+
99
+ add_settings_field(
100
+ 'wpzoom-instagram-widget-basic-access-token-input',
101
+ __( 'Access Token', 'wpzoom-instagram-widget' ),
102
+ array( $this, 'settings_field_basic_access_token_input' ),
103
+ 'wpzoom-instagram-widget-settings-group',
104
+ 'wpzoom-instagram-widget-settings-general',
105
+ array('class' => 'wpzoom-instagram-widget-with-basic-access-token-group')
106
+
107
+ );
108
+
109
  add_settings_field(
110
  'wpzoom-instagram-widget-username-description',
111
  __( '', 'wpzoom-instagram-widget' ),
161
 
162
  }
163
 
164
+ public function settings_field_access_token_button() {
165
+ $oauth_url = 'https://instagram.com/oauth/authorize/?client_id=955bdb2319484968b93de8d6a1032c66&response_type=token&redirect_uri=https://www.wpzoom.com/instagram/';
166
+ $oauth_url .= '?auth_site=' . esc_url( admin_url( 'options-general.php?page=wpzoom-instagram-widget' ) );
167
+ $oauth_url.='&hl=en';
168
+
169
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
170
+ ?>
171
 
172
  <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
173
 
174
  <br />
175
 
176
  <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
177
+ <?php if ( empty( $settings['access-token'] ) ) : ?>
178
  <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
179
+ <?php else: ?>
180
  <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
181
+ <?php endif; ?>
182
  </a>
183
  </p>
184
+ <?php
185
+ }
186
+
187
+ public function settings_field_basic_access_token_button() {
188
+
189
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
190
+
191
+ $oauth_url = add_query_arg( [
192
+ 'client_id' => '1242932982579434',
193
+ 'redirect_uri' => 'https://wpzoom.com/instagram-auth/',
194
+ 'scope' => 'user_profile,user_media',
195
+ 'response_type' => 'code',
196
+ ], 'https://api.instagram.com/oauth/authorize' );
197
+ $oauth_url.='&state='. base64_encode( urlencode(admin_url( 'options-general.php?page=wpzoom-instagram-widget' )) );
198
+ ?>
199
+
200
+ <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
201
+
202
+ <br />
203
+
204
+ <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
205
+ <?php if ( empty( $settings['basic-access-token'] ) ) : ?>
206
+ <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
207
+ <?php else: ?>
208
+ <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
209
+ <?php endif; ?>
210
+ </a>
211
+ </p>
212
+ <?php
213
+ }
214
 
215
  public function settings_field_transient_lifetime() {
216
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
217
  $lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
218
  $lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
219
  ?>
235
  }
236
 
237
  public function settings_field_is_embed_stream() {
238
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
239
  $is_embed_stream = ! empty( $settings['is-embed-stream'] ) ? wp_validate_boolean($settings['is-embed-stream']) : false;
240
  ?>
241
  <input class="regular-text code"
249
  }
250
 
251
  public function settings_field_is_forced_timeout() {
252
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
253
  $is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean($settings['is-forced-timeout']) : false;
254
  ?>
255
  <input class="regular-text code"
263
  }
264
 
265
  public function settings_field_request_timeout() {
266
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
267
  $timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
268
  ?>
269
  <input class="regular-text code"
277
  }
278
 
279
  public function settings_field_access_token_input() {
280
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
281
+ $access_token = ! empty( $settings['access-token'] ) ? $settings['access-token'] : '';
282
+
283
+ ?>
284
+ <input class="regular-text code" id="wpzoom-instagram-widget-settings_access-token" name="wpzoom-instagram-widget-settings[access-token]" value="<?php echo esc_attr( $access_token ) ?>" type="text">
285
  <p class="description">
286
  <?php
287
  printf(
296
  <?php
297
  }
298
 
299
+ public function settings_field_basic_access_token_input() {
300
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
301
+ $basic_access_token = ! empty( $settings['basic-access-token'] ) ? $settings['basic-access-token'] : '';
302
+ ?>
303
+ <input class="regular-text code" id="wpzoom-instagram-widget-settings_basic-access-token" name="wpzoom-instagram-widget-settings[basic-access-token]" value="<?php echo esc_attr( $basic_access_token ) ?>" type="text">
304
+ <p class="description">
305
+ <?php
306
+ printf(
307
+ __(
308
+ 'The Instagram Access Token is a long string of characters unique to your account that grants other applications access to your Instagram feed. You can also get it manually from <a href="%1$s">here</a>.',
309
+ 'wpzoom-instagram-widget'
310
+ ),
311
+ 'https://www.wpzoom.com/instagram-auth/'
312
+ );
313
+ ?>
314
+ </p>
315
+ <?php
316
+ }
317
+
318
  public function settings_field_username_description() {
319
  ?>
320
  <p class="description"><?php _e( 'Using this method, a public feed, limited to <strong>12 photos</strong>, will be displayed in the widget.<br/>This option is useful if you want to display the feed of an Instagram account which you don\'t own or you have troubles getting your Access Token.', 'wpzoom-instagram-widget' ); ?></p>
324
  }
325
 
326
  public function settings_field_username() {
327
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
328
  ?>
329
  <input class="regular-text code" id="wpzoom-instagram-widget-settings_username" name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ) ?>" type="text">
330
  <p class="description">
341
  }
342
 
343
  public function settings_field_request_type() {
344
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
345
  $request_type = empty( $settings['request-type'] ) ? 'with-access-token' : $settings['request-type'];
346
  ?>
347
 
348
  <div class="wpzoom-instagram-widget-settings-request-type-wrapper">
349
+
350
+ <div class="label-wrap">
351
+ <input class="code"
352
+ id="wpzoom-instagram-widget-settings_with-basic-access-token"
353
+ name="wpzoom-instagram-widget-settings[request-type]"
354
+ value="with-basic-access-token" <?php checked( $request_type, 'with-basic-access-token' ) ?>
355
+ type="radio">
356
+ <label for="wpzoom-instagram-widget-settings_with-basic-access-token">
357
+ <?php _e( 'With Basic Instagram API Access Token (New)', 'wpzoom-instagram-widget' ) ?>
358
+ </label>
359
+ </div>
360
+ <div class="label-wrap">
361
+ <input class="code"
362
+ id="wpzoom-instagram-widget-settings_without-access-token"
363
+ name="wpzoom-instagram-widget-settings[request-type]"
364
+ value="without-access-token"
365
+ <?php checked( $request_type, 'without-access-token' ) ?>
366
+ type="radio">
367
+ <label for="wpzoom-instagram-widget-settings_without-access-token">
368
+ <?php _e( 'Public Feed (12 photos)', 'wpzoom-instagram-widget' ) ?>
369
+ </label>
370
+ </div>
371
+ <div class="label-wrap">
372
+ <input class="code"
373
+ id="wpzoom-instagram-widget-settings_with-access-token"
374
+ name="wpzoom-instagram-widget-settings[request-type]"
375
+ value="with-access-token" <?php checked( $request_type, 'with-access-token' ) ?>
376
+ type="radio">
377
+ <label for="wpzoom-instagram-widget-settings_with-access-token">
378
+ <?php _e( 'With Instagram Legacy API Access Token (Retired)', 'wpzoom-instagram-widget' ) ?>
379
+ &nbsp;</label>
380
+ </div>
381
+
382
  </div>
383
 
384
  <?php
429
  return;
430
  }
431
 
432
+ wp_enqueue_style( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/admin-instagram-widget.css', array(), '1.6.0' );
433
+ wp_enqueue_script( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/admin-instagram-widget.js', array( 'jquery' ), '1.6.0' );
434
  wp_localize_script( 'zoom-instagram-widget-admin', 'zoom_instagram_widget_admin', array(
435
  'i18n_connect_confirm' => __( "Instagram Widget is already connected to Instagram.\r\n\r\nDo you want to connect again?", 'wpzoom-instagram-widget' ),
436
  ) );
440
  $result = array();
441
 
442
  $result['access-token'] = sanitize_text_field( $input['access-token'] );
443
+ $result['basic-access-token'] = sanitize_text_field( $input['basic-access-token'] );
444
+ $result['request-type'] = sanitize_text_field( $input['request-type'] );
445
 
446
+ if ( ! empty( $result['access-token'] ) && !empty($result['request-type']) && 'with-access-token' === $result['request-type'] ) {
447
+ $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['access-token'], $result['request-type']);
448
 
449
  if ( $validation_result !== true ) {
450
+ $access_token_error_message = __( 'Provided Access Token has been rejected by Instagram Legacy API (Retired). Please try again or use the other option.', 'wpzoom-instagram-widget' );
451
 
452
  if ( is_wp_error( $validation_result ) ) {
453
  $access_token_error_message = $validation_result->get_error_message();
466
  }
467
  }
468
 
469
+ if ( ! empty( $result['basic-access-token'] ) && !empty($result['request-type']) && 'with-basic-access-token' === $result['request-type'] ) {
470
+ $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['basic-access-token'], $result['request-type'] );
471
+
472
+ if ( $validation_result !== true ) {
473
+ $access_token_error_message = __( 'Provided Access Token has been rejected by Basic Instagram API (new). Please try again or use the other option.', 'wpzoom-instagram-widget' );
474
+
475
+ if ( is_wp_error( $validation_result ) ) {
476
+ $access_token_error_message = $validation_result->get_error_message();
477
+ }
478
+
479
+ if ( $validation_result !== true ) {
480
+ add_settings_error(
481
+ 'wpzoom-instagram-widget-access-token',
482
+ esc_attr( 'wpzoom-instagram-widget-access-token-invalid' ),
483
+ $access_token_error_message,
484
+ 'error'
485
+ );
486
+ }
487
+
488
+ $result['basic-access-token'] = '';
489
+ }
490
+ }
491
+
492
  $result['username'] = sanitize_text_field( $input['username'] );
 
493
  $result['transient-lifetime-value'] = sanitize_text_field( $input['transient-lifetime-value'] );
494
  $result['transient-lifetime-type'] = sanitize_text_field( $input['transient-lifetime-type'] );
495
  $result['is-embed-stream']= ! empty( $input['is-embed-stream'] ) ? wp_validate_boolean($input['is-embed-stream']) : false;
class-wpzoom-instagram-widget.php CHANGED
@@ -47,9 +47,9 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
47
  * Widget specific scripts & styles
48
  */
49
  public function scripts() {
50
- wp_enqueue_style( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/instagram-widget.css', array('dashicons'), '1.4.2' );
51
  wp_enqueue_script( 'zoom-instagram-widget-lazy-load', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/jquery.lazy.min.js', array( 'jquery' ), '1.4.2' );
52
- wp_enqueue_script( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/instagram-widget.js', array( 'jquery' ), '1.4.2' );
53
  }
54
 
55
  /**
@@ -288,26 +288,28 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
288
  }
289
 
290
  if($show_overlay):?>
291
- <div class='hover-layout zoom-instagram-widget__overlay zoom-instagram-widget__black <?php echo $small_class?>'>
292
 
293
- <div class='hover-controls'>
 
294
  <span class="dashicons dashicons-heart"></span>
295
  <span class="counter"><?php echo $this->format_number($likes); ?></span>
296
  <span class="dashicons dashicons-format-chat"></span>
297
  <span class="counter"><?php echo $this->format_number($comments); ?></span>
298
  </div>
299
- <div class='zoom-instagram-icon-wrap'>
 
300
  <a class="zoom-svg-instagram-stroke" href="<?php echo $link; ?>" rel="noopener" target="_blank" title="<?php echo $alt; ?>"></a>
301
  </div>
302
 
303
 
304
- <a class='zoom-instagram-link' data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
305
  href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
306
  >
307
  </a>
308
  </div>
309
  <?php else: ?>
310
- <a class='zoom-instagram-link' data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
311
  href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
312
  >
313
  </a>
47
  * Widget specific scripts & styles
48
  */
49
  public function scripts() {
50
+ wp_enqueue_style( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/instagram-widget.css', array('dashicons'), '1.6.0' );
51
  wp_enqueue_script( 'zoom-instagram-widget-lazy-load', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/jquery.lazy.min.js', array( 'jquery' ), '1.4.2' );
52
+ wp_enqueue_script( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/instagram-widget.js', array( 'jquery' ), '1.6.0' );
53
  }
54
 
55
  /**
288
  }
289
 
290
  if($show_overlay):?>
291
+ <div class="hover-layout zoom-instagram-widget__overlay zoom-instagram-widget__black <?php echo $small_class?>">
292
 
293
+ <?php if( !empty($likes) && !empty($comments) ):?>
294
+ <div class="hover-controls">
295
  <span class="dashicons dashicons-heart"></span>
296
  <span class="counter"><?php echo $this->format_number($likes); ?></span>
297
  <span class="dashicons dashicons-format-chat"></span>
298
  <span class="counter"><?php echo $this->format_number($comments); ?></span>
299
  </div>
300
+ <?php endif;?>
301
+ <div class="zoom-instagram-icon-wrap">
302
  <a class="zoom-svg-instagram-stroke" href="<?php echo $link; ?>" rel="noopener" target="_blank" title="<?php echo $alt; ?>"></a>
303
  </div>
304
 
305
 
306
+ <a class="zoom-instagram-link" data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
307
  href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
308
  >
309
  </a>
310
  </div>
311
  <?php else: ?>
312
+ <a class="zoom-instagram-link" data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
313
  href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
314
  >
315
  </a>
css/admin-instagram-widget.css CHANGED
@@ -72,4 +72,51 @@
72
  #wpzoom-instagram-widget-settings_transient-lifetime-type{
73
  float: left;
74
  max-width: 100px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
72
  #wpzoom-instagram-widget-settings_transient-lifetime-type{
73
  float: left;
74
  max-width: 100px;
75
+ }
76
+
77
+ .zoom-instagram-widget .wpzoom-instagram-widget-with-access-token-group {
78
+ background-color: #fff6f6;
79
+ }
80
+
81
+ .zoom-instagram-widget .wpzoom-instagram-widget-with-basic-access-token-group, .zoom-instagram-widget .wpzoom-instagram-widget-without-access-token-group {
82
+ background-color: #e0f0e3;
83
+ }
84
+
85
+ .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_with-basic-access-token'],
86
+ .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_without-access-token'] {
87
+ background-color: #e0f0e3;
88
+ }
89
+
90
+ .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_with-access-token'] {
91
+ background-color: #fff6f6;
92
+ }
93
+
94
+ .zoom-instagram-widget .wpzoom-instagram-widget-settings-request-type-wrapper {
95
+ display: flex;
96
+ flex-direction: column;
97
+ }
98
+
99
+ .zoom-instagram-widget .wpzoom-instagram-widget-settings-request-type-wrapper .label-wrap {
100
+ display: flex;
101
+ align-items: center;
102
+ }
103
+
104
+ .zoom-instagram-widget .wpzoom-instagram-widget-settings-request-type-wrapper .label-wrap input[type=radio] {
105
+ z-index: 2;
106
+ }
107
+
108
+ .zoom-instagram-widget .wpzoom-instagram-widget-settings-request-type-wrapper .label-wrap label {
109
+ padding: 10px;
110
+ width: 100%;
111
+ margin-left: -30px;
112
+ padding-left: 40px;
113
+ z-index: 1;
114
+ }
115
+
116
+ .zoom-instagram-widget .form-table th {
117
+ padding-left: 10px;
118
+ }
119
+
120
+ .zoom-instagram-widget .wpzoom-instagram-widget-with-token-group > td {
121
+ padding-right: 0px;
122
  }
css/instagram-widget.css CHANGED
@@ -51,10 +51,23 @@ a.ig-b-v-24:hover {
51
  -moz-transition: opacity 0.25s ease-in-out;
52
  -webkit-transition: opacity 0.25s ease-in-out;
53
  }
 
 
 
 
 
 
 
 
 
 
 
 
54
  .zoom-instagram-widget__item .zoom-instagram-icon-wrap{
 
 
55
  width: 100%;
56
  position: absolute;
57
- bottom: 10%;
58
  z-index: 9;
59
  text-align: center;
60
  }
@@ -139,9 +152,6 @@ a.ig-b-v-24:hover {
139
  width: 18px;
140
  height: 18px;
141
  }
142
- .zoom-instagram-widget__item .hover-layout.small .zoom-instagram-icon-wrap{
143
- bottom: 6%;
144
- }
145
 
146
  .zoom-instagram-widget__item .hover-layout.small .hover-controls .counter{
147
  padding-left: 1px;
51
  -moz-transition: opacity 0.25s ease-in-out;
52
  -webkit-transition: opacity 0.25s ease-in-out;
53
  }
54
+ .zoom-instagram-widget__item .hover-controls ~ .zoom-instagram-icon-wrap{
55
+ bottom: 10%;
56
+ }
57
+
58
+ .zoom-instagram-widget__item .hover-layout.small .hover-controls ~ .zoom-instagram-icon-wrap{
59
+ bottom: 6%;
60
+ }
61
+
62
+ .zoom-instagram-widget__item .hover-layout.small .zoom-instagram-icon-wrap{
63
+ bottom: calc(50% - 15px);
64
+ }
65
+
66
  .zoom-instagram-widget__item .zoom-instagram-icon-wrap{
67
+ bottom: calc(50% - 15px);
68
+ height: 30px;
69
  width: 100%;
70
  position: absolute;
 
71
  z-index: 9;
72
  text-align: center;
73
  }
152
  width: 18px;
153
  height: 18px;
154
  }
 
 
 
155
 
156
  .zoom-instagram-widget__item .hover-layout.small .hover-controls .counter{
157
  padding-left: 1px;
instagram-widget-by-wpzoom.php CHANGED
@@ -6,7 +6,7 @@
6
  * Description: Simple and responsive widget for WordPress to display your Instagram feed
7
  * Author: WPZOOM
8
  * Author URI: https://www.wpzoom.com/
9
- * Version: 1.5.0
10
  * License: GPLv2 or later
11
  */
12
 
@@ -44,3 +44,48 @@ function wpzoom_instagram_ignore_admin_notice() {
44
  add_user_meta($user_id, 'wpzoom_instagram_admin_notice', 'true', true);
45
  }
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  * Description: Simple and responsive widget for WordPress to display your Instagram feed
7
  * Author: WPZOOM
8
  * Author URI: https://www.wpzoom.com/
9
+ * Version: 1.6.4
10
  * License: GPLv2 or later
11
  */
12
 
44
  add_user_meta($user_id, 'wpzoom_instagram_admin_notice', 'true', true);
45
  }
46
  }
47
+
48
+ function wpzoom_instagram_legacy_api_admin_notice() {
49
+
50
+ global $current_user ;
51
+ $user_id = $current_user->ID;
52
+
53
+ $options = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
54
+
55
+ $request_type = !empty($options['request-type']) ? $options['request-type'] : '';
56
+
57
+ /* Check that the user hasn't already clicked to ignore the message */
58
+ if ( ! get_user_meta($user_id, 'wpzoom_instagram_legacy_api_admin_notice') && $request_type === 'with-access-token') {
59
+ echo '<div class="error notice" style="position:relative"><p>';
60
+ printf(__('You’re using an <strong>outdated method</strong> to display your <strong>Instagram feed</strong>. This method will be <a target="_blank" href="https://www.instagram.com/developer/">deprecated</a> on <strong>June 29, 2020</strong>, and we recommend go to the <a href="options-general.php?page=wpzoom-instagram-widget">Settings page</a> and <strong>switch</strong> to the new method.<a style="text-decoration: none" class="notice-dismiss" href="%1$s"></a>'), '?wpzoom_instagram_legacy_api_admin_notice=0');
61
+ echo "</p></div>";
62
+ }
63
+ }
64
+
65
+ function wpzoom_instagram_get_default_settings() {
66
+ return [
67
+ 'access-token' => '',
68
+ 'basic-access-token' => '',
69
+ 'request-type' => 'with-basic-access-token',
70
+ 'username' => '',
71
+ 'transient-lifetime-value' => 1,
72
+ 'transient-lifetime-type' => 'days',
73
+ 'is-embed-stream' => '',
74
+ 'is-forced-timeout' => '',
75
+ 'request-timeout-value' => 15
76
+ ];
77
+ }
78
+
79
+ function wpzoom_instagram_ignore_legacy_api_admin_notice() {
80
+ global $current_user;
81
+ $user_id = $current_user->ID;
82
+ /* If user clicks to ignore the notice, add that to their user meta */
83
+
84
+ if ( isset($_GET['wpzoom_instagram_legacy_api_admin_notice']) && '0' == $_GET['wpzoom_instagram_legacy_api_admin_notice'] ) {
85
+ add_user_meta($user_id, 'wpzoom_instagram_legacy_api_admin_notice', 'true', true);
86
+ }
87
+ }
88
+
89
+
90
+ add_action('admin_notices', 'wpzoom_instagram_legacy_api_admin_notice');
91
+ add_action('admin_init', 'wpzoom_instagram_ignore_legacy_api_admin_notice');
js/admin-instagram-widget.js CHANGED
@@ -6,30 +6,45 @@ jQuery(function($) {
6
  e.preventDefault();
7
 
8
  var activeClass = $(this).val();
9
- var oposite = activeClass == 'with-access-token' ? 'without-access-token' : 'with-access-token';
10
 
11
- $(this).closest('.form-table').find('.wpzoom-instagram-widget-' + activeClass + '-group').show();
12
- $(this).closest('.form-table').find('.wpzoom-instagram-widget-' + oposite + '-group').hide();
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  });
16
 
17
  $('.wpzoom-instagram-widget-settings-request-type-wrapper').find('input[type=radio]:checked').change();
18
 
19
- var hash = window.location.hash;
 
 
20
 
21
- if (hash.indexOf('access_token') > 0) {
22
- var input = $('#wpzoom-instagram-widget-settings_access-token');
23
 
24
- input.val(hash.split('=').pop());
 
 
25
 
26
- input.closest('.form-table').find('input[type=radio]').removeAttr('checked');
 
27
 
28
- var $radio = input.closest('.form-table').find('#wpzoom-instagram-widget-settings_with-access-token');
29
  $radio.prop('checked', true);
30
  $radio.trigger('change');
31
 
32
- input.parents('form').find('#submit').click();
 
33
  }
34
 
35
  $('.zoom-instagram-widget .button-connect').on('click', function(event) {
6
  e.preventDefault();
7
 
8
  var activeClass = $(this).val();
 
9
 
10
+ var allDivs = ['with-access-token', 'with-basic-access-token', 'without-access-token'];
11
+
12
+ var inactiveDivs = allDivs.filter(function(item){
13
+ return item !== activeClass;
14
+ });
15
+
16
+ var $formTable = $(this).closest('.form-table');
17
+ $formTable.find('.wpzoom-instagram-widget-' + activeClass + '-group').show();
18
+
19
+ inactiveDivs.forEach(function(inactive){
20
+ $formTable.find('.wpzoom-instagram-widget-' + inactive + '-group').hide();
21
+
22
+ });
23
 
24
 
25
  });
26
 
27
  $('.wpzoom-instagram-widget-settings-request-type-wrapper').find('input[type=radio]:checked').change();
28
 
29
+ var parsedHash = new URLSearchParams(
30
+ window.location.hash.substr(1) // skip the first char (#)
31
+ );
32
 
33
+ if (!!parsedHash.get('access_token')) {
 
34
 
35
+ var requestType = !!parsedHash.get('request_type') && parsedHash.get('request_type') === 'with-basic-access-token' ? 'with-basic-access-token' : 'with-access-token';
36
+ var accessTokenInputName = requestType === 'with-basic-access-token' ? 'basic-access-token' : 'access-token';
37
+ var $input = $('#wpzoom-instagram-widget-settings_' + accessTokenInputName);
38
 
39
+ $input.val(parsedHash.get('access_token'));
40
+ $input.closest('.form-table').find('input[type=radio]').removeAttr('checked');
41
 
42
+ var $radio = $input.closest('.form-table').find('#wpzoom-instagram-widget-settings_' + requestType);
43
  $radio.prop('checked', true);
44
  $radio.trigger('change');
45
 
46
+ $input.parents('form').find('#submit').click();
47
+
48
  }
49
 
50
  $('.zoom-instagram-widget .button-connect').on('click', function(event) {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: WPZOOM, nvartolomei, ciorici
3
  Donate link: https://www.wpzoom.com/
4
  Tags: instagram, widget, timeline, social network, latest images, feed, instagram feed, story, stories, insta, instagram widget
5
  Requires at least: 4.3
6
- Tested up to: 5.4
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
@@ -16,7 +16,7 @@ Formerly known as "Instagram Widget by WPZOOM". Fully customisable and responsiv
16
  Formerly known as *Instagram Widget by WPZOOM*, **WPZOOM Social Feed Widget** is a fully customisable and responsive widget for WordPress to display your **Instagram feed**.
17
 
18
 
19
- **[View Demo](http://demo.wpzoom.com/instagram-widget/)**
20
 
21
 
22
  > Did you find this plugin helpful? Please consider [leaving a 5-star review](https://wordpress.org/support/view/plugin-reviews/instagram-widget-by-wpzoom).
@@ -67,6 +67,22 @@ Make sure to connect your Instagram account with the plugin. You can do that in
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  = 1.5.0 =
71
  * Refactor of the Public Feed method.
72
  * Added 2 new options in the settings page to have more control on the connection with the Instagram API on specific hosting
@@ -153,3 +169,9 @@ Make sure to connect your Instagram account with the plugin. You can do that in
153
 
154
  = 1.0 =
155
  * Initial release.
 
 
 
 
 
 
3
  Donate link: https://www.wpzoom.com/
4
  Tags: instagram, widget, timeline, social network, latest images, feed, instagram feed, story, stories, insta, instagram widget
5
  Requires at least: 4.3
6
+ Tested up to: 5.5
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
16
  Formerly known as *Instagram Widget by WPZOOM*, **WPZOOM Social Feed Widget** is a fully customisable and responsive widget for WordPress to display your **Instagram feed**.
17
 
18
 
19
+ **[View Demo](https://demo.wpzoom.com/instagram-widget/)**
20
 
21
 
22
  > Did you find this plugin helpful? Please consider [leaving a 5-star review](https://wordpress.org/support/view/plugin-reviews/instagram-widget-by-wpzoom).
67
 
68
  == Changelog ==
69
 
70
+ = 1.6.4 =
71
+ * Minor bug fixes for PHP 7.4
72
+
73
+ = 1.6.3 =
74
+ * Minor bug fix when switching from Public Feed to the new API method.
75
+
76
+ = 1.6.2 =
77
+ * Minor bug fix with cached plugin assets when updating from an older version
78
+
79
+ = 1.6.1 =
80
+ * Minor bug fixes
81
+
82
+ = 1.6.0 =
83
+ * Added support for the new Instagram Basic Display API.
84
+ * IMPORTANT: On June 29, Instagram will stop supporting its old API which will disrupt feeds created using the old API. If your Instagram account is connected in the plugin settings, you will need to reconnect it again using the new API.
85
+
86
  = 1.5.0 =
87
  * Refactor of the Public Feed method.
88
  * Added 2 new options in the settings page to have more control on the connection with the Instagram API on specific hosting
169
 
170
  = 1.0 =
171
  * Initial release.
172
+
173
+
174
+ == Upgrade Notice ==
175
+
176
+ = 1.6.0 =
177
+ ⚠️ IMPORTANT: On June 29, Instagram will stop supporting its old API which will disrupt feeds created using the old API. If your Instagram account is connected in the plugin settings, you will need to reconnect it again using the new API.
screenshot-1.jpg DELETED
Binary file
screenshot-2.jpg DELETED
Binary file
screenshot-3.jpg DELETED
Binary file
screenshot-4.jpg DELETED
Binary file
screenshot-5.jpg DELETED
Binary file