Instagram Feed - Version 2.5.4

Version Description

  • Fix: Added more debugging info to the System Info for oEmbeds.
  • Fix: Added a workaround for a rare issue where oEmbed access tokens wouldn't save.
  • Fix: Carousel posts would not show images when using the "Disable JS Image Loading" setting and image resizing was disabled.
Download this release

Release Info

Developer smashballoon
Plugin Icon 128x128 Instagram Feed
Version 2.5.4
Comparing to
See all releases

Code changes from version 2.5.3 to 2.5.4

README.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: smashballoon, craig-at-smash-balloon
3
  Tags: Instagram, Instagram feed, Instagram photos, Instagram widget, Instagram gallery
4
  Requires at least: 3.4
5
  Tested up to: 5.5
6
- Stable tag: 2.5.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -331,6 +331,11 @@ We understand that sometimes you need help, have issues or just have questions.
331
  * Plus more customization options added all the time!
332
 
333
  == Changelog ==
 
 
 
 
 
334
  = 2.5.3 =
335
  * Fix: Fixed an issue caused by an unannounced Instagram API change affecting thumbnails in certain video posts which don't have image data available in the API.
336
  * Fix: Added oEmbed account info to the plugin "System Info" to make debugging easier.
3
  Tags: Instagram, Instagram feed, Instagram photos, Instagram widget, Instagram gallery
4
  Requires at least: 3.4
5
  Tested up to: 5.5
6
+ Stable tag: 2.5.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
331
  * Plus more customization options added all the time!
332
 
333
  == Changelog ==
334
+ = 2.5.4 =
335
+ * Fix: Added more debugging info to the System Info for oEmbeds.
336
+ * Fix: Added a workaround for a rare issue where oEmbed access tokens wouldn't save.
337
+ * Fix: Carousel posts would not show images when using the "Disable JS Image Loading" setting and image resizing was disabled.
338
+
339
  = 2.5.3 =
340
  * Fix: Fixed an issue caused by an unannounced Instagram API change affecting thumbnails in certain video posts which don't have image data available in the API.
341
  * Fix: Added oEmbed account info to the plugin "System Info" to make debugging easier.
