Image Widget - Version 4.4.2

Version Description

  • Fix - fixed compatibility with WordPress versions prior to 4.4
  • Fix - proportional scaling of image within the widget editor
  • Fix - fix validation by avoiding empty attributes and only specifying sizes with srcset (thanks Zodiak1978)
Download this release

Release Info

Developer zbtirrell
Plugin Icon 128x128 Image Widget
Version 4.4.2
Comparing to
See all releases

Code changes from version 4.4.1 to 4.4.2

Files changed (4) hide show
  1. image-widget.php +43 -46
  2. lang/image-widget.pot +16 -23
  3. readme.txt +11 -6
  4. resources/css/admin.css +23 -0
image-widget.php CHANGED
@@ -2,9 +2,9 @@
2
  /*
3
  Plugin Name: Image Widget
4
  Plugin URI: http://wordpress.org/plugins/image-widget/
5
- Description: A simple image widget that uses the native WordPress media manager to add image widgets to your site. <strong>COMING SOON: <a href="http://m.tri.be/19m-">Image Widget Plus</a> - Multiple images, slider and more.</strong>
6
  Author: Modern Tribe, Inc.
7
- Version: 4.4.1
8
  Author URI: http://m.tri.be/iwpdoc
9
  Text Domain: image-widget
10
  Domain Path: /lang
@@ -26,7 +26,7 @@ add_action( 'widgets_init', 'tribe_load_image_widget' );
26
  **/
