Instagram Widget by WPZOOM - Version 1.5.0

Version Description

  • Refactor of the Public Feed method.
  • Added 2 new options in the settings page to have more control on the connection with the Instagram API on specific hosting
Download this release

Release Info

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

Code changes from version 1.4.4 to 1.5.0

class-wpzoom-instagram-widget-api.php CHANGED
@@ -13,6 +13,20 @@ class Wpzoom_Instagram_Widget_API {
13
  */
14
  protected $access_token;
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * Returns the *Singleton* instance of this class.
18
  *
@@ -34,9 +48,86 @@ class Wpzoom_Instagram_Widget_API {
34
  $this->request_type = !empty($options['request_type']) ? $options['request_type'] : '';
35
  $this->transient_lifetime_type = !empty($options['transient-lifetime-type']) ? $options['transient-lifetime-type'] : 'days';
36
  $this->transient_lifetime_value = !empty($options['transient-lifetime-value']) ? $options['transient-lifetime-value'] : 1;
 
 
 
 
 
 
 
 
 
 
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  function get_transient_lifetime() {
41
 
42
  $values = array( 'minutes' => MINUTE_IN_SECONDS, 'hours' => HOUR_IN_SECONDS, 'days' => DAY_IN_SECONDS );
@@ -50,14 +141,20 @@ class Wpzoom_Instagram_Widget_API {
50
 
51
  $response = $this->get_response_without_token( $user );
52
 
53
- if ( empty( $response ) ) {
54
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
 
 
55
  }
56
 
57
- if ( isset( $response->entry_data->ProfilePage[0]->graphql->user ) ) {
58
  $user_info = $response->entry_data->ProfilePage[0]->graphql->user;
 
 
59
  } else {
60
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
 
 
61
  }
62
 
63
  $converted = new stdClass;
@@ -81,15 +178,50 @@ class Wpzoom_Instagram_Widget_API {
81
 
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  function get_response_without_token( $user ) {
85
 
86
  $user = trim( $user );
87
- $url = $url = 'https://instagram.com/' . str_replace( '@', '', $user );
 
 
 
 
 
 
 
88
 
89
- $request = wp_remote_get( $url );
90
 
91
- if ( is_wp_error( $request ) || empty( $request ) ) {
92
- return new WP_Error( 'invalid_response', __( 'Invalid response from Instagram', 'wpzoom-instagram-widget' ) );
 
 
 
93
  }
94
 
95
  $body = wp_remote_retrieve_body( $request );
@@ -113,7 +245,15 @@ class Wpzoom_Instagram_Widget_API {
113
  $result = json_decode( $json );
114
 
115
  if ( empty( $result ) ) {
116
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
 
 
 
 
 
 
 
 
117
  }
118
 
119
  return $result;
@@ -121,17 +261,22 @@ class Wpzoom_Instagram_Widget_API {
121
 
122
  function get_items_without_token( $user ) {
123
 
124
-
125
  $result = $this->get_response_without_token( $user );
126
 
127
- if ( empty( $result ) ) {
128
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
 
 
129
  }
130
 
131
- if ( isset( $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges ) ) {
132
  $edges = $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges;
 
 
133
  } else {
134
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
 
 
135
  }
136
 
137
  $converted = new stdClass;
@@ -221,11 +366,14 @@ class Wpzoom_Instagram_Widget_API {
221
 
222
  if ( ! empty( $this->access_token ) ) {
223
  $api_image_limit = 30;
224
- $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 ) );
225
 
226
  if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
227
  set_transient( $transient, false, MINUTE_IN_SECONDS );
228
 
 
 
 
229
  return false;
230
  }
231
 
@@ -267,6 +415,9 @@ class Wpzoom_Instagram_Widget_API {
267
  } else {
268
  set_transient( $transient, false, MINUTE_IN_SECONDS );
269
 
 
 
 
270
  return false;
271
  }
272
 
@@ -294,9 +445,12 @@ class Wpzoom_Instagram_Widget_API {
294
 
295
  }
296
 
 
 
 
297
  $result[] = array(
298
  'link' => $item->link,
299
- 'image-url' => $item->images->{$this->get_best_size( $image_width, $image_resolution )}->url,
300
  'image-caption' => ! empty( $item->caption->text ) ? esc_attr( $item->caption->text ) : '',
301
  'likes_count' => ! empty( $item->likes->count ) ? esc_attr( $item->likes->count ) : 0,
302
  'comments_count' => ! empty( $item->comments->count ) ? esc_attr( $item->comments->count ) : 0
@@ -330,11 +484,14 @@ class Wpzoom_Instagram_Widget_API {
330
 
331
  if ( ! empty( $this->access_token ) ) {
332
 
333
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $this->access_token ) );
334
 
335
  if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
336
  set_transient( $transient, false, MINUTE_IN_SECONDS );
337
 
 
 
 
338
  return false;
339
  }
340
 
@@ -375,6 +532,9 @@ class Wpzoom_Instagram_Widget_API {
375
  } else {
376
  set_transient( $transient, false, MINUTE_IN_SECONDS );
377
 
 
 
 
378
  return false;
379
  }
380
 
@@ -394,7 +554,7 @@ class Wpzoom_Instagram_Widget_API {
394
  return $user_id;
395
  }
396
 
397
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/search?q=%s&access_token=%s', $screen_name, $this->access_token ) );
398
 
399
  if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
400
  return false;
@@ -450,6 +610,19 @@ class Wpzoom_Instagram_Widget_API {
450
  return $size;
451
  }
452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  /**
454
  * Check if given access token is valid for Instagram Api.
455
  */
@@ -511,4 +684,4 @@ class Wpzoom_Instagram_Widget_API {
511
  public function set_access_token( $access_token ) {
512
  $this->access_token = $access_token;
513
  }
514
- }
13
  */
14
  protected $access_token;
15
 
16
+ /**
17
+ * Request headers.
18
+ *
19
+ * @var array
20
+ */
21
+ public $headers = [];
22
+
23
+ /**
24
+ * Errors collector.
25
+ *
26
+ * @var array|WP_Error
27
+ */
28
+ public $errors = [];
29
+
30
  /**
31
  * Returns the *Singleton* instance of this class.
32
  *
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;
52
+ $this->is_forced_timeout = ! empty($options['is-forced-timeout']) ? wp_validate_boolean( $options['is-forced-timeout'] ) : false;
53
+ $this->request_timeout_value = !empty($options['request-timeout-value']) ? $options['request-timeout-value'] : 15;
54
+
55
+ if ($this->is_forced_timeout && !empty($this->request_timeout_value)) {
56
+ $this->headers['timeout'] = $this->request_timeout_value;
57
+ }
58
+
59
+ $this->errors = new WP_Error();
60
+
61
+ }
62
 
63
+ /**
64
+ * Get error messages collection.
65
+ *
66
+ * @return array
67
+ */
68
+ public function get_errors(){
69
+ return [
70
+ 'user-info-without-token' => [
71
+ 'code' => 'user-info-without-token',
72
+ 'message' => __('Empty json user info from Public Feed.', 'wpzoom-instagram-widget')
73
+ ],
74
+ 'response-data-without-token-from-json-invalid-response' => [
75
+ 'code' => 'response-data-without-token-from-json-invalid-response',
76
+ 'message' => __('The request from the Public Feed failed. Invalid server response from Public JSON API url.', 'wpzoom-instagram-widget')
77
+ ],
78
+ 'response-data-without-token-from-json-invalid-json-format' => [
79
+ 'code' => 'response-data-without-token-from-json-invalid-json-format',
80
+ 'message' => __('The request from the Public Feed failed. Invalid JSON format from Public JSON API url.', 'wpzoom-instagram-widget')
81
+ ],
82
+ 'response-data-without-token-from-html-invalid-response' => [
83
+ 'code' => 'response-data-without-token-from-html-invalid-response',
84
+ 'message' => __('The request from the Public Feed failed. Check username.', 'wpzoom-instagram-widget')
85
+ ],
86
+ 'response-data-without-token-from-html-invalid-json-format' => [
87
+ 'code' => 'response-data-without-token-from-html-invalid-json-format',
88
+ 'message' => __('The request from the Public Feed failed. Invalid JSON format from parsed html body.', 'wpzoom-instagram-widget')
89
+ ],
90
+ 'items-without-token-invalid-response' => [
91
+ 'code' => 'items-without-token-invalid-response',
92
+ 'message' => __('Get items from the Public Feed failed. Invalid response.', 'wpzoom-instagram-widget')
93
+ ],
94
+ 'items-without-token-invalid-json-structure' => [
95
+ 'code' => 'items-without-token-invalid-json-structure',
96
+ 'message' => __('Get items from the Public Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
97
+ ],
98
+ 'items-with-token-invalid-response' => [
99
+ 'code' => 'items-with-token-invalid-response',
100
+ 'message' => __('Geting items from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget')
101
+ ],
102
+ 'items-with-token-invalid-data-structure' => [
103
+ 'code' => 'items-with-token-invalid-data-structure',
104
+ 'message' => __('Get items from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
105
+ ],
106
+ 'user-with-token-invalid-response' => [
107
+ 'code' => 'user-with-token-invalid-response',
108
+ 'message' => __('Get user data from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget')
109
+ ],
110
+ 'user-with-token-invalid-data-structure' => [
111
+ 'code' => 'user-with-token-invalid-data-structure',
112
+ 'message' => __('Get user data from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
113
+ ],
114
+
115
+ ];
116
  }
117
 
118
+ /**
119
+ * Retrieve error message by key.
120
+ *
121
+ * @param $key
122
+ *
123
+ * @return bool|mixed
124
+ */
125
+ public function get_error( $key ) {
126
+ $errors = $this->get_errors();
127
+
128
+ return array_key_exists( $key, $errors ) ? $errors[ $key ] : false;
129
+ }
130
+
131
  function get_transient_lifetime() {
132
 
133
  $values = array( 'minutes' => MINUTE_IN_SECONDS, 'hours' => HOUR_IN_SECONDS, 'days' => DAY_IN_SECONDS );
141
 
142
  $response = $this->get_response_without_token( $user );
143
 
144
+ if ( is_wp_error( $response ) ) {
145
+ $error_data = $this->get_error('user-info-without-token');
146
+ $this->errors->add($error_data['code'], $error_data['message']);
147
+ return new WP_Error( $error_data['code'], $error_data['message'] );
148
  }
149
 
150
+ if (isset($response->entry_data->ProfilePage[0]->graphql->user)) {
151
  $user_info = $response->entry_data->ProfilePage[0]->graphql->user;
152
+ } elseif (isset($response->graphql->user)) {
153
+ $user_info = $response->graphql->user;
154
  } else {
155
+ $error_data = $this->get_error('user-info-without-token');
156
+ $this->errors->add($error_data['code'], $error_data['message']);
157
+ return new WP_Error( $error_data['code'], $error_data['message'] );
158
  }
159
 
160
  $converted = new stdClass;
178
 
179
  }
180
 
181
+ function get_response_without_token_from_json( $user ) {
182
+
183
+ $user = trim( $user );
184
+ $url = 'https://instagram.com/' . str_replace( '@', '', $user ).'/?__a=1';
185
+
186
+ $request = wp_remote_get( $url, $this->headers );
187
+
188
+ if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
189
+ $error_data = $this->get_error('response-data-without-token-from-json-invalid-response');
190
+ $this->errors->add($error_data['code'], $error_data['message']);
191
+ return new WP_Error($error_data['code'], $error_data['message']);
192
+ }
193
+
194
+ $result = json_decode( wp_remote_retrieve_body( $request ) );
195
+
196
+ if ( empty( $result ) ) {
197
+ $error_data = $this->get_error('response-data-without-token-from-json-invalid-json-format');
198
+ $this->errors->add($error_data['code'], $error_data['message']);
199
+ return new WP_Error($error_data['code'], $error_data['message']);
200
+ }
201
+
202
+ return $result;
203
+ }
204
+
205
+
206
  function get_response_without_token( $user ) {
207
 
208
  $user = trim( $user );
209
+ $url = 'https://instagram.com/' . str_replace( '@', '', $user );
210
+
211
+ $request = wp_remote_get( $url, $this->headers );
212
+
213
+ if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
214
+
215
+ $error_data = $this->get_error('response-data-without-token-from-html-invalid-response');
216
+ $this->errors->add($error_data['code'], $error_data['message']);
217
 
218
+ $result = $this->get_response_without_token_from_json($user);
219
 
220
+ if (is_wp_error($result)) {
221
+ return new WP_Error('invalid_response', __('Invalid response from Instagram', 'wpzoom-instagram-widget'));
222
+ } else {
223
+ return $result;
224
+ }
225
  }
226
 
227
  $body = wp_remote_retrieve_body( $request );
245
  $result = json_decode( $json );
246
 
247
  if ( empty( $result ) ) {
248
+
249
+ $error_data = $this->get_error('response-data-without-token-from-html-invalid-json-format');
250
+ $this->errors->add($error_data['code'], $error_data['message']);
251
+
252
+ $result = $this->get_response_without_token_from_json($user);
253
+
254
+ if(is_wp_error($result)){
255
+ return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
256
+ }
257
  }
258
 
259
  return $result;
261
 
262
  function get_items_without_token( $user ) {
263
 
 
264
  $result = $this->get_response_without_token( $user );
265
 
266
+ if (is_wp_error($result)) {
267
+ $error_data = $this->get_error('items-without-token-invalid-response');
268
+ $this->errors->add($error_data['code'], $error_data['message']);
269
+ return new WP_Error($error_data['code'], $error_data['message']);
270
  }
271
 
272
+ if (isset($result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges)) {
273
  $edges = $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges;
274
+ } elseif (isset($result->graphql->user->edge_owner_to_timeline_media->edges)) {
275
+ $edges = $result->graphql->user->edge_owner_to_timeline_media->edges;
276
  } else {
277
+ $error_data = $this->get_error('items-without-token-invalid-json-structure');
278
+ $this->errors->add($error_data['code'], $error_data['message']);
279
+ return new WP_Error($error_data['code'], $error_data['message']);
280
  }
281
 
282
  $converted = new stdClass;
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
 
415
  } else {
416
  set_transient( $transient, false, MINUTE_IN_SECONDS );
417
 
418
+ $error_data = $this->get_error('items-with-token-invalid-data-structure');
419
+ $this->errors->add($error_data['code'], $error_data['message']);
420
+
421
  return false;
422
  }
423
 
445
 
446
  }
447
 
448
+ $best_size = $this->get_best_size( $image_width, $image_resolution );
449
+ $image_url = $this->is_embed_stream ? $this->convert_to_embed_url( $best_size, $item->link ) : $item->images->{$best_size}->url;
450
+
451
  $result[] = array(
452
  'link' => $item->link,
453
+ 'image-url' => $image_url,
454
  'image-caption' => ! empty( $item->caption->text ) ? esc_attr( $item->caption->text ) : '',
455
  'likes_count' => ! empty( $item->likes->count ) ? esc_attr( $item->likes->count ) : 0,
456
  'comments_count' => ! empty( $item->comments->count ) ? esc_attr( $item->comments->count ) : 0
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
 
532
  } else {
533
  set_transient( $transient, false, MINUTE_IN_SECONDS );
534
 
535
+ $error_data = $this->get_error('user-with-token-invalid-data-structure');
536
+ $this->errors->add($error_data['code'], $error_data['message']);
537
+
538
  return false;
539
  }
540
 
554
  return $user_id;
555
  }
556
 
557
+ $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/search?q=%s&access_token=%s', $screen_name, $this->access_token ), $this->headers );
558
 
559
  if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
560
  return false;
610
  return $size;
611
  }
612
 
613
+ protected function convert_to_embed_url( $size, $link ) {
614
+ $sizes = array(
615
+ 'thumbnail' => 't',
616
+ 'low_resolution' => 'm',
617
+ 'standard_resolution' => 'l'
618
+ );
619
+
620
+ $shortcode = trim( basename( $link ) );
621
+ $embed_url = sprintf( 'https://instagram.com/p/%1$s/media/?size=%2$s', $shortcode, $sizes[ $size ] );
622
+
623
+ return $embed_url;
624
+ }
625
+
626
  /**
627
  * Check if given access token is valid for Instagram Api.
628
  */
684
  public function set_access_token( $access_token ) {
685
  $this->access_token = $access_token;
686
  }
687
+ }
class-wpzoom-instagram-widget-settings.php CHANGED
@@ -106,6 +106,31 @@ class Wpzoom_Instagram_Widget_Settings {
106
  'wpzoom-instagram-widget-settings-general'
107
  );
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  }
111
 
@@ -152,6 +177,48 @@ class Wpzoom_Instagram_Widget_Settings {
152
  <?php
153
  }
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  public function settings_field_access_token_input() {
156
  $settings = get_option( 'wpzoom-instagram-widget-settings' );
157
  ?>
@@ -200,7 +267,7 @@ class Wpzoom_Instagram_Widget_Settings {
200
  $request_type = empty( $settings['request-type'] ) ? 'with-access-token' : $settings['request-type'];
201
  ?>
202
 
203
- <div class="wpzoom-instagram-widget-settins-request-type-wrapper">
204
  <p><label for="wpzoom-instagram-widget-settings_with-access-token"><input class="code" id="wpzoom-instagram-widget-settings_with-access-token"
205
  name="wpzoom-instagram-widget-settings[request-type]"
206
  value="with-access-token" <?php checked( $request_type, 'with-access-token' ) ?> type="radio"> <?php _e('With Access Token', 'wpzoom-instagram-widget')?>&nbsp;&nbsp;</label>
@@ -297,6 +364,9 @@ class Wpzoom_Instagram_Widget_Settings {
297
  $result['request-type'] = sanitize_text_field( $input['request-type'] );
298
  $result['transient-lifetime-value'] = sanitize_text_field( $input['transient-lifetime-value'] );
299
  $result['transient-lifetime-type'] = sanitize_text_field( $input['transient-lifetime-type'] );
 
 
 
300
 
301
  Wpzoom_Instagram_Widget_API::reset_cache();
302
 
106
  'wpzoom-instagram-widget-settings-general'
107
  );
108
 
109
+ add_settings_field(
110
+ 'wpzoom-instagram-widget-is-embed-stream',
111
+ __( 'Serve images from Instagram embed links', 'wpzoom-instagram-widget' ),
112
+ array( $this, 'settings_field_is_embed_stream' ),
113
+ 'wpzoom-instagram-widget-settings-group',
114
+ 'wpzoom-instagram-widget-settings-general'
115
+ );
116
+
117
+ add_settings_field(
118
+ 'wpzoom-instagram-widget-is-forced-timeout',
119
+ __( 'Enable request timeout', 'wpzoom-instagram-widget' ),
120
+ array( $this, 'settings_field_is_forced_timeout' ),
121
+ 'wpzoom-instagram-widget-settings-group',
122
+ 'wpzoom-instagram-widget-settings-general'
123
+ );
124
+
125
+ add_settings_field(
126
+ 'wpzoom-instagram-widget-request-timeout',
127
+ __( 'Request timeout in seconds.', 'wpzoom-instagram-widget' ),
128
+ array( $this, 'settings_field_request_timeout' ),
129
+ 'wpzoom-instagram-widget-settings-group',
130
+ 'wpzoom-instagram-widget-settings-general',
131
+ array('class' => 'wpzoom-instagram-widget-request-timeout')
132
+ );
133
+
134
 
135
  }
136
 
177
  <?php
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"
185
+ id="wpzoom-instagram-widget-settings_is-embed-stream"
186
+ name="wpzoom-instagram-widget-settings[is-embed-stream]"
187
+ <?php checked(true , $is_embed_stream)?>
188
+ value="1"
189
+ type="checkbox">
190
+
191
+ <?php
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"
199
+ id="wpzoom-instagram-widget-settings_is-forced-timeout"
200
+ name="wpzoom-instagram-widget-settings[is-forced-timeout]"
201
+ <?php checked(true , $is_forced_timeout)?>
202
+ value="1"
203
+ type="checkbox">
204
+
205
+ <?php
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"
213
+ id="wpzoom-instagram-widget-settings_request-timeout-value"
214
+ name="wpzoom-instagram-widget-settings[request-timeout-value]"
215
+ value="<?php echo esc_attr( $timeout_value ) ?>"
216
+ type="number"
217
+ min="1"
218
+ max="30">
219
+ <?php
220
+ }
221
+
222
  public function settings_field_access_token_input() {
223
  $settings = get_option( 'wpzoom-instagram-widget-settings' );
224
  ?>
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>
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;
368
+ $result['is-forced-timeout']= ! empty( $input['is-forced-timeout'] ) ? wp_validate_boolean($input['is-forced-timeout']) : false;
369
+ $result['request-timeout-value'] = sanitize_text_field( $input['request-timeout-value'] );
370
 
371
  Wpzoom_Instagram_Widget_API::reset_cache();
372
 
class-wpzoom-instagram-widget.php CHANGED
@@ -71,9 +71,10 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
71
 
72
 
73
  $items = $this->api->get_items( $instance );
 
74
 
75
  if ( ! is_array( $items ) ) {
76
- $this->display_errors();
77
  } else {
78
 
79
  if ( ! empty( $instance['show-user-info'] ) ) {
@@ -435,12 +436,20 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
435
  *
436
  * @return void
437
  */
438
- protected function display_errors() {
439
  if ( current_user_can( 'edit_theme_options' ) ) {
440
  ?>
441
  <p>
442
  <?php _e( 'Instagram Widget misconfigured, check plugin &amp; widget settings.', 'wpzoom-instagram-widget' ); ?>
443
  </p>
 
 
 
 
 
 
 
 
444
  <?php
445
  } else {
446
  echo "&#8230;";
71
 
72
 
73
  $items = $this->api->get_items( $instance );
74
+ $errors = $this->api->errors->get_error_messages();
75
 
76
  if ( ! is_array( $items ) ) {
77
+ $this->display_errors($errors);
78
  } else {
79
 
80
  if ( ! empty( $instance['show-user-info'] ) ) {
436
  *
437
  * @return void
438
  */
439
+ protected function display_errors($errors) {
440
  if ( current_user_can( 'edit_theme_options' ) ) {
441
  ?>
442
  <p>
443
  <?php _e( 'Instagram Widget misconfigured, check plugin &amp; widget settings.', 'wpzoom-instagram-widget' ); ?>
444
  </p>
445
+
446
+ <?php if ( ! empty( $errors ) ): ?>
447
+ <ul>
448
+ <?php foreach ( $errors as $error ): ?>
449
+ <li><?php echo $error; ?></li>
450
+ <?php endforeach; ?>
451
+ </ul>
452
+ <?php endif; ?>
453
  <?php
454
  } else {
455
  echo "&#8230;";
instagram-widget-by-wpzoom.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
 
3
  /**
4
- * Plugin Name: WPZOOM Social Feed Widget
5
  * Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
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.4.4
10
  * License: GPLv2 or later
11
  */
12
 
1
  <?php
2
 
3
  /**
4
+ * Plugin Name: WPZOOM Instagram Widget
5
  * Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
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
 
js/admin-instagram-widget.js CHANGED
@@ -2,7 +2,7 @@
2
 
3
  jQuery(function($) {
4
 
5
- $('.wpzoom-instagram-widget-settins-request-type-wrapper').find('input[type=radio]').on('change', function (e) {
6
  e.preventDefault();
7
 
8
  var activeClass = $(this).val();
@@ -14,7 +14,7 @@ jQuery(function($) {
14
 
15
  });
16
 
17
- $('.wpzoom-instagram-widget-settins-request-type-wrapper').find('input[type=radio]:checked').change();
18
 
19
  var hash = window.location.hash;
20
 
@@ -42,5 +42,9 @@ jQuery(function($) {
42
  }
43
  });
44
 
 
 
 
 
45
 
46
  });
2
 
3
  jQuery(function($) {
4
 
5
+ $('.wpzoom-instagram-widget-settings-request-type-wrapper').find('input[type=radio]').on('change', function (e) {
6
  e.preventDefault();
7
 
8
  var activeClass = $(this).val();
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
 
42
  }
43
  });
44
 
45
+ $('#wpzoom-instagram-widget-settings_is-forced-timeout').on('change', function(e){
46
+ e.preventDefault();
47
+ $('.wpzoom-instagram-widget-request-timeout')[$(this).is(":checked") ? 'show' :'hide']();
48
+ }).trigger('change');
49
 
50
  });
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.2
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
@@ -67,6 +67,10 @@ Make sure to connect your Instagram account with the plugin. You can do that in
67
 
68
  == Changelog ==
69
 
 
 
 
 
70
  = 1.4.4 =
71
  * New option to hide video thumbnails. Sometimes video thubmanils may show as blank squares, so the new option will help to fix this problem.
72
 
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
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
73
+
74
  = 1.4.4 =
75
  * New option to hide video thumbnails. Sometimes video thubmanils may show as blank squares, so the new option will help to fix this problem.
76