WP Instagram Widget - Version 2.0.3

Version Description

  • New JSON on the Instagram end, fixes broken usernames
  • Support same tag and username
Download this release

Release Info

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

Code changes from version 2.0.2 to 2.0.3

assets/languages/wp-instagram-widget-fr_FR.mo ADDED
Binary file
assets/languages/wp-instagram-widget-fr_FR.po ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: WP Instagram Widget\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2017-09-21 10:19+0100\n"
6
+ "PO-Revision-Date: 2018-01-29 10:59-0500\n"
7
+ "Last-Translator: Scott Evans @scottsweb <translate@scott.ee>\n"
8
+ "Language-Team: @scottsweb <translate@scott.ee>\n"
9
+ "Language: en_GB\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
14
+ "X-Poedit-KeywordsList: __;_e;_x;esc_html_e;esc_html__;esc_attr_e;esc_attr__;"
15
+ "_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2;_n_noop:1,2;"
16
+ "__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
17
+ "X-Poedit-Basepath: ../..\n"
18
+ "X-Poedit-SourceCharset: utf-8\n"
19
+ "X-Generator: Poedit 2.0.6\n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+
22
+ #: wp-instagram-widget.php:53 wp-instagram-widget.php:138
23
+ msgid "Instagram"
24
+ msgstr "Instagram"
25
+
26
+ #: wp-instagram-widget.php:56
27
+ msgid "Displays your latest Instagram photos"
28
+ msgstr "Affichez vos dernières photos Instagram"
29
+
30
+ #: wp-instagram-widget.php:138
31
+ msgid "Follow Me!"
32
+ msgstr "Suivez moi!"
33
+
34
+ #: wp-instagram-widget.php:146
35
+ msgid "Title"
36
+ msgstr "Titre"
37
+
38
+ #: wp-instagram-widget.php:147
39
+ msgid "@username or #tag"
40
+ msgstr "@nomutilisateur ou #tag"
41
+
42
+ #: wp-instagram-widget.php:148
43
+ msgid "Number of photos"
44
+ msgstr "Nombre de photos"
45
+
46
+ #: wp-instagram-widget.php:149
47
+ msgid "Photo size"
48
+ msgstr "Taille des photos"
49
+
50
+ #: wp-instagram-widget.php:151
51
+ msgid "Thumbnail"
52
+ msgstr "Miniature"
53
+
54
+ #: wp-instagram-widget.php:152
55
+ msgid "Small"
56
+ msgstr "Petit"
57
+
58
+ #: wp-instagram-widget.php:153
59
+ msgid "Large"
60
+ msgstr "Large"
61
+
62
+ #: wp-instagram-widget.php:154
63
+ msgid "Original"
64
+ msgstr "Originale"
65
+
66
+ #: wp-instagram-widget.php:157
67
+ msgid "Open links in"
68
+ msgstr "Ouvrir les liens vers"
69
+
70
+ #: wp-instagram-widget.php:159
71
+ msgid "Current window (_self)"
72
+ msgstr "Fenêtre courante (_self)"
73
+
74
+ #: wp-instagram-widget.php:160
75
+ msgid "New window (_blank)"
76
+ msgstr "Nouvelle fenêtre (_blank)"
77
+
78
+ #: wp-instagram-widget.php:163
79
+ msgid "Link text"
80
+ msgstr "Texte du lien"
81
+
82
+ #: wp-instagram-widget.php:199
83
+ msgid "Unable to communicate with Instagram."
84
+ msgstr "Impossible de communiquer avec Instagram."
85
+
86
+ #: wp-instagram-widget.php:203
87
+ msgid "Instagram did not return a 200."
88
+ msgstr "Instagram n'a pas retourné le status 200."
89
+
90
+ #: wp-instagram-widget.php:211 wp-instagram-widget.php:219
91
+ #: wp-instagram-widget.php:223
92
+ msgid "Instagram has returned invalid data."
93
+ msgstr "Instagram a retourné des données invalides."
94
+
95
+ #: wp-instagram-widget.php:254
96
+ msgid "Instagram Image"
97
+ msgstr "Image Instagram"
98
+
99
+ #: wp-instagram-widget.php:286
100
+ msgid "Instagram did not return any images."
101
+ msgstr "Instagram n'a retourné aucune image."
readme.md CHANGED
@@ -84,6 +84,10 @@ In version 1.9.6 you can now use a filter to change the location of your custom
84
 