27
  class Tribe_Image_Widget extends WP_Widget {
28
 
29
- const VERSION = '4.4.1';
30
 
31
  const CUSTOM_IMAGE_SIZE_SLUG = 'tribe_image_widget_custom';
32
 
@@ -47,9 +47,8 @@ class Tribe_Image_Widget extends WP_Widget {
47
  require_once( 'lib/ImageWidgetDeprecated.php' );
48
  new ImageWidgetDeprecated( $this );
49
  } else {
50
- add_action( 'sidebar_admin_setup', array( $this, 'admin_setup' ) );
51
  }
52
- add_action( 'admin_head-widgets.php', array( $this, 'admin_head' ) );
53
 
54
  add_action( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
55
 
@@ -70,10 +69,22 @@ class Tribe_Image_Widget extends WP_Widget {
70
  }
71
 
72
  /**
73
- * Enqueue all the javascript.
74
  */
75
  public function admin_setup() {
 
 
 
 
 
 
 
 
 
76
  wp_enqueue_media();
 
 
 
77
  wp_enqueue_script( 'tribe-image-widget', plugins_url( 'resources/js/image-widget.js', __FILE__ ), array( 'jquery', 'media-upload', 'media-views' ), self::VERSION );
78
 
79
  wp_localize_script( 'tribe-image-widget', 'TribeImageWidget', array(
@@ -181,37 +192,6 @@ class Tribe_Image_Widget extends WP_Widget {
181
  }
182
  }
183
 
184
- /**
185
- * Admin header css
186
- *
187
- * @author Modern Tribe, Inc.
188
- */
189
- public function admin_head() {
190
- ?>
191
- <style type="text/css">
192
- .uploader input.button {
193
- width: 100%;
194
- height: 34px;
195
- line-height: 33px;
196
- margin-top: 15px;
197
- }
198
- .tribe_preview .aligncenter {
199
- display: block;
200
- margin-left: auto !important;
201
- margin-right: auto !important;
202
- }
203
- .tribe_preview {
204
- overflow: hidden;
205
- max-height: 300px;
206
- }
207
- .tribe_preview img {
208
- margin: 10px 0;
209
- height: auto;
210
- }
211
- </style>
212
- <?php
213
- }
214
-
215
  /**
216
  * Render an array of default values.
217
  *
@@ -273,7 +253,9 @@ class Tribe_Image_Widget extends WP_Widget {
273
  $attr = array_map( 'esc_attr', $attr );
274
  $output = '<a';
275
  foreach ( $attr as $name => $value ) {
276
- $output .= sprintf( ' %s="%s"', $name, $value );
 
 
277
  }
278
  $output .= '>';
279
  }
@@ -291,39 +273,54 @@ class Tribe_Image_Widget extends WP_Widget {
291
  $instance['height'] = $image_details[2];
292
  }
293
 
294
- $image_srcset = wp_get_attachment_image_srcset( $instance['attachment_id'], $size );
 
 
295
  if ( $image_srcset ) {
296
  $instance['srcset'] = $image_srcset;
297
- }
298
 
299
- $image_sizes = wp_get_attachment_image_sizes( $instance['attachment_id'], $size );
300
- if ( $image_sizes ) {
301
- $instance['sizes'] = $image_sizes;
 
 
 
302
  }
303
  }
304
  $instance['width'] = abs( $instance['width'] );
305
  $instance['height'] = abs( $instance['height'] );
306
 
307
  $attr = array();
308
- $attr['alt'] = ( ! empty( $instance['alt'] ) ) ? $instance['alt'] : $instance['title'];
 
 
 
 
 
 
309
  if ( is_array( $size ) ) {
310
  $attr['class'] = 'attachment-' . join( 'x', $size );
311
  } else {
312
  $attr['class'] = 'attachment-' . $size;
313
  }
 
314
  $attr['style'] = '';
315
  if ( ! empty( $instance['maxwidth'] ) ) {
316
  $attr['style'] .= "max-width: {$instance['maxwidth']};";
317
  }
 
318
  if ( ! empty( $instance['maxheight'] ) ) {
319
  $attr['style'] .= "max-height: {$instance['maxheight']};";
320
  }
 
321
  if ( ! empty( $instance['align'] ) && $instance['align'] != 'none' ) {
322
  $attr['class'] .= " align{$instance['align']}";
323
  }
 
324
  if ( ! empty( $instance['srcset'] ) ) {
325
  $attr['srcset'] = $instance['srcset'];
326
  }
 
327
  if ( ! empty( $instance['sizes'] ) ) {
328
  $attr['sizes'] = $instance['sizes'];
329
  }
@@ -504,7 +501,7 @@ class Tribe_Image_Widget extends WP_Widget {
504
  $option_key = $this->generate_key( $key );
505
  if ( get_site_option( $option_key ) == self::VERSION ) return;
506
  $msg = sprintf(
507
- __( '<p class="dashicons-before dashicons-format-gallery"><strong><a href="%s" target="_blank">Image Widget Plus</a></strong> is coming soon! Add random images, lightbox, and slider - <strong><a href="%s">Sign up now for early access.</a></strong></p>', 'image-widget' ),
508
  'http://m.tri.be/19my',
509
  'http://m.tri.be/19my'
510
  );
@@ -536,7 +533,7 @@ class Tribe_Image_Widget extends WP_Widget {
536
  */
537
  public function plugin_row_meta( $meta, $file ) {
538
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/image-widget.php' ) ) {
539
- $meta[] = '<strong>' . esc_html__( 'Coming Soon:', 'image-widget' ) . '</strong> <a href="http://m.tri.be/19ma" target="_blank">' . esc_html__( 'Image Widget Plus', 'image-widget' ) . '</a>';
540
  }
541
  return $meta;
542
  }
2
  /*
3
  Plugin Name: Image Widget
4
  Plugin URI: http://wordpress.org/plugins/image-widget/
5
+ Description: A simple image widget that uses the native WordPress media manager to add image widgets to your site. <strong><a href="http://m.tri.be/19my">Image Widget Plus</a> - Multiple images, slider and more.</strong>
6
  Author: Modern Tribe, Inc.
7
+ Version: 4.4.2
8
  Author URI: http://m.tri.be/iwpdoc
9
  Text Domain: image-widget
10
  Domain Path: /lang
26
  **/
27
  class Tribe_Image_Widget extends WP_Widget {
28
 
29
+ const VERSION = '4.4.2';
30
 
31
  const CUSTOM_IMAGE_SIZE_SLUG = 'tribe_image_widget_custom';
32
 
47
  require_once( 'lib/ImageWidgetDeprecated.php' );
48
  new ImageWidgetDeprecated( $this );
49
  } else {
50
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_setup' ) );
51
  }
 
52
 
53
  add_action( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
54
 
69
  }
70
 
71
  /**
72
+ * Enqueue all the javascript and CSS.
73
  */
74
  public function admin_setup() {
75
+
76
+ // Only load on widget admin page and in the "Customizer" view.
77
+ $screen = get_current_screen();
78
+ $should_load = 'customize' == $screen->base || 'widgets' == $screen->base;
79
+
80
+ if ( ! $should_load ) {
81
+ return;
82
+ }
83
+
84
  wp_enqueue_media();
85
+
86
+ wp_enqueue_style( 'tribe-image-widget', plugins_url( 'resources/css/admin.css', __FILE__ ), array(), self::VERSION );
87
+
88
  wp_enqueue_script( 'tribe-image-widget', plugins_url( 'resources/js/image-widget.js', __FILE__ ), array( 'jquery', 'media-upload', 'media-views' ), self::VERSION );
89
 
90
  wp_localize_script( 'tribe-image-widget', 'TribeImageWidget', array(
192
  }
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  /**
196
  * Render an array of default values.
197
  *
253
  $attr = array_map( 'esc_attr', $attr );
254
  $output = '<a';
255
  foreach ( $attr as $name => $value ) {
256
+ if ( ! empty( $value ) ) {
257
+ $output .= sprintf( ' %s="%s"', $name, $value );
258
+ }
259
  }
260
  $output .= '>';
261
  }
273
  $instance['height'] = $image_details[2];
274
  }
275
 
276
+ $image_srcset = function_exists( 'wp_get_attachment_image_srcset' )
277
+ ? wp_get_attachment_image_srcset( $instance['attachment_id'], $size )
278
+ : false;
279
  if ( $image_srcset ) {
280
  $instance['srcset'] = $image_srcset;
 
281
 
282
+ $image_sizes = function_exists( 'wp_get_attachment_image_sizes' )
283
+ ? wp_get_attachment_image_sizes( $instance['attachment_id'], $size )
284
+ : false;
285
+ if ( $image_sizes ) {
286
+ $instance['sizes'] = $image_sizes;
287
+ }
288
  }
289
  }
290
  $instance['width'] = abs( $instance['width'] );
291
  $instance['height'] = abs( $instance['height'] );
292
 
293
  $attr = array();
294
+
295
+ if ( ! empty( $instance['alt'] ) ) {
296
+ $attr['alt'] = $instance['alt'];
297
+ } elseif ( ! empty( $instance['title'] ) ) {
298
+ $attr['alt'] = $instance['title'];
299
+ }
300
+
301
  if ( is_array( $size ) ) {
302
  $attr['class'] = 'attachment-' . join( 'x', $size );
303
  } else {
304
  $attr['class'] = 'attachment-' . $size;
305
  }
306
+
307
  $attr['style'] = '';
308
  if ( ! empty( $instance['maxwidth'] ) ) {
309
  $attr['style'] .= "max-width: {$instance['maxwidth']};";
310
  }
311
+
312
  if ( ! empty( $instance['maxheight'] ) ) {
313
  $attr['style'] .= "max-height: {$instance['maxheight']};";
314
  }
315
+
316
  if ( ! empty( $instance['align'] ) && $instance['align'] != 'none' ) {
317
  $attr['class'] .= " align{$instance['align']}";
318
  }
319
+
320
  if ( ! empty( $instance['srcset'] ) ) {
321
  $attr['srcset'] = $instance['srcset'];
322
  }
323
+
324
  if ( ! empty( $instance['sizes'] ) ) {
325
  $attr['sizes'] = $instance['sizes'];
326
  }
501
  $option_key = $this->generate_key( $key );
502
  if ( get_site_option( $option_key ) == self::VERSION ) return;
503
  $msg = sprintf(
504
+ __( '<p class="dashicons-before dashicons-format-gallery"><strong>Image Widget Plus</strong> - Add lightbox, slideshow, and random image widgets. <strong><a href="%s" target="_blank">Find out how!</a></strong></p>', 'image-widget' ),
505
  'http://m.tri.be/19my',
506
  'http://m.tri.be/19my'
507
  );
533
  */
534
  public function plugin_row_meta( $meta, $file ) {
535
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/image-widget.php' ) ) {
536
+ $meta[] = '<strong><a href="http://m.tri.be/19ma" target="_blank">' . esc_html__( 'Image Widget Plus', 'image-widget' ) . '</a></strong>';
537
  }
538
  return $meta;
539
  }
lang/image-widget.pot CHANGED
@@ -3,7 +3,7 @@ msgid ""
3
  msgstr ""
4
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
5
  "Project-Id-Version: Image Widget\n"
6
- "POT-Creation-Date: 2017-04-17 09:33-0400\n"
7
  "PO-Revision-Date: 2017-03-17 17:01-0400\n"
8
  "Last-Translator: \n"
9
  "Language-Team: \n"
@@ -29,44 +29,43 @@ msgstr ""
29
  msgid "Image Widget"
30
  msgstr ""
31
 
32
- #: image-widget.php:80 views/widget-admin.php:13
33
  msgid "Select an Image"
34
  msgstr ""
35
 
36
- #: image-widget.php:81 lib/ImageWidgetDeprecated.php:66
37
  msgid "Insert Into Widget"
38
  msgstr ""
39
 
40
- #: image-widget.php:365
41
  msgid "Full Size"
42
  msgstr ""
43
 
44
- #: image-widget.php:366
45
  msgid "Thumbnail"
46
  msgstr ""
47
 
48
- #: image-widget.php:367
49
  msgid "Medium"
50
  msgstr ""
51
 
52
- #: image-widget.php:368
53
  msgid "Large"
54
  msgstr ""
55
 
56
- #: image-widget.php:369
57
  msgid "Custom"
58
  msgstr ""
59
 
60
- #: image-widget.php:507
61
  #, php-format
62
  msgid ""
63
- "<p class=\"dashicons-before dashicons-format-gallery\"><strong><a href=\"%s"
64
- "\" target=\"_blank\">Image Widget Plus</a></strong> is coming soon! Add "
65
- "random images, lightbox, and slider - <strong><a href=\"%s\">Sign up now "
66
- "for early access.</a></strong></p>"
67
  msgstr ""
68
 
69
- #: image-widget.php:524
70
  #, php-format
71
  msgid ""
72
  "<p class=\"dashicons-before dashicons-star-filled\"><strong>Image Widget "
@@ -74,11 +73,7 @@ msgid ""
74
  "<strong><a href=\"%s\" target=\"_blank\">Find out how!</a></strong></p>"
75
  msgstr ""
76
 
77
- #: image-widget.php:539
78
- msgid "Coming Soon:"
79
- msgstr ""
80
-
81
- #: image-widget.php:539
82
  msgid "Image Widget Plus"
83
  msgstr ""
84
 
@@ -172,10 +167,8 @@ msgstr ""
172
  #. Description of the plugin/theme
173
  msgid ""
174
  "A simple image widget that uses the native WordPress media manager to add "
175
- "image widgets to your site. <strong>COMING SOON: <a href=\"http://"
176
- "theeventscalendar.org/products/image-widget-plus/?utm_campaign=in-"
177
- "app&utm_source=docblock&utm_medium=image-widget\">Image Widget Plus</a> - "
178
- "Multiple images, slider and more.</strong>"
179
  msgstr ""
180
 
181
  #. Author of the plugin/theme
3
  msgstr ""
4
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
5
  "Project-Id-Version: Image Widget\n"
6
+ "POT-Creation-Date: 2017-05-11 09:41-0400\n"
7
  "PO-Revision-Date: 2017-03-17 17:01-0400\n"
8
  "Last-Translator: \n"
9
  "Language-Team: \n"
29
  msgid "Image Widget"
30
  msgstr ""
31
 
32
+ #: image-widget.php:91 views/widget-admin.php:13
33
  msgid "Select an Image"
34
  msgstr ""
35
 
36
+ #: image-widget.php:92 lib/ImageWidgetDeprecated.php:66
37
  msgid "Insert Into Widget"
38
  msgstr ""
39
 
40
+ #: image-widget.php:362
41
  msgid "Full Size"
42
  msgstr ""
43
 
44
+ #: image-widget.php:363
45
  msgid "Thumbnail"
46
  msgstr ""
47
 
48
+ #: image-widget.php:364
49
  msgid "Medium"
50
  msgstr ""
51
 
52
+ #: image-widget.php:365
53
  msgid "Large"
54
  msgstr ""
55
 
56
+ #: image-widget.php:366
57
  msgid "Custom"
58
  msgstr ""
59
 
60
+ #: image-widget.php:504
61
  #, php-format
62
  msgid ""
63
+ "<p class=\"dashicons-before dashicons-format-gallery\"><strong>Image "
64
+ "Widget Plus</strong> - Add lightbox, slideshow, and random image widgets. "
65
+ "<strong><a href=\"%s\" target=\"_blank\">Find out how!</a></strong></p>"
 
66
  msgstr ""
67
 
68
+ #: image-widget.php:521
69
  #, php-format
70
  msgid ""
71
  "<p class=\"dashicons-before dashicons-star-filled\"><strong>Image Widget "
73
  "<strong><a href=\"%s\" target=\"_blank\">Find out how!</a></strong></p>"
74
  msgstr ""
75
 
76
+ #: image-widget.php:536
 
 
 
 
77
  msgid "Image Widget Plus"
78
  msgstr ""
79
 
167
  #. Description of the plugin/theme
168
  msgid ""
169
  "A simple image widget that uses the native WordPress media manager to add "
170
+ "image widgets to your site. <strong><a href=\"http://m.tri.be/19my\">Image "
171
+ "Widget Plus</a> - Multiple images, slider and more.</strong>"
 
 
172
  msgstr ""
173
 
174
  #. Author of the plugin/theme
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Image Widget ===
2
  Contributors: ModernTribe, peterchester, borkweb, zbtirrell
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4BSPTNFFY6AL6
4
- Tags: widget, image, ad, banner, simple, upload, sidebar, admin, thickbox, resize, arabic, brazilian portuguese, dutch, german, hebrew, italian, japanese, polish, spanish, swedish, widget-only
5
  Requires at least: 3.5
6
  Tested up to: 4.7.3
7
- Stable tag: 4.4.1
8
 
9
  A simple image widget that uses the native WordPress media manager to add image widgets to your site.
10
 
@@ -12,7 +12,8 @@ A simple image widget that uses the native WordPress media manager to add image
12
 
13
  Image Widget is a simple plugin that uses the native WordPress media manager to add image widgets to your site.
14
 
15
- Need to add slideshows, lightboxes, or random images? Check out [Image Widget Plus](http://m.tri.be/19mc)!
 
16
 
17
  = Image Widget Features =
18
 
@@ -32,9 +33,7 @@ Image Widget is developed and maintained by [Modern Tribe](http://m.tri.be/19md)
32
 
33
  This plugin is actively supported by our team and contributions from community members. If you see a question in the forum you can help with or have a great idea and want to code it up or submit a patch, that would be awesome! Not only will we shower you with praise and thanks, it’s also a good way to get to know us and lead into options for paid work if you freelance.
34
 
35
- = Coming Soon - Image Widget Plus! =
36
-
37
- Looking for more features? Our [new Image Widget Plus plugin](http://m.tri.be/19mf) is coming soon!
38
 
39
  Image Widget Plus features include:
40
 
@@ -207,6 +206,12 @@ For more info on the philosophy here, check out our [blog post](http://tri.be/de
207
 
208
  == Changelog ==
209
 
 
 
 
 
 
 
210
  = 4.4.1 =
211
 
212
  * Fix - fixed some broken links
1
  === Image Widget ===
2
  Contributors: ModernTribe, peterchester, borkweb, zbtirrell
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4BSPTNFFY6AL6
4
+ Tags: widget, image, ad, banner, simple, upload, sidebar, retina, admin, thickbox, resize, arabic, brazilian portuguese, dutch, german, hebrew, italian, japanese, polish, spanish, swedish, widget-only
5
  Requires at least: 3.5
6
  Tested up to: 4.7.3
7
+ Stable tag: 4.4.2
8
 
9
  A simple image widget that uses the native WordPress media manager to add image widgets to your site.
10
 
12
 
13
  Image Widget is a simple plugin that uses the native WordPress media manager to add image widgets to your site.
14
 
15
+ Need to add slideshows, lightboxes, or random images?
16
+ <strong>Check out [Image Widget Plus](http://m.tri.be/19mc)!</strong>
17
 
18
  = Image Widget Features =
19
 
33
 
34
  This plugin is actively supported by our team and contributions from community members. If you see a question in the forum you can help with or have a great idea and want to code it up or submit a patch, that would be awesome! Not only will we shower you with praise and thanks, it’s also a good way to get to know us and lead into options for paid work if you freelance.
35
 
36
+ = Image Widget Plus! =
 
 
37
 
38
  Image Widget Plus features include:
39
 
206
 
207
  == Changelog ==
208
 
209
+ = 4.4.2 =
210
+
211
+ * Fix - fixed compatibility with WordPress versions prior to 4.4
212
+ * Fix - proportional scaling of image within the widget editor
213
+ * Fix - fix validation by avoiding empty attributes and only specifying sizes with srcset (thanks Zodiak1978)
214
+
215
  = 4.4.1 =
216
 
217
  * Fix - fixed some broken links
resources/css/admin.css ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .uploader input.button {
2
+ height: 34px;
3
+ line-height: 1;
4
+ margin-top: 15px;
5
+ width: 100%;
6
+ }
7
+
8
+ .tribe_preview .aligncenter {
9
+ display: block;
10
+ margin-left: auto !important;
11
+ margin-right: auto !important;
12
+ }
13
+
14
+ .tribe_preview {
15
+ max-height: 300px;
16
+ overflow: hidden;
17
+ }
18
+
19
+ .tribe_preview img {
20
+ height: auto;
21
+ margin: 10px 0;
22
+ max-width: 100%;
23
+ }