inc/admin/main.php CHANGED
@@ -216,6 +216,12 @@ function sbi_oembeds_page() {
216
  </div>
217
  <?php } else {
218
  if ( $valid_new_access_token ) {
 
 
 
 
 
 
219
  $oembed_token_settings['access_token'] = $valid_new_access_token;
220
  $oembed_token_settings['disabled'] = false;
221
  update_option( 'sbi_oembed_token', $oembed_token_settings );
@@ -3206,6 +3212,21 @@ $oembed_token_settings = get_option( 'sbi_oembed_token', array() );
3206
  foreach( $oembed_token_settings as $key => $value ) {
3207
  echo $key . ': ' . esc_attr( $value ) . "\n";
3208
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3209
  ?>
3210
  </textarea>
3211
  <div><input id="sbi_reset_log" class="button-secondary" type="submit" value="<?php esc_attr_e( 'Reset Error Log' ); ?>" style="vertical-align: middle;"/></div>
216
  </div>
217
  <?php } else {
218
  if ( $valid_new_access_token ) {
219
+ if ( ! is_array( $oembed_token_settings ) ) {
220
+ $oembed_token_settings = array(
221
+ 'access_token' => '',
222
+ 'disabled' => '',
223
+ );
224
+ }
225
  $oembed_token_settings['access_token'] = $valid_new_access_token;
226
  $oembed_token_settings['disabled'] = false;
227
  update_option( 'sbi_oembed_token', $oembed_token_settings );
3212
  foreach( $oembed_token_settings as $key => $value ) {
3213
  echo $key . ': ' . esc_attr( $value ) . "\n";
3214
  }
3215
+
3216
+ $single = new SB_Instagram_Single( 'https://www.instagram.com/p/CCq1D_cMYMF/' );
3217
+ $post = $single->fetch();
3218
+ $message = '';
3219
+ if ( isset( $post['thumbnail_url'] ) ) {
3220
+ $message = 'success';
3221
+ } else {
3222
+ $error = $single->get_error();
3223
+
3224
+ if ( ! empty( $error ) ) {
3225
+ $message = $error;
3226
+ }
3227
+ }
3228
+ echo 'oEmbed request test: ' . esc_attr( $message );
3229
+
3230
  ?>
3231
  </textarea>
3232
  <div><input id="sbi_reset_log" class="button-secondary" type="submit" value="<?php esc_attr_e( 'Reset Error Log' ); ?>" style="vertical-align: middle;"/></div>
inc/class-sb-instagram-display-elements.php CHANGED
@@ -74,14 +74,20 @@ class SB_Instagram_Display_Elements
74
  $optimum_res = 'full';
75
  $settings['imageres'] = 'full';
76
  } else {
77
- if ( $settings['imageres'] !== 'thumb' && ! empty( $resized_images ) ) {
78
  $resolution = $settings['imageres'];
79
  $post_id = SB_Instagram_Parse::get_post_id( $post );
80
  if ( isset( $resized_images[ $post_id ] )
81
  && $resized_images[ $post_id ]['id'] !== 'error'
82
  && $resized_images[ $post_id ]['id'] !== 'pending'
83
  && $resized_images[ $post_id ]['id'] !== 'video' ) {
84
- if ( $resolution === 'medium' ) {
 
 
 
 
 
 
85
  if ( isset( $resized_images[ $post_id ]['sizes']['low'] ) ) {
86
  $suffix = 'low';
87
  } elseif ( isset( $resized_images[ $post_id ]['sizes']['full'] ) ) {
@@ -127,32 +133,55 @@ class SB_Instagram_Display_Elements
127
  && $resized_images[ $post_id ]['id'] !== 'error' ) {
128
  $media_url = sbi_get_resized_uploads_url() . $resized_images[ $post_id ]['id'] . 'full.jpg';
129
  } else {
130
- $permalink = SB_Instagram_Parse::get_permalink( $post );
131
- if ( substr_count( $permalink, '/' ) > 5 ) {
132
- $permalink_array = explode( '/', $permalink );
133
- $perm_id = $permalink_array[ count( $permalink_array ) - 2 ];
134
- $permalink = 'https://www.instagram.com/p/' . $perm_id . '/';
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
- if ( ($post['media_type'] === 'CAROUSEL_ALBUM' || $post['media_type'] === 'VIDEO') && ($optimum_res === 'lightbox' || $optimum_res === 'full')) {
138
- $media_url = $permalink . 'media/?size=l';
139
- } else {
140
- switch ($optimum_res) {
141
- case 'thumb' :
142
- $media_url = $permalink . 'media/?size=t';
143
- break;
144
- case 'medium' :
145
- $media_url = $permalink . 'media/?size=m';
146
- break;
147
- default :
148
- if ( isset( $post['media_url'] ) ) {
149
- $media_url = $post['media_url'];
150
- } else {
151
- $permalink = SB_Instagram_Parse::fix_permalink( SB_Instagram_Parse::get_permalink( $post ) );
152
 
153
- $media_url = $permalink . 'media/?size=l';
154
- }
 
 
 
 
 
 
 
 
 
155
  }
 
 
156
  }
157
  }
158
 
74
  $optimum_res = 'full';
75
  $settings['imageres'] = 'full';
76
  } else {
77
+ if ( ! empty( $resized_images ) ) {
78
  $resolution = $settings['imageres'];
79
  $post_id = SB_Instagram_Parse::get_post_id( $post );
80
  if ( isset( $resized_images[ $post_id ] )
81
  && $resized_images[ $post_id ]['id'] !== 'error'
82
  && $resized_images[ $post_id ]['id'] !== 'pending'
83
  && $resized_images[ $post_id ]['id'] !== 'video' ) {
84
+ if ( $resolution === 'thumb' ) {
85
+ if ( isset( $resized_images[ $post_id ]['sizes']['low'] ) ) {
86
+ $suffix = 'low';
87
+ } elseif ( isset( $resized_images[ $post_id ]['sizes']['full'] ) ) {
88
+ $suffix = 'full';
89
+ }
90
+ } elseif ( $resolution === 'medium' ) {
91
  if ( isset( $resized_images[ $post_id ]['sizes']['low'] ) ) {
92
  $suffix = 'low';
93
  } elseif ( isset( $resized_images[ $post_id ]['sizes']['full'] ) ) {
133
  && $resized_images[ $post_id ]['id'] !== 'error' ) {
134
  $media_url = sbi_get_resized_uploads_url() . $resized_images[ $post_id ]['id'] . 'full.jpg';
135
  } else {
136
+ $media_type = $post['media_type'];
137
+ if ( $media_type === 'CAROUSEL_ALBUM'
138
+ || $media_type === 'VIDEO'
139
+ || $media_type === 'OEMBED' ) {
140
+ if ( isset( $post['thumbnail_url'] ) ) {
141
+ return $post['thumbnail_url'];
142
+ } elseif ( $media_type === 'CAROUSEL_ALBUM' && isset( $post['media_url'] ) ) {
143
+ return $post['media_url'];
144
+ } elseif ( isset( $post['children'] ) ) {
145
+ $i = 0;
146
+ $full_size = '';
147
+ foreach ( $post['children']['data'] as $carousel_item ) {
148
+ if ( $carousel_item['media_type'] === 'IMAGE' && empty( $full_size ) ) {
149
+ if ( isset( $carousel_item['media_url'] ) ) {
150
+ $full_size = $carousel_item['media_url'];
151
+ }
152
+ } elseif ( $carousel_item['media_type'] === 'VIDEO' && empty( $full_size ) ) {
153
+ if ( isset( $carousel_item['thumbnail_url'] ) ) {
154
+ $full_size = $carousel_item['thumbnail_url'];
155
+ }
156
+ }
157
 
158
+ $i++;
159
+ }
160
+ return $full_size;
161
+ } else {
162
+ if ( ! class_exists( 'SB_Instagram_Single' ) ) {
163
+ return trailingslashit( SBI_PLUGIN_URL ) . 'img/thumb-placeholder.png';
164
+ }
165
+ //attempt to get
166
+ $permalink = SB_Instagram_Parse::fix_permalink( SB_Instagram_Parse::get_permalink( $post ) );
167
+ $single = new SB_Instagram_Single( $permalink );
168
+ $single->init();
169
+ $post = $single->get_post();
 
 
 
170
 
171
+ if ( isset( $post['thumbnail_url'] ) ) {
172
+ return $post['thumbnail_url'];
173
+ } elseif ( isset( $post['media_url'] ) && strpos( $post['media_url'], '.mp4' ) === false ) {
174
+ return $post['media_url'];
175
+ }
176
+
177
+ return trailingslashit( SBI_PLUGIN_URL ) . 'img/thumb-placeholder.png';
178
+ }
179
+ } else {
180
+ if ( isset( $post['media_url'] ) ) {
181
+ return $post['media_url'];
182
  }
183
+
184
+ return trailingslashit( SBI_PLUGIN_URL ) . 'img/thumb-placeholder.png';
185
  }
186
  }
187
 
inc/class-sb-instagram-single.php CHANGED
@@ -28,6 +28,11 @@ class SB_Instagram_Single
28
  */
29
  private $post;
30
 
 
 
 
 
 
31
  /**
32
  * SB_Instagram_Single constructor.
33
  *
@@ -44,6 +49,7 @@ class SB_Instagram_Single
44
  $this->permalink_id = $permalink_or_permalink_id;
45
  $this->permalink = 'https://www.instagram.com/p/' . $this->permalink_id;
46
  }
 
47
  }
48
 
49
  /**
@@ -84,6 +90,10 @@ class SB_Instagram_Single
84
  return $this->post;
85
  }
86
 
 
 
 
 
87
  /**
88
  * Image URLs expire so this will compare when the data
89
  * was last updated from the API
@@ -115,6 +125,7 @@ class SB_Instagram_Single
115
  $access_token = SB_Instagram_Oembed::last_access_token();
116
 
117
  if ( empty( $access_token ) ) {
 
118
  return false;
119
  }
120
 
@@ -132,8 +143,15 @@ class SB_Instagram_Single
132
 
133
  if ( $data && isset( $data['error'] ) ) {
134
  $this->add_oembed_request_delay();
 
135
  $data = false;
136
  }
 
 
 
 
 
 
137
  }
138
 
139
  return $data;
28
  */
29
  private $post;
30
 
31
+ /**
32
+ * @var array
33
+ */
34
+ private $error;
35
+
36
  /**
37
  * SB_Instagram_Single constructor.
38
  *
49
  $this->permalink_id = $permalink_or_permalink_id;
50
  $this->permalink = 'https://www.instagram.com/p/' . $this->permalink_id;
51
  }
52
+ $this->error = false;
53
  }
54
 
55
  /**
90
  return $this->post;
91
  }
92
 
93
+ public function get_error() {
94
+ return $this->error;
95
+ }
96
+
97
  /**
98
  * Image URLs expire so this will compare when the data
99
  * was last updated from the API
125
  $access_token = SB_Instagram_Oembed::last_access_token();
126
 
127
  if ( empty( $access_token ) ) {
128
+ $this->error = 'No access token';
129
  return false;
130
  }
131
 
143
 
144
  if ( $data && isset( $data['error'] ) ) {
145
  $this->add_oembed_request_delay();
146
+ $this->error = sprintf( __( 'API error %s:', 'instagram-feed' ), $data['error']['code'] ) . ' ' . $data['error']['message'];
147
  $data = false;
148
  }
149
+ } else {
150
+ $error = '';
151
+ foreach ( $result->errors as $key => $item ) {
152
+ $error .= $key . ' - ' . $item[0] . ' ';
153
+ }
154
+ $this->error = $error;
155
  }
156
 
157
  return $data;
instagram-feed.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Smash Balloon Instagram Feed
4
  Plugin URI: https://smashballoon.com/instagram-feed
5
  Description: Display beautifully clean, customizable, and responsive Instagram feeds.
6
- Version: 2.5.3
7
  Author: Smash Balloon
8
  Author URI: https://smashballoon.com/
9
  License: GPLv2 or later
@@ -23,7 +23,7 @@ along with this program; if not, write to the Free Software
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
  if ( ! defined( 'SBIVER' ) ) {
26
- define( 'SBIVER', '2.5.3' );
27
  }
28
  // Db version.
29
  if ( ! defined( 'SBI_DBVERSION' ) ) {
3
  Plugin Name: Smash Balloon Instagram Feed
4
  Plugin URI: https://smashballoon.com/instagram-feed
5
  Description: Display beautifully clean, customizable, and responsive Instagram feeds.
6
+ Version: 2.5.4
7
  Author: Smash Balloon
8
  Author URI: https://smashballoon.com/
9
  License: GPLv2 or later
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
  if ( ! defined( 'SBIVER' ) ) {
26
+ define( 'SBIVER', '2.5.4' );
27
  }
28
  // Db version.
29
  if ( ! defined( 'SBI_DBVERSION' ) ) {