WP Instagram Widget - Version 2.0.1

Version Description

  • Fix hashtag support
Download this release

Release Info

Developer scottsweb
Plugin Icon 128x128 WP Instagram Widget
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

Files changed (3) hide show
  1. readme.md +29 -24
  2. readme.txt +10 -5
  3. wp-instagram-widget.php +90 -53
readme.md CHANGED
@@ -51,9 +51,11 @@ The second allows you to filter video results from the widget:
51
  add_filter('wpiw_images_only', '__return_true');
52
  ```
53
 
54
- The rest allow you to add custom classes to each list item, link or image:
55
 
56
  ```
 
 
57
  add_filter( 'wpiw_item_class', 'my_instagram_class' );
58
  add_filter( 'wpiw_a_class', 'my_instagram_class' );
59
  add_filter( 'wpiw_img_class', 'my_instagram_class' );
@@ -82,97 +84,100 @@ In version 1.9.6 you can now use a filter to change the location of your custom
82
 
83
  ## Changelog
84
 
85
- ####2.0.0
 
 
 
86
  * Ability to track tags / hashtags instead of just usernames (e.g. #cheese)
87
  * New filter for custom link class
88
  * Bundle German language (props jensteichert)
89
  * Other minor fixes and formatting
90
 
91
- ####1.9.8
92
  * Return more items when using filter for images only
93
 
94
- ####1.9.7
95
  * Fix double trailing slash on custom text link
96
 
97
- ####1.9.6
98
  * Trailing slash all URLs to support Instagram app on iOS
99
  * Support selective refresh in 4.5
100
  * New filter for `wpiw_template_part`
101
 
102
- ####1.9.5
103
  * Another fix for image URL handling, I think we have all the edge cases now!
104
 
105
- ####1.9.4
106
  * IMPORTANT: You must be on WordPress 4.4 or later to upgrade to this version of the plugin. This fixes a bug with PHP versions < 5.4.7. If you are on a version of WordPress older than 4.4 and you notice images are not loading then I recommend rolling your version of the widget back to this version: https://github.com/scottsweb/wp-instagram-widget/blob/c66550eded59bd51f508f304a85a3e031ac4044c/wp-instagram-widget.php
107
 
108
- ####1.9.3
109
  * Fix issues introduced in the last version (apologies). Certain CDN URLs are still in use
110
 
111
- ####1.9.2
112
  * Better handling of all image and video image URLs props @thegallagher
113
 
114
- ####1.9.1
115
  * Fix bug with some image URLs
116
 
117
- ####1.9
118
  * WordPress.com VIP checked
119
  * Updated CDN matching to ensure correct image sizes are served at all times
120
  * Shortened the transient key - should mean we bump into the character limit less often
121
  * Remove use of `extract`
122
 
123
- ####1.8.1
124
  * Apologies for all the recent updates, all good things though!
125
  * Update plugin text domain ready for translate.wordpress.org
126
  * Introduce an 'original' image size if you want to use non-square originals
127
  * Introduce new filter for `<ul>` class `wpiw_list_class`
128
 
129
- ####1.8
130
  * Bring back image captions
131
  * Fix small PHP error in 1.7
132
 
133
- ####1.7
134
  * Bring back image sizes
135
  * Use thumbnails that are square (originals are in the data returned and can be used)
136
  * Remove @ from usernames
137
 
138
- ####1.6
139
  * Compatibility with 4.3
140
 
141
- ####1.5.1
142
  * Invalidate old transients
143
 
144
- ####1.5
145
  * Remove null framework support
146
  * Fix breaking change by Instagram whilst maintaining old style support
147
  * Remove thumbnail size option
148
 
149
- ####1.4
150
  * Introduce class filters
151
  * Only set a transient if images are returned
152
  * Optional template part for complete output control
153
 
154
- ####1.3.1
155
  * Force lowercase usernames
156
  * Correct hook name
157
 
158
- ####1.3
159
  * Option to open links in new window
160
  * Support for video items (with filter to disable this)
161
  * New actions for adding custom output to the widget
162
  * Support for https://
163
  * Correctly escape attributes
164
 
165
- ####1.2.1
166
  * Change transient name due to data change
167
 
168
- ####1.2
169
  * Better error handling
170
  * Encode emoji as they cause transient issues
171
 
172
- ####1.1
173
  * Fix issue with Instagram feed
174
  * Add composer.json
175
 
176
- ####1.0
177
  * Initial release
178
 
51
  add_filter('wpiw_images_only', '__return_true');
52
  ```
53
 
54
+ The rest allow you to add custom classes to the [ul] list container, each list item, link or image:
55
 
56
  ```
57
+ add_filter( 'wpiw_list_class', 'my_instagram_class' );
58
+
59
  add_filter( 'wpiw_item_class', 'my_instagram_class' );
60
  add_filter( 'wpiw_a_class', 'my_instagram_class' );
61
  add_filter( 'wpiw_img_class', 'my_instagram_class' );
84
 
85
  ## Changelog
86
 
87
+ #### 2.0.1
88
+ * Fix hashtag support
89
+
90
+ #### 2.0.0
91
  * Ability to track tags / hashtags instead of just usernames (e.g. #cheese)
92
  * New filter for custom link class
93
  * Bundle German language (props jensteichert)
94
  * Other minor fixes and formatting
95
 
96
+ #### 1.9.8
97
  * Return more items when using filter for images only
98
 
99
+ #### 1.9.7
100
  * Fix double trailing slash on custom text link
101
 
102
+ #### 1.9.6
103
  * Trailing slash all URLs to support Instagram app on iOS
104
  * Support selective refresh in 4.5
105
  * New filter for `wpiw_template_part`
106
 
107
+ #### 1.9.5
108
  * Another fix for image URL handling, I think we have all the edge cases now!
109
 
110
+ #### 1.9.4
111
  * IMPORTANT: You must be on WordPress 4.4 or later to upgrade to this version of the plugin. This fixes a bug with PHP versions < 5.4.7. If you are on a version of WordPress older than 4.4 and you notice images are not loading then I recommend rolling your version of the widget back to this version: https://github.com/scottsweb/wp-instagram-widget/blob/c66550eded59bd51f508f304a85a3e031ac4044c/wp-instagram-widget.php
112
 
113
+ #### 1.9.3
114
  * Fix issues introduced in the last version (apologies). Certain CDN URLs are still in use
115
 
116
+ #### 1.9.2
117
  * Better handling of all image and video image URLs props @thegallagher
118
 
119
+ #### 1.9.1
120
  * Fix bug with some image URLs
121
 
122
+ #### 1.9
123
  * WordPress.com VIP checked
124
  * Updated CDN matching to ensure correct image sizes are served at all times
125
  * Shortened the transient key - should mean we bump into the character limit less often
126
  * Remove use of `extract`
127
 
128
+ #### 1.8.1
129
  * Apologies for all the recent updates, all good things though!
130
  * Update plugin text domain ready for translate.wordpress.org
131
  * Introduce an 'original' image size if you want to use non-square originals
132
  * Introduce new filter for `<ul>` class `wpiw_list_class`
133
 
134
+ #### 1.8
135
  * Bring back image captions
136
  * Fix small PHP error in 1.7
137
 
138
+ #### 1.7
139
  * Bring back image sizes
140
  * Use thumbnails that are square (originals are in the data returned and can be used)
141
  * Remove @ from usernames
142
 
143
+ #### 1.6
144
  * Compatibility with 4.3
145
 
146
+ #### 1.5.1
147
  * Invalidate old transients
148
 
149
+ #### 1.5
150
  * Remove null framework support
151
  * Fix breaking change by Instagram whilst maintaining old style support
152
  * Remove thumbnail size option
153
 
154
+ #### 1.4
155
  * Introduce class filters
156
  * Only set a transient if images are returned
157
  * Optional template part for complete output control
158
 
159
+ #### 1.3.1
160
  * Force lowercase usernames
161
  * Correct hook name
162
 
163
+ #### 1.3
164
  * Option to open links in new window
165
  * Support for video items (with filter to disable this)
166
  * New actions for adding custom output to the widget
167
  * Support for https://
168
  * Correctly escape attributes
169
 
170
+ #### 1.2.1
171
  * Change transient name due to data change
172
 
173
+ #### 1.2
174
  * Better error handling
175
  * Encode emoji as they cause transient issues
176
 
177
+ #### 1.1
178
  * Fix issue with Instagram feed
179
  * Add composer.json
180
 
181
+ #### 1.0
182
  * Initial release
183
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: scottsweb, codeforthepeople
3
  Tags: instagram, widget, photos, photography, hipster, sidebar, widgets, simple
4
  Requires at least: 4.4
5
- Tested up to: 4.8.2
6
- Stable tag: 2.0.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -49,9 +49,11 @@ The second allows you to filter video results from the widget:
49
 
50
  `add_filter('wpiw_images_only', '__return_true');`
51
 
52
- The rest allow you to add custom classes to each list item, link or image:
53
 
54
- `add_filter( 'wpiw_item_class', 'my_instagram_class' );
 
 
55
  add_filter( 'wpiw_a_class', 'my_instagram_class' );
56
  add_filter( 'wpiw_img_class', 'my_instagram_class' );
57
  add_filter( 'wpiw_linka_class', 'my_instagram_class' );
@@ -78,6 +80,9 @@ In version 1.9.6 you can now use a filter to change the location of your custom
78
 
79
  == Changelog ==
80
 
 
 
 
81
  = 2.0.0 =
82
  * Ability to track tags / hashtags instead of just usernames (e.g. #cheese)
83
  * New filter for custom link class
@@ -120,7 +125,7 @@ In version 1.9.6 you can now use a filter to change the location of your custom
120
  * Apologies for all the recent updates, all good things though!
121
  * Update plugin text domain ready for translate.wordpress.org
122
  * Introduce an 'original' image size if you want to use non-square originals
123
- * Introduce new filter for <ul> class `wpiw_list_class`
124
 
125
  = 1.8 =
126
  * Bring back image captions
2
  Contributors: scottsweb, codeforthepeople
3
  Tags: instagram, widget, photos, photography, hipster, sidebar, widgets, simple
4
  Requires at least: 4.4
5
+ Tested up to: 4.9.1
6
+ Stable tag: 2.0.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
49
 
50
  `add_filter('wpiw_images_only', '__return_true');`
51
 
52
+ The rest allow you to add custom classes to the [ul] list container, each list item, link or image:
53
 
54
+ `add_filter( 'wpiw_list_class', 'my_instagram_class' );
55
+
56
+ add_filter( 'wpiw_item_class', 'my_instagram_class' );
57
  add_filter( 'wpiw_a_class', 'my_instagram_class' );
58
  add_filter( 'wpiw_img_class', 'my_instagram_class' );
59
  add_filter( 'wpiw_linka_class', 'my_instagram_class' );
80
 
81
  == Changelog ==
82
 
83
+ = 2.0.1 =
84
+ * Fix hashtag support
85
+
86
  = 2.0.0 =
87
  * Ability to track tags / hashtags instead of just usernames (e.g. #cheese)
88
  * New filter for custom link class
125
  * Apologies for all the recent updates, all good things though!
126
  * Update plugin text domain ready for translate.wordpress.org
127
  * Introduce an 'original' image size if you want to use non-square originals
128
+ * Introduce new filter for `<ul>` class `wpiw_list_class`
129
 
130
  = 1.8 =
131
  * Bring back image captions
wp-instagram-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Instagram Widget
4
  Plugin URI: https://github.com/scottsweb/wp-instagram-widget
5
  Description: A WordPress widget for showing your latest Instagram photos.
6
- Version: 2.0.0
7
  Author: Scott Evans
8
  Author URI: https://scott.ee
9
  Text Domain: wp-instagram-widget
@@ -135,7 +135,14 @@ Class null_instagram_widget extends WP_Widget {
135
  }
136
 
137
  function form( $instance ) {
138
- $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Instagram', 'wp-instagram-widget' ), 'username' => '', 'size' => 'large', 'link' => __( 'Follow Me!', 'wp-instagram-widget' ), 'number' => 9, 'target' => '_self' ) );
 
 
 
 
 
 
 
139
  $title = $instance['title'];
140
  $username = $instance['username'];
141
  $number = absint( $instance['number'] );
@@ -148,16 +155,16 @@ Class null_instagram_widget extends WP_Widget {
148
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php esc_html_e( 'Number of photos', 'wp-instagram-widget' ); ?>: <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" /></label></p>
149
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Photo size', 'wp-instagram-widget' ); ?>:</label>
150
  <select id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" class="widefat">
151
- <option value="thumbnail" <?php selected( 'thumbnail', $size ) ?>><?php esc_html_e( 'Thumbnail', 'wp-instagram-widget' ); ?></option>
152
- <option value="small" <?php selected( 'small', $size ) ?>><?php esc_html_e( 'Small', 'wp-instagram-widget' ); ?></option>
153
- <option value="large" <?php selected( 'large', $size ) ?>><?php esc_html_e( 'Large', 'wp-instagram-widget' ); ?></option>
154
- <option value="original" <?php selected( 'original', $size ) ?>><?php esc_html_e( 'Original', 'wp-instagram-widget' ); ?></option>
155
  </select>
156
  </p>
157
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>"><?php esc_html_e( 'Open links in', 'wp-instagram-widget' ); ?>:</label>
158
  <select id="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'target' ) ); ?>" class="widefat">
159
- <option value="_self" <?php selected( '_self', $target ) ?>><?php esc_html_e( 'Current window (_self)', 'wp-instagram-widget' ); ?></option>
160
- <option value="_blank" <?php selected( '_blank', $target ) ?>><?php esc_html_e( 'New window (_blank)', 'wp-instagram-widget' ); ?></option>
161
  </select>
162
  </p>
163
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>"><?php esc_html_e( 'Link text', 'wp-instagram-widget' ); ?>: <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'link' ) ); ?>" type="text" value="<?php echo esc_attr( $link ); ?>" /></label></p>
@@ -181,7 +188,7 @@ Class null_instagram_widget extends WP_Widget {
181
 
182
  $username = trim( strtolower( $username ) );
183
 
184
- if ( false === ( $instagram = get_transient( 'instagram-a7-' . sanitize_title_with_dashes( $username ) ) ) ) {
185
 
186
  switch ( substr( $username, 0, 1 ) ) {
187
  case '#':
@@ -213,8 +220,8 @@ Class null_instagram_widget extends WP_Widget {
213
 
214
  if ( isset( $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'] ) ) {
215
  $images = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
216
- } else if ( isset( $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'] ) ) {
217
- $images = $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'];
218
  } else {
219
  return new WP_Error( 'bad_json_2', esc_html__( 'Instagram has returned invalid data.', 'wp-instagram-widget' ) );
220
  }
@@ -226,54 +233,84 @@ Class null_instagram_widget extends WP_Widget {
226
  $instagram = array();
227
 
228
  foreach ( $images as $image ) {
229
-
230
- $image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['thumbnail_src'] );
231
- $image['display_src'] = preg_replace( '/^https?\:/i', '', $image['display_src'] );
232
-
233
- // handle both types of CDN url.
234
- if ( ( strpos( $image['thumbnail_src'], 's640x640' ) !== false ) ) {
235
- $image['thumbnail'] = str_replace( 's640x640', 's160x160', $image['thumbnail_src'] );
236
- $image['small'] = str_replace( 's640x640', 's320x320', $image['thumbnail_src'] );
237
- } else {
238
- $urlparts = wp_parse_url( $image['thumbnail_src'] );
239
- $pathparts = explode( '/', $urlparts['path'] );
240
- array_splice( $pathparts, 3, 0, array( 's160x160' ) );
241
- $image['thumbnail'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
242
- $pathparts[3] = 's320x320';
243
- $image['small'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
244
- }
245
-
246
- $image['large'] = $image['thumbnail_src'];
247
-
248
- if ( true === $image['is_video'] ) {
249
- $type = 'video';
250
- } else {
251
- $type = 'image';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
253
-
254
- $caption = __( 'Instagram Image', 'wp-instagram-widget' );
255
- if ( ! empty( $image['caption'] ) ) {
256
- $caption = $image['caption'];
257
- }
258
-
259
- $instagram[] = array(
260
- 'description' => $caption,
261
- 'link' => trailingslashit( '//instagram.com/p/' . $image['code'] ),
262
- 'time' => $image['date'],
263
- 'comments' => $image['comments']['count'],
264
- 'likes' => $image['likes']['count'],
265
- 'thumbnail' => $image['thumbnail'],
266
- 'small' => $image['small'],
267
- 'large' => $image['large'],
268
- 'original' => $image['display_src'],
269
- 'type' => $type,
270
- );
271
  } // End foreach().
272
 
273
  // do not set an empty transient - should help catch private or empty accounts.
274
  if ( ! empty( $instagram ) ) {
275
  $instagram = base64_encode( serialize( $instagram ) );
276
- set_transient( 'instagram-a7-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
277
  }
278
  }
279
 
3
  Plugin Name: WP Instagram Widget
4
  Plugin URI: https://github.com/scottsweb/wp-instagram-widget
5
  Description: A WordPress widget for showing your latest Instagram photos.
6
+ Version: 2.0.1
7
  Author: Scott Evans
8
  Author URI: https://scott.ee
9
  Text Domain: wp-instagram-widget
135
  }
136
 
137
  function form( $instance ) {
138
+ $instance = wp_parse_args( (array) $instance, array(
139
+ 'title' => __( 'Instagram', 'wp-instagram-widget' ),
140
+ 'username' => '',
141
+ 'size' => 'large',
142
+ 'link' => __( 'Follow Me!', 'wp-instagram-widget' ),
143
+ 'number' => 9,
144
+ 'target' => '_self',
145
+ ) );
146
  $title = $instance['title'];
147
  $username = $instance['username'];
148
  $number = absint( $instance['number'] );
155
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php esc_html_e( 'Number of photos', 'wp-instagram-widget' ); ?>: <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" /></label></p>
156
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Photo size', 'wp-instagram-widget' ); ?>:</label>
157
  <select id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" class="widefat">
158
+ <option value="thumbnail" <?php selected( 'thumbnail', $size ); ?>><?php esc_html_e( 'Thumbnail', 'wp-instagram-widget' ); ?></option>
159
+ <option value="small" <?php selected( 'small', $size ); ?>><?php esc_html_e( 'Small', 'wp-instagram-widget' ); ?></option>
160
+ <option value="large" <?php selected( 'large', $size ); ?>><?php esc_html_e( 'Large', 'wp-instagram-widget' ); ?></option>
161
+ <option value="original" <?php selected( 'original', $size ); ?>><?php esc_html_e( 'Original', 'wp-instagram-widget' ); ?></option>
162
  </select>
163
  </p>
164
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>"><?php esc_html_e( 'Open links in', 'wp-instagram-widget' ); ?>:</label>
165
  <select id="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'target' ) ); ?>" class="widefat">
166
+ <option value="_self" <?php selected( '_self', $target ); ?>><?php esc_html_e( 'Current window (_self)', 'wp-instagram-widget' ); ?></option>
167
+ <option value="_blank" <?php selected( '_blank', $target ); ?>><?php esc_html_e( 'New window (_blank)', 'wp-instagram-widget' ); ?></option>
168
  </select>
169
  </p>
170
  <p><label for="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>"><?php esc_html_e( 'Link text', 'wp-instagram-widget' ); ?>: <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'link' ) ); ?>" type="text" value="<?php echo esc_attr( $link ); ?>" /></label></p>
188
 
189
  $username = trim( strtolower( $username ) );
190
 
191
+ if ( false === ( $instagram = get_transient( 'instagram-a8-' . sanitize_title_with_dashes( $username ) ) ) ) {
192
 
193
  switch ( substr( $username, 0, 1 ) ) {
194
  case '#':
220
 
221
  if ( isset( $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'] ) ) {
222
  $images = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
223
+ } elseif ( isset( $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'] ) ) {
224
+ $images = $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'];
225
  } else {
226
  return new WP_Error( 'bad_json_2', esc_html__( 'Instagram has returned invalid data.', 'wp-instagram-widget' ) );
227
  }
233
  $instagram = array();
234
 
235
  foreach ( $images as $image ) {
236
+ // the hashtag json is now completely different
237
+ switch ( substr( $username, 0, 1 ) ) {
238
+ case '#':
239
+ if ( true === $image['node']['is_video'] ) {
240
+ $type = 'video';
241
+ } else {
242
+ $type = 'image';
243
+ }
244
+
245
+ $caption = __( 'Instagram Image', 'wp-instagram-widget' );
246
+ if ( ! empty( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'] ) ) {
247
+ $caption = $image['node']['edge_media_to_caption']['edges'][0]['node']['text'];
248
+ }
249
+
250
+ $instagram[] = array(
251
+ 'description' => $caption,
252
+ 'link' => trailingslashit( '//instagram.com/p/' . $image['node']['shortcode'] ),
253
+ 'time' => $image['node']['taken_at_timestamp'],
254
+ 'comments' => $image['node']['edge_media_to_comment']['count'],
255
+ 'likes' => $image['node']['edge_liked_by']['count'],
256
+ 'thumbnail' => str_replace( 's150x150', 's160x160', preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] ) ),
257
+ 'small' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][2]['src'] ),
258
+ 'large' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][4]['src'] ),
259
+ 'original' => preg_replace( '/^https?\:/i', '', $image['node']['display_url'] ),
260
+ 'type' => $type,
261
+ );
262
+ break;
263
+ default:
264
+ $image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['thumbnail_src'] );
265
+ $image['display_src'] = preg_replace( '/^https?\:/i', '', $image['display_src'] );
266
+
267
+ // handle both types of CDN url.
268
+ if ( ( strpos( $image['thumbnail_src'], 's640x640' ) !== false ) ) {
269
+ $image['thumbnail'] = str_replace( 's640x640', 's160x160', $image['thumbnail_src'] );
270
+ $image['small'] = str_replace( 's640x640', 's320x320', $image['thumbnail_src'] );
271
+ } else {
272
+ $urlparts = wp_parse_url( $image['thumbnail_src'] );
273
+ $pathparts = explode( '/', $urlparts['path'] );
274
+ array_splice( $pathparts, 3, 0, array( 's160x160' ) );
275
+ $image['thumbnail'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
276
+ $pathparts[3] = 's320x320';
277
+ $image['small'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
278
+ }
279
+
280
+ $image['large'] = $image['thumbnail_src'];
281
+
282
+ if ( true === $image['is_video'] ) {
283
+ $type = 'video';
284
+ } else {
285
+ $type = 'image';
286
+ }
287
+
288
+ $caption = __( 'Instagram Image', 'wp-instagram-widget' );
289
+ if ( ! empty( $image['caption'] ) ) {
290
+ $caption = $image['caption'];
291
+ }
292
+
293
+ $instagram[] = array(
294
+ 'description' => $caption,
295
+ 'link' => trailingslashit( '//instagram.com/p/' . $image['code'] ),
296
+ 'time' => $image['date'],
297
+ 'comments' => $image['comments']['count'],
298
+ 'likes' => $image['likes']['count'],
299
+ 'thumbnail' => $image['thumbnail'],
300
+ 'small' => $image['small'],
301
+ 'large' => $image['large'],
302
+ 'original' => $image['display_src'],
303
+ 'type' => $type,
304
+ );
305
+
306
+ break;
307
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  } // End foreach().
309
 
310
  // do not set an empty transient - should help catch private or empty accounts.
311
  if ( ! empty( $instagram ) ) {
312
  $instagram = base64_encode( serialize( $instagram ) );
313
+ set_transient( 'instagram-a8-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
314
  }
315
  }
316