85
  ## Changelog
86
 
 
 
 
 
87
  #### 2.0.2
88
  * Use image sizes from JSON due to errors loading images
89
 
84
 
85
  ## Changelog
86
 
87
+ #### 2.0.3
88
+ * New JSON on the Instagram end, fixes broken usernames
89
+ * Support same tag and username
90
+
91
  #### 2.0.2
92
  * Use image sizes from JSON due to errors loading images
93
 
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.9.1
6
- Stable tag: 2.0.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -80,6 +80,10 @@ In version 1.9.6 you can now use a filter to change the location of your custom
80
 
81
  == Changelog ==
82
 
 
 
 
 
83
  = 2.0.2 =
84
  * Use image sizes from JSON due to errors loading images
85
 
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.4
6
+ Stable tag: 2.0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
80
 
81
  == Changelog ==
82
 
83
+ = 2.0.3 =
84
+ * New JSON on the Instagram end, fixes broken usernames
85
+ * Support same tag and username
86
+
87
  = 2.0.2 =
88
  * Use image sizes from JSON due to errors loading images
89
 
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.2
7
  Author: Scott Evans
8
  Author URI: https://scott.ee
9
  Text Domain: wp-instagram-widget
@@ -188,17 +188,19 @@ Class null_instagram_widget extends WP_Widget {
188
 
189
  $username = trim( strtolower( $username ) );
190
 
191
- if ( false === ( $instagram = get_transient( 'instagram-a9-' . sanitize_title_with_dashes( $username ) ) ) ) {
 
 
 
 
192
 
193
- switch ( substr( $username, 0, 1 ) ) {
194
- case '#':
195
- $url = 'https://instagram.com/explore/tags/' . str_replace( '#', '', $username );
196
- break;
 
197
 
198
- default:
199
- $url = 'https://instagram.com/' . str_replace( '@', '', $username );
200
- break;
201
- }
202
 
203
  $remote = wp_remote_get( $url );
204
 
@@ -210,16 +212,16 @@ Class null_instagram_widget extends WP_Widget {
210
  return new WP_Error( 'invalid_response', esc_html__( 'Instagram did not return a 200.', 'wp-instagram-widget' ) );
211
  }
212
 
213
- $shards = explode( 'window._sharedData = ', $remote['body'] );
214
- $insta_json = explode( ';</script>', $shards[1] );
215
  $insta_array = json_decode( $insta_json[0], true );
216
 
217
  if ( ! $insta_array ) {
218
  return new WP_Error( 'bad_json', esc_html__( 'Instagram has returned invalid data.', 'wp-instagram-widget' ) );
219
  }
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 {
@@ -233,67 +235,35 @@ Class null_instagram_widget extends WP_Widget {
233
  $instagram = array();
234
 
235
  foreach ( $images as $image ) {
236
- // Note: keep hashtag support different until these JSON changes stabalise
237
- // these are mostly the same again now
238
- switch ( substr( $username, 0, 1 ) ) {
239
- case '#':
240
- if ( true === $image['node']['is_video'] ) {
241
- $type = 'video';
242
- } else {
243
- $type = 'image';
244
- }
245
-
246
- $caption = __( 'Instagram Image', 'wp-instagram-widget' );
247
- if ( ! empty( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'] ) ) {
248
- $caption = $image['node']['edge_media_to_caption']['edges'][0]['node']['text'];
249
- }
250
-
251
- $instagram[] = array(
252
- 'description' => $caption,
253
- 'link' => trailingslashit( '//instagram.com/p/' . $image['node']['shortcode'] ),
254
- 'time' => $image['node']['taken_at_timestamp'],
255
- 'comments' => $image['node']['edge_media_to_comment']['count'],
256
- 'likes' => $image['node']['edge_liked_by']['count'],
257
- 'thumbnail' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] ),
258
- 'small' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][2]['src'] ),
259
- 'large' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][4]['src'] ),
260
- 'original' => preg_replace( '/^https?\:/i', '', $image['node']['display_url'] ),
261
- 'type' => $type,
262
- );
263
- break;
264
- default:
265
- if ( true === $image['is_video'] ) {
266
- $type = 'video';
267
- } else {
268
- $type = 'image';
269
- }
270
-
271
- $caption = __( 'Instagram Image', 'wp-instagram-widget' );
272
- if ( ! empty( $image['caption'] ) ) {
273
- $caption = $image['caption'];
274
- }
275
-
276
- $instagram[] = array(
277
- 'description' => $caption,
278
- 'link' => trailingslashit( '//instagram.com/p/' . $image['code'] ),
279
- 'time' => $image['date'],
280
- 'comments' => $image['comments']['count'],
281
- 'likes' => $image['likes']['count'],
282
- 'thumbnail' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][0]['src'] ),
283
- 'small' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][2]['src'] ),
284
- 'large' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][4]['src'] ),
285
- 'original' => preg_replace( '/^https?\:/i', '', $image['display_src'] ),
286
- 'type' => $type,
287
- );
288
-
289
- break;
290
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  } // End foreach().
292
 
293
  // do not set an empty transient - should help catch private or empty accounts.
294
  if ( ! empty( $instagram ) ) {
295
  $instagram = base64_encode( serialize( $instagram ) );
296
- set_transient( 'instagram-a9-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
297
  }
298
  }
299
 
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.3
7
  Author: Scott Evans
8
  Author URI: https://scott.ee
9
  Text Domain: wp-instagram-widget
188
 
189
  $username = trim( strtolower( $username ) );
190
 
191
+ switch ( substr( $username, 0, 1 ) ) {
192
+ case '#':
193
+ $url = 'https://instagram.com/explore/tags/' . str_replace( '#', '', $username );
194
+ $transient_prefix = 'h';
195
+ break;
196
 
197
+ default:
198
+ $url = 'https://instagram.com/' . str_replace( '@', '', $username );
199
+ $transient_prefix = 'u';
200
+ break;
201
+ }
202
 
203
+ if ( false === ( $instagram = get_transient( 'insta-a10-' . $transient_prefix . '-' . sanitize_title_with_dashes( $username ) ) ) ) {
 
 
 
204
 
205
  $remote = wp_remote_get( $url );
206
 
212
  return new WP_Error( 'invalid_response', esc_html__( 'Instagram did not return a 200.', 'wp-instagram-widget' ) );
213
  }
214
 
215
+ $shards = explode( 'window._sharedData = ', $remote['body'] );
216
+ $insta_json = explode( ';</script>', $shards[1] );
217
  $insta_array = json_decode( $insta_json[0], true );
218
 
219
  if ( ! $insta_array ) {
220
  return new WP_Error( 'bad_json', esc_html__( 'Instagram has returned invalid data.', 'wp-instagram-widget' ) );
221
  }
222
 
223
+ if ( isset( $insta_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'] ) ) {
224
+ $images = $insta_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'];
225
  } elseif ( isset( $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'] ) ) {
226
  $images = $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'];
227
  } else {
235
  $instagram = array();
236
 
237
  foreach ( $images as $image ) {
238
+ if ( true === $image['node']['is_video'] ) {
239
+ $type = 'video';
240
+ } else {
241
+ $type = 'image';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
+
244
+ $caption = __( 'Instagram Image', 'wp-instagram-widget' );
245
+ if ( ! empty( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'] ) ) {
246
+ $caption = wp_kses( $image['node']['edge_media_to_caption']['edges'][0]['node']['text'], array() );
247
+ }
248
+
249
+ $instagram[] = array(
250
+ 'description' => $caption,
251
+ 'link' => trailingslashit( '//instagram.com/p/' . $image['node']['shortcode'] ),
252
+ 'time' => $image['node']['taken_at_timestamp'],
253
+ 'comments' => $image['node']['edge_media_to_comment']['count'],
254
+ 'likes' => $image['node']['edge_liked_by']['count'],
255
+ 'thumbnail' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] ),
256
+ 'small' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][2]['src'] ),
257
+ 'large' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][4]['src'] ),
258
+ 'original' => preg_replace( '/^https?\:/i', '', $image['node']['display_url'] ),
259
+ 'type' => $type,
260
+ );
261
  } // End foreach().
262
 
263
  // do not set an empty transient - should help catch private or empty accounts.
264
  if ( ! empty( $instagram ) ) {
265
  $instagram = base64_encode( serialize( $instagram ) );
266
+ set_transient( 'insta-a10-' . $transient_prefix . '-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
267
  }
268
  }
269