Simple Image Widget - Version 3.0.4

Version Description

  • Fixed a slash preventing custom translations from loading.
  • Dropped the text domain from custom translation filenames.
  • Loading the text domain earlier so the widget title and description can be filtered.
  • Minor code formatting updates.
Download this release

Release Info

Developer bradyvercher
Plugin Icon 128x128 Simple Image Widget
Version 3.0.4
Comparing to
See all releases

Code changes from version 3.0.2 to 3.0.4

class-simple-image-widget.php CHANGED
@@ -18,24 +18,24 @@ class Simple_Image_Widget extends WP_Widget {
18
  function __construct( $id_base = false, $name = false, $widget_options = array(), $control_options = array() ) {
19
  $id_base = ( $id_base ) ? $id_base : 'simpleimage'; // Legacy ID.
20
  $name = ( $name ) ? $name : __( 'Image', 'simple-image-widget' );
21
-
22
  $widget_options = wp_parse_args( $widget_options, array(
23
  'classname' => 'widget_simpleimage', // Legacy class name.
24
  'description' => __( 'Display an image', 'simple-image-widget' ),
25
  ) );
26
-
27
  $control_options = wp_parse_args( $control_options, array(
28
  'width' => 300
29
  ) );
30
-
31
  parent::__construct( $id_base, $name, $widget_options, $control_options );
32
-
33
  // Flush widget group cache when an attachment is saved, deleted, or the theme is switched.
34
  add_action( 'save_post', array( $this, 'flush_group_cache' ) );
35
  add_action( 'delete_attachment', array( $this, 'flush_group_cache' ) );
36
  add_action( 'switch_theme', array( $this, 'flush_group_cache' ) );
37
  }
38
-
39
  /**
40
  * Default widget front end display method.
41
  *
@@ -46,23 +46,23 @@ class Simple_Image_Widget extends WP_Widget {
46
  */
47
  function widget( $args, $instance ) {
48
  $cache = (array) wp_cache_get( 'simple_image_widget', 'widget' );
49
-
50
  if ( isset( $cache[ $this->id ] ) ) {
51
  echo $cache[ $this->id ];
52
  return;
53
  }
54
-
55
  // Copy the original title so it can be passed to hooks.
56
  $instance['title_raw'] = $instance['title'];
57
  $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
58
-
59
  // Copy the original text so it can be passed to hooks.
60
  $instance['text_raw'] = $instance['text'];
61
  $instance['text'] = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance, $this->id_base );
62
-
63
  // Start building the output.
64
  $output = '';
65
-
66
  // Make sure the image ID is a valid attachment.
67
  if ( ! empty( $instance['image_id'] ) ) {
68
  $image = get_post( $instance['image_id'] );
@@ -70,17 +70,17 @@ class Simple_Image_Widget extends WP_Widget {
70
  $output = '<!-- Image Widget Error: Invalid Attachment ID -->';
71
  }
72
  }
73
-
74
  if ( empty( $output ) ) {
75
  $output = $this->render( $args, $instance );
76
  }
77
-
78
  echo $output;
79
-
80
  $cache[ $this->id ] = $output;
81
  wp_cache_set( 'simple_image_widget', array_filter( $cache ), 'widget' );
82
  }
83
-
84
  /**
85
  * Generate the widget output.
86
  *
@@ -93,54 +93,54 @@ class Simple_Image_Widget extends WP_Widget {
93
  * @since 3.0.0
94
  */
95
  function render( $args, $instance ) {
96
- $link_open = '';
97
- $link_close = '';
98
  if ( ! empty ( $instance['link'] ) ) {
99
  $target = ( empty( $instance['new_window'] ) ) ? '' : ' target="_blank"';
100
- $link_open = '<a href="' . esc_url( $instance['link'] ) . '"' . $target . '>';
101
- $link_close = '</a>';
102
  }
103
-
104
  $output = $args['before_widget'];
105
-
106
  // Allow custom output to override the default HTML.
107
  if ( $inside = apply_filters( 'simple_image_widget_output', '', $args, $instance, $this->id_base ) ) {
108
  $output .= $inside;
109
  } else {
110
  $output .= ( empty( $instance['title'] ) ) ? '' : $args['before_title']. $instance['title'] . $args['after_title'];
111
-
112
  // Add the image.
113
  if ( ! empty( $instance['image_id'] ) ) {
114
  $image_size = ( ! empty( $instance['image_size'] ) ) ? $instance['image_size'] : apply_filters( 'simple_image_widget_output_default_size', 'medium', $this->id_base );
115
-
116
- $output .= sprintf( '<p>%s%s%s</p>',
117
- $link_open,
118
  wp_get_attachment_image( $instance['image_id'], $image_size ),
119
- $link_close
120
  );
121
  } elseif ( ! empty( $instance['image'] ) ) {
122
  // Legacy output.
123
  $output .= sprintf( '%s<img src="%s" alt="%s">%s',
124
- $link_open,
125
  esc_url( $instance['image'] ),
126
  ( empty( $instance['alt'] ) ) ? '' : esc_attr( $instance['alt'] ),
127
- $link_close
128
  );
129
  }
130
-
131
  // Add the text.
132
  if ( ! empty( $instance['text'] ) ) {
133
  $output .= apply_filters( 'the_content', $instance['text'] );
134
  }
135
-
136
  // Add a more link.
137
- if ( ! empty( $link_open ) && ! empty( $instance['link_text'] ) ) {
138
- $output .= '<p class="more">' . $link_open . $instance['link_text'] . $link_close . '</p>';
139
  }
140
  }
141
-
142
  $output .= $args['after_widget'];
143
-
144
  return $output;
145
  }
146
 
@@ -161,26 +161,26 @@ class Simple_Image_Widget extends WP_Widget {
161
  'title' => '',
162
  'text' => '',
163
  ) );
164
-
165
  $instance['image_id'] = absint( $instance['image_id'] );
166
  $instance['title'] = wp_strip_all_tags( $instance['title'] );
167
-
168
  $button_class = array( 'button', 'button-hero', 'simple-image-widget-control-choose' );
169
  $image_id = $instance['image_id'];
170
-
171
  // The order of fields can be modified, new fields can be registered, or existing fields can be removed here.
172
  $fields = (array) apply_filters( 'simple_image_widget_fields', $this->form_fields(), $this->id_base );
173
  ?>
174
-
175
  <div class="simple-image-widget-form">
176
-
177
  <?php do_action( 'simple_image_widget_form_before', $instance, $this->id_base ); ?>
178
-
179
  <p>
180
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'simple-image-widget' ); ?></label>
181
  <input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat">
182
  </p>
183
-
184
  <?php if ( ! is_simple_image_widget_legacy() ) : ?>
185
  <p class="simple-image-widget-control<?php echo ( $image_id ) ? ' has-image' : ''; ?>"
186
  data-title="<?php esc_attr_e( 'Choose an Image for the Widget', 'simple-image-widget' ); ?>"
@@ -196,7 +196,7 @@ class Simple_Image_Widget extends WP_Widget {
196
  <a href="#" class="<?php echo join( ' ', $button_class ); ?>"><?php _e( 'Choose an Image', 'simple-image-widget' ); ?></a>
197
  </p>
198
  <?php endif; ?>
199
-
200
  <?php if ( is_simple_image_widget_legacy() || ! empty( $instance['image'] ) ) : ?>
201
  <div class="simple-image-widget-legacy-fields">
202
  <?php if ( ! is_simple_image_widget_legacy() ) : ?>
@@ -207,7 +207,7 @@ class Simple_Image_Widget extends WP_Widget {
207
  <em><?php _e( 'Select an image, then clear these values, and they will disappear when you save the widget.', 'simple-image-widget' ); ?></em>
208
  </p>
209
  <?php endif; ?>
210
-
211
  <p>
212
  <label for="<?php echo $this->get_field_id( 'image' ); ?>"><?php _e( 'Image URL:', 'simple-image-widget' ); ?></label>
213
  <input type="text" name="<?php echo $this->get_field_name( 'image' ); ?>" id="<?php echo $this->get_field_id( 'image' ); ?>" value="<?php echo esc_url( $instance['image'] ); ?>" class="widefat">
@@ -218,7 +218,7 @@ class Simple_Image_Widget extends WP_Widget {
218
  </p>
219
  </div>
220
  <?php endif; ?>
221
-
222
  <?php
223
  if ( ! empty( $fields ) ) {
224
  foreach ( $fields as $field ) {
@@ -242,7 +242,7 @@ class Simple_Image_Widget extends WP_Widget {
242
  </p>
243
  <?php
244
  break;
245
-
246
  case 'link' :
247
  ?>
248
  <p style="margin-bottom: 0.25em">
@@ -255,9 +255,9 @@ class Simple_Image_Widget extends WP_Widget {
255
  <?php _e( 'Open in new window?', 'simple-image-widget' ); ?>
256
  </label>
257
  </p>
258
- <?php
259
  break;
260
-
261
  case 'link_text' :
262
  ?>
263
  <p>
@@ -266,7 +266,7 @@ class Simple_Image_Widget extends WP_Widget {
266
  </p>
267
  <?php
268
  break;
269
-
270
  case 'text' :
271
  ?>
272
  <p>
@@ -275,21 +275,21 @@ class Simple_Image_Widget extends WP_Widget {
275
  </p>
276
  <?php
277
  break;
278
-
279
  default :
280
  // Custom fields can be added using this action.
281
  do_action( 'simple_image_widget_field-' . sanitize_key( $field ), $instance, $this );
282
  }
283
  }
284
  }
285
-
286
  do_action( 'simple_image_widget_form_after', $instance, $this->id_base );
287
  ?>
288
-
289
  </div>
290
  <?php
291
  }
292
-
293
  /**
294
  * The list of extra fields that should be shown in the widget form.
295
  *
@@ -299,15 +299,15 @@ class Simple_Image_Widget extends WP_Widget {
299
  */
300
  function form_fields() {
301
  $fields = array( 'link', 'link_text', 'text' );
302
-
303
  // Don't show the image size field for users with older WordPress versions.
304
  if ( ! is_simple_image_widget_legacy() ) {
305
  array_unshift( $fields, 'image_size' );
306
  }
307
-
308
  return $fields;
309
  }
310
-
311
  /**
312
  * Save widget settings.
313
  *
@@ -315,31 +315,31 @@ class Simple_Image_Widget extends WP_Widget {
315
  */
316
  function update( $new_instance, $old_instance ) {
317
  $instance = wp_parse_args( $new_instance, $old_instance );
318
-
319
  $instance = apply_filters( 'simple_image_widget_instance', $instance, $new_instance, $old_instance, $this->id_base );
320
-
321
  $instance['title'] = wp_strip_all_tags( $new_instance['title'] );
322
  $instance['image_id'] = absint( $new_instance['image_id'] );
323
  $instance['link'] = esc_url_raw( $new_instance['link'] );
324
  $instance['link_text'] = wp_kses_data( $new_instance['link_text'] );
325
  $instance['new_window'] = isset( $new_instance['new_window'] );
326
  $instance['text'] = wp_kses_data( $new_instance['text'] );
327
-
328
  $instance['image'] = esc_url_raw( $new_instance['image'] ); // Legacy image URL.
329
  if ( empty( $instance['image'] ) ) {
330
  unset( $instance['image'] );
331
  }
332
-
333
  $instance['alt'] = wp_strip_all_tags( $instance['alt'] ); // Legacy alt text.
334
  if ( empty( $instance['alt'] ) ) {
335
  unset( $instance['alt'] );
336
  }
337
-
338
  $this->flush_widget_cache();
339
-
340
  return $instance;
341
  }
342
-
343
  /**
344
  * Get the various sizes of an images.
345
  *
@@ -350,24 +350,24 @@ class Simple_Image_Widget extends WP_Widget {
350
  */
351
  function get_image_sizes( $image_id ) {
352
  $sizes = array( 'full' => __( 'Full Size', 'simple-image-widget' ) );
353
-
354
  $imagedata = wp_get_attachment_metadata( $image_id );
355
  if ( isset( $imagedata['sizes'] ) ) {
356
- $size_names = simple_image_widget_Loader::get_image_size_names();
357
-
358
  $sizes['full'] .= ( isset( $imagedata['width'] ) && isset( $imagedata['height'] ) ) ? sprintf( ' (%d&times;%d)', $imagedata['width'], $imagedata['height'] ) : '';
359
-
360
  foreach( $imagedata['sizes'] as $_size => $data ) {
361
  $label = ( isset( $size_names[ $_size ] ) ) ? $size_names[ $_size ] : ucwords( $_size );
362
  $label .= sprintf( ' (%d&times;%d)', $data['width'], $data['height'] );
363
-
364
  $sizes[ $_size ] = $label;
365
  }
366
  }
367
-
368
  return $sizes;
369
  }
370
-
371
  /**
372
  * Remove a single image widget from the cache.
373
  *
@@ -375,14 +375,14 @@ class Simple_Image_Widget extends WP_Widget {
375
  */
376
  function flush_widget_cache() {
377
  $cache = (array) wp_cache_get( 'simple_image_widget', 'widget' );
378
-
379
  if ( isset( $cache[ $this->id ] ) ) {
380
  unset( $cache[ $this->id ] );
381
  }
382
-
383
  wp_cache_set( 'simple_image_widget', array_filter( $cache ), 'widget' );
384
  }
385
-
386
  /**
387
  * Flush the cache for all image widgets.
388
  *
@@ -392,7 +392,7 @@ class Simple_Image_Widget extends WP_Widget {
392
  if ( 'save_post' == current_filter() && 'attachment' != get_post_type( $post_id ) ) {
393
  return;
394
  }
395
-
396
  wp_cache_delete( 'simple_image_widget', 'widget' );
397
  }
398
  }
18
  function __construct( $id_base = false, $name = false, $widget_options = array(), $control_options = array() ) {
19
  $id_base = ( $id_base ) ? $id_base : 'simpleimage'; // Legacy ID.
20
  $name = ( $name ) ? $name : __( 'Image', 'simple-image-widget' );
21
+
22
  $widget_options = wp_parse_args( $widget_options, array(
23
  'classname' => 'widget_simpleimage', // Legacy class name.
24
  'description' => __( 'Display an image', 'simple-image-widget' ),
25
  ) );
26
+
27
  $control_options = wp_parse_args( $control_options, array(
28
  'width' => 300
29
  ) );
30
+
31
  parent::__construct( $id_base, $name, $widget_options, $control_options );
32
+
33
  // Flush widget group cache when an attachment is saved, deleted, or the theme is switched.
34
  add_action( 'save_post', array( $this, 'flush_group_cache' ) );
35
  add_action( 'delete_attachment', array( $this, 'flush_group_cache' ) );
36
  add_action( 'switch_theme', array( $this, 'flush_group_cache' ) );
37
  }
38
+
39
  /**
40
  * Default widget front end display method.
41
  *
46
  */
47
  function widget( $args, $instance ) {
48
  $cache = (array) wp_cache_get( 'simple_image_widget', 'widget' );
49
+
50
  if ( isset( $cache[ $this->id ] ) ) {
51
  echo $cache[ $this->id ];
52
  return;
53
  }
54
+
55
  // Copy the original title so it can be passed to hooks.
56
  $instance['title_raw'] = $instance['title'];
57
  $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
58
+
59
  // Copy the original text so it can be passed to hooks.
60
  $instance['text_raw'] = $instance['text'];
61
  $instance['text'] = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance, $this->id_base );
62
+
63
  // Start building the output.
64
  $output = '';
65
+
66
  // Make sure the image ID is a valid attachment.
67
  if ( ! empty( $instance['image_id'] ) ) {
68
  $image = get_post( $instance['image_id'] );
70
  $output = '<!-- Image Widget Error: Invalid Attachment ID -->';
71
  }
72
  }
73
+
74
  if ( empty( $output ) ) {
75
  $output = $this->render( $args, $instance );
76
  }
77
+
78
  echo $output;
79
+
80
  $cache[ $this->id ] = $output;
81
  wp_cache_set( 'simple_image_widget', array_filter( $cache ), 'widget' );
82
  }
83
+
84
  /**
85
  * Generate the widget output.
86
  *
93
  * @since 3.0.0
94
  */
95
  function render( $args, $instance ) {
96
+ $instance['link_open'] = '';
97
+ $instance['link_close'] = '';
98
  if ( ! empty ( $instance['link'] ) ) {
99
  $target = ( empty( $instance['new_window'] ) ) ? '' : ' target="_blank"';
100
+ $instance['link_open'] = '<a href="' . esc_url( $instance['link'] ) . '"' . $target . '>';
101
+ $instance['link_close'] = '</a>';
102
  }
103
+
104
  $output = $args['before_widget'];
105
+
106
  // Allow custom output to override the default HTML.
107
  if ( $inside = apply_filters( 'simple_image_widget_output', '', $args, $instance, $this->id_base ) ) {
108
  $output .= $inside;
109
  } else {
110
  $output .= ( empty( $instance['title'] ) ) ? '' : $args['before_title']. $instance['title'] . $args['after_title'];
111
+
112
  // Add the image.
113
  if ( ! empty( $instance['image_id'] ) ) {
114
  $image_size = ( ! empty( $instance['image_size'] ) ) ? $instance['image_size'] : apply_filters( 'simple_image_widget_output_default_size', 'medium', $this->id_base );
115
+
116
+ $output .= sprintf( '<p class="simple-image">%s%s%s</p>',
117
+ $instance['link_open'],
118
  wp_get_attachment_image( $instance['image_id'], $image_size ),
119
+ $instance['link_close']
120
  );
121
  } elseif ( ! empty( $instance['image'] ) ) {
122
  // Legacy output.
123
  $output .= sprintf( '%s<img src="%s" alt="%s">%s',
124
+ $instance['link_open'],
125
  esc_url( $instance['image'] ),
126
  ( empty( $instance['alt'] ) ) ? '' : esc_attr( $instance['alt'] ),
127
+ $instance['link_close']
128
  );
129
  }
130
+
131
  // Add the text.
132
  if ( ! empty( $instance['text'] ) ) {
133
  $output .= apply_filters( 'the_content', $instance['text'] );
134
  }
135
+
136
  // Add a more link.
137
+ if ( ! empty( $instance['link_open'] ) && ! empty( $instance['link_text'] ) ) {
138
+ $output .= '<p class="more">' . $instance['link_open'] . $instance['link_text'] . $instance['link_close'] . '</p>';
139
  }
140
  }
141
+
142
  $output .= $args['after_widget'];
143
+
144
  return $output;
145
  }
146
 
161
  'title' => '',
162
  'text' => '',
163
  ) );
164
+
165
  $instance['image_id'] = absint( $instance['image_id'] );
166
  $instance['title'] = wp_strip_all_tags( $instance['title'] );
167
+
168
  $button_class = array( 'button', 'button-hero', 'simple-image-widget-control-choose' );
169
  $image_id = $instance['image_id'];
170
+
171
  // The order of fields can be modified, new fields can be registered, or existing fields can be removed here.
172
  $fields = (array) apply_filters( 'simple_image_widget_fields', $this->form_fields(), $this->id_base );
173
  ?>
174
+
175
  <div class="simple-image-widget-form">
176
+
177
  <?php do_action( 'simple_image_widget_form_before', $instance, $this->id_base ); ?>
178
+
179
  <p>
180
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'simple-image-widget' ); ?></label>
181
  <input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat">
182
  </p>
183
+
184
  <?php if ( ! is_simple_image_widget_legacy() ) : ?>
185
  <p class="simple-image-widget-control<?php echo ( $image_id ) ? ' has-image' : ''; ?>"
186
  data-title="<?php esc_attr_e( 'Choose an Image for the Widget', 'simple-image-widget' ); ?>"
196
  <a href="#" class="<?php echo join( ' ', $button_class ); ?>"><?php _e( 'Choose an Image', 'simple-image-widget' ); ?></a>
197
  </p>
198
  <?php endif; ?>
199
+
200
  <?php if ( is_simple_image_widget_legacy() || ! empty( $instance['image'] ) ) : ?>
201
  <div class="simple-image-widget-legacy-fields">
202
  <?php if ( ! is_simple_image_widget_legacy() ) : ?>
207
  <em><?php _e( 'Select an image, then clear these values, and they will disappear when you save the widget.', 'simple-image-widget' ); ?></em>
208
  </p>
209
  <?php endif; ?>
210
+
211
  <p>
212
  <label for="<?php echo $this->get_field_id( 'image' ); ?>"><?php _e( 'Image URL:', 'simple-image-widget' ); ?></label>
213
  <input type="text" name="<?php echo $this->get_field_name( 'image' ); ?>" id="<?php echo $this->get_field_id( 'image' ); ?>" value="<?php echo esc_url( $instance['image'] ); ?>" class="widefat">
218
  </p>
219
  </div>
220
  <?php endif; ?>
221
+
222
  <?php
223
  if ( ! empty( $fields ) ) {
224
  foreach ( $fields as $field ) {
242
  </p>
243
  <?php
244
  break;
245
+
246
  case 'link' :
247
  ?>
248
  <p style="margin-bottom: 0.25em">
255
  <?php _e( 'Open in new window?', 'simple-image-widget' ); ?>
256
  </label>
257
  </p>
258
+ <?php
259
  break;
260
+
261
  case 'link_text' :
262
  ?>
263
  <p>
266
  </p>
267
  <?php
268
  break;
269
+
270
  case 'text' :
271
  ?>
272
  <p>
275
  </p>
276
  <?php
277
  break;
278
+
279
  default :
280
  // Custom fields can be added using this action.
281
  do_action( 'simple_image_widget_field-' . sanitize_key( $field ), $instance, $this );
282
  }
283
  }
284
  }
285
+
286
  do_action( 'simple_image_widget_form_after', $instance, $this->id_base );
287
  ?>
288
+
289
  </div>
290
  <?php
291
  }
292
+
293
  /**
294
  * The list of extra fields that should be shown in the widget form.
295
  *
299
  */
300
  function form_fields() {
301
  $fields = array( 'link', 'link_text', 'text' );
302
+
303
  // Don't show the image size field for users with older WordPress versions.
304
  if ( ! is_simple_image_widget_legacy() ) {
305
  array_unshift( $fields, 'image_size' );
306
  }
307
+
308
  return $fields;
309
  }
310
+
311
  /**
312
  * Save widget settings.
313
  *
315
  */
316
  function update( $new_instance, $old_instance ) {
317
  $instance = wp_parse_args( $new_instance, $old_instance );
318
+
319
  $instance = apply_filters( 'simple_image_widget_instance', $instance, $new_instance, $old_instance, $this->id_base );
320
+
321
  $instance['title'] = wp_strip_all_tags( $new_instance['title'] );
322
  $instance['image_id'] = absint( $new_instance['image_id'] );
323
  $instance['link'] = esc_url_raw( $new_instance['link'] );
324
  $instance['link_text'] = wp_kses_data( $new_instance['link_text'] );
325
  $instance['new_window'] = isset( $new_instance['new_window'] );
326
  $instance['text'] = wp_kses_data( $new_instance['text'] );
327
+
328
  $instance['image'] = esc_url_raw( $new_instance['image'] ); // Legacy image URL.
329
  if ( empty( $instance['image'] ) ) {
330
  unset( $instance['image'] );
331
  }
332
+
333
  $instance['alt'] = wp_strip_all_tags( $instance['alt'] ); // Legacy alt text.
334
  if ( empty( $instance['alt'] ) ) {
335
  unset( $instance['alt'] );
336
  }
337
+
338
  $this->flush_widget_cache();
339
+
340
  return $instance;
341
  }
342
+
343
  /**
344
  * Get the various sizes of an images.
345
  *
350
  */
351
  function get_image_sizes( $image_id ) {
352
  $sizes = array( 'full' => __( 'Full Size', 'simple-image-widget' ) );
353
+
354
  $imagedata = wp_get_attachment_metadata( $image_id );
355
  if ( isset( $imagedata['sizes'] ) ) {
356
+ $size_names = Simple_Image_Widget_Loader::get_image_size_names();
357
+
358
  $sizes['full'] .= ( isset( $imagedata['width'] ) && isset( $imagedata['height'] ) ) ? sprintf( ' (%d&times;%d)', $imagedata['width'], $imagedata['height'] ) : '';
359
+
360
  foreach( $imagedata['sizes'] as $_size => $data ) {
361
  $label = ( isset( $size_names[ $_size ] ) ) ? $size_names[ $_size ] : ucwords( $_size );
362
  $label .= sprintf( ' (%d&times;%d)', $data['width'], $data['height'] );
363
+
364
  $sizes[ $_size ] = $label;
365
  }
366
  }
367
+
368
  return $sizes;
369
  }
370
+
371
  /**
372
  * Remove a single image widget from the cache.
373
  *
375
  */
376
  function flush_widget_cache() {
377
  $cache = (array) wp_cache_get( 'simple_image_widget', 'widget' );
378
+
379
  if ( isset( $cache[ $this->id ] ) ) {
380
  unset( $cache[ $this->id ] );
381
  }
382
+
383
  wp_cache_set( 'simple_image_widget', array_filter( $cache ), 'widget' );
384
  }
385
+
386
  /**
387
  * Flush the cache for all image widgets.
388
  *
392
  if ( 'save_post' == current_filter() && 'attachment' != get_post_type( $post_id ) ) {
393
  return;
394
  }
395
+
396
  wp_cache_delete( 'simple_image_widget', 'widget' );
397
  }
398
  }
js/simple-image-widget.js CHANGED
@@ -4,24 +4,24 @@ var SimpleImageWidget;
4
  SimpleImageWidget.updateSizeDropdownOptions = function( field, sizes ) {
5
  var currentValue = field.val(),
6
  options;
7
-
8
  if ( sizes ) {
9
  $.each( sizes, function( key, size ) {
10
  var name;
11
-
12
  if ( key in SimpleImageWidget.imageSizeNames ) {
13
  name = SimpleImageWidget.imageSizeNames[ key ];
14
  }
15
-
16
  options += '<option value="' + key + '">' + name + ' (' + size.width + '&times;' + size.height + ')</option>';
17
  });
18
  }
19
-
20
  if ( ! options ) {
21
  name = SimpleImageWidget.imageSizeNames['full'] || SimpleImageWidget.fullSizeLabel;
22
  options = '<option value="full">' + name + '</option>';
23
  }
24
-
25
  // Try to maintain the previously selected size if it still exists.
26
  field.html( options ).val( currentValue ).removeAttr('disabled');
27
  };
@@ -33,7 +33,7 @@ var SimpleImageWidget;
33
  jQuery(function($) {
34
  var Attachment = wp.media.model.Attachment,
35
  $control, $controlTarget, mediaControl;
36
-
37
  mediaControl = {
38
  // Initialize a new media manager or return an existing frame.
39
  // @see wp.media.featuredImage.frame()
@@ -51,31 +51,31 @@ jQuery(function($) {
51
  },
52
  multiple: $control.data( 'select-multiple' ) || false
53
  });
54
-
55
  this._frame.on( 'open', this.updateLibrarySelection ).state('library').on( 'select', this.select );
56
-
57
  return this._frame;
58
  },
59
-
60
  // Update the control when an image is selected from the media library.
61
  select: function() {
62
  var selection = this.get('selection'),
63
  returnProperty = $control.data('return-property') || 'id';
64
-
65
  // Insert the selected attachment ids into the target element.
66
  if ( $controlTarget.length ) {
67
  $controlTarget.val( selection.pluck( returnProperty ) );
68
  }
69
-
70
  // Trigger an event on the control to allow custom updates.
71
  $control.trigger( 'selectionChange.simpleimagewidget', [ selection ] );
72
  },
73
-
74
  // Update the selected image in the media library based on the image in the control.
75
  updateLibrarySelection: function() {
76
  var selection = this.get('library').get('selection'),
77
  attachment, selectedIds;
78
-
79
  if ( $controlTarget.length ) {
80
  selectedIds = $controlTarget.val();
81
  if ( selectedIds && '' !== selectedIds && -1 !== selectedIds && '0' !== selectedIds ) {
@@ -83,18 +83,18 @@ jQuery(function($) {
83
  attachment.fetch();
84
  }
85
  }
86
-
87
  selection.reset( attachment ? [ attachment ] : [] );
88
  },
89
-
90
  init: function() {
91
  $('#wpbody').on('click', '.simple-image-widget-control-choose', function(e) {
92
  var targetSelector;
93
-
94
  e.preventDefault();
95
-
96
  $control = $(this).closest('.simple-image-widget-control');
97
-
98
  targetSelector = $control.data('target') || '.simple-image-widget-control-target';
99
  if ( 0 === targetSelector.indexOf('#') ) {
100
  // Context doesn't matter if the selector is an ID.
@@ -103,11 +103,11 @@ jQuery(function($) {
103
  // Search for other selectors within the context of the control.
104
  $controlTarget = $control.find( targetSelector );
105
  }
106
-
107
  mediaControl.frame().open();
108
  });
109
  }
110
  };
111
-
112
  mediaControl.init();
113
  });
4
  SimpleImageWidget.updateSizeDropdownOptions = function( field, sizes ) {
5
  var currentValue = field.val(),
6
  options;
7
+
8
  if ( sizes ) {
9
  $.each( sizes, function( key, size ) {
10
  var name;
11
+
12
  if ( key in SimpleImageWidget.imageSizeNames ) {
13
  name = SimpleImageWidget.imageSizeNames[ key ];
14
  }
15
+
16
  options += '<option value="' + key + '">' + name + ' (' + size.width + '&times;' + size.height + ')</option>';
17
  });
18
  }
19
+
20
  if ( ! options ) {
21
  name = SimpleImageWidget.imageSizeNames['full'] || SimpleImageWidget.fullSizeLabel;
22
  options = '<option value="full">' + name + '</option>';
23
  }
24
+
25
  // Try to maintain the previously selected size if it still exists.
26
  field.html( options ).val( currentValue ).removeAttr('disabled');
27
  };
33
  jQuery(function($) {
34
  var Attachment = wp.media.model.Attachment,
35
  $control, $controlTarget, mediaControl;
36
+
37
  mediaControl = {
38
  // Initialize a new media manager or return an existing frame.
39
  // @see wp.media.featuredImage.frame()
51
  },
52
  multiple: $control.data( 'select-multiple' ) || false
53
  });
54
+
55
  this._frame.on( 'open', this.updateLibrarySelection ).state('library').on( 'select', this.select );
56
+
57
  return this._frame;
58
  },
59
+
60
  // Update the control when an image is selected from the media library.
61
  select: function() {
62
  var selection = this.get('selection'),
63
  returnProperty = $control.data('return-property') || 'id';
64
+
65
  // Insert the selected attachment ids into the target element.
66
  if ( $controlTarget.length ) {
67
  $controlTarget.val( selection.pluck( returnProperty ) );
68
  }
69
+
70
  // Trigger an event on the control to allow custom updates.
71
  $control.trigger( 'selectionChange.simpleimagewidget', [ selection ] );
72
  },
73
+
74
  // Update the selected image in the media library based on the image in the control.
75
  updateLibrarySelection: function() {
76
  var selection = this.get('library').get('selection'),
77
  attachment, selectedIds;
78
+
79
  if ( $controlTarget.length ) {
80
  selectedIds = $controlTarget.val();
81
  if ( selectedIds && '' !== selectedIds && -1 !== selectedIds && '0' !== selectedIds ) {
83
  attachment.fetch();
84
  }
85
  }
86
+
87
  selection.reset( attachment ? [ attachment ] : [] );
88
  },
89
+
90
  init: function() {
91
  $('#wpbody').on('click', '.simple-image-widget-control-choose', function(e) {
92
  var targetSelector;
93
+
94
  e.preventDefault();
95
+
96
  $control = $(this).closest('.simple-image-widget-control');
97
+
98
  targetSelector = $control.data('target') || '.simple-image-widget-control-target';
99
  if ( 0 === targetSelector.indexOf('#') ) {
100
  // Context doesn't matter if the selector is an ID.
103
  // Search for other selectors within the context of the control.
104
  $controlTarget = $control.find( targetSelector );
105
  }
106
+
107
  mediaControl.frame().open();
108
  });
109
  }
110
  };
111
+
112
  mediaControl.init();
113
  });
languages/simple-image-widget.pot CHANGED
@@ -1,17 +1,17 @@
 
 
1
  msgid ""
2
  msgstr ""
3
- "Project-Id-Version: Simple Image Widget\n"
4
- "POT-Creation-Date: 2013-01-11 14:34-0800\n"
5
- "PO-Revision-Date: 2013-01-11 14:38-0800\n"
6
- "Last-Translator: Brady Vercher <brady@blazersix.com>\n"
7
- "Language-Team: \n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "X-Generator: Poedit 1.5.4\n"
12
- "X-Poedit-KeywordsList: _e;__;esc_attr_e;esc_attr__;esc_html_e;esc_html__\n"
13
- "X-Poedit-Basepath: ../\n"
14
- "X-Poedit-SearchPath-0: .\n"
15
 
16
  #: class-simple-image-widget.php:20
17
  msgid "Image"
@@ -21,77 +21,101 @@ msgstr ""
21
  msgid "Display an image"
22
  msgstr ""
23
 
24
- #: class-simple-image-widget.php:178
25
  msgid "Title:"
26
  msgstr ""
27
 
28
- #: class-simple-image-widget.php:184
29
  msgid "Choose an Image for the Widget"
30
  msgstr ""
31
 
32
- #: class-simple-image-widget.php:185
33
  msgid "Update Image"
34
  msgstr ""
35
 
36
- #: class-simple-image-widget.php:194
37
  msgid "Choose an Image"
38
  msgstr ""
39
 
40
- #: class-simple-image-widget.php:202
41
  msgid "These fields are here to maintain your data from an earlier version."
42
  msgstr ""
43
 
44
- #: class-simple-image-widget.php:205
45
  msgid ""
46
  "Select an image, then clear these values, and they will disappear when you "
47
  "save the widget."
48
  msgstr ""
49
 
50
- #: class-simple-image-widget.php:210
51
  msgid "Image URL:"
52
  msgstr ""
53
 
54
- #: class-simple-image-widget.php:214
55
  msgid "Alternate Text:"
56
  msgstr ""
57
 
58
- #: class-simple-image-widget.php:228
59
  msgid "Size:"
60
  msgstr ""
61
 
62
- #: class-simple-image-widget.php:247
63
  msgid "Link:"
64
  msgstr ""
65
 
66
- #: class-simple-image-widget.php:256
 
 
 
 
67
  msgid "Link Text:"
68
  msgstr ""
69
 
70
- #: class-simple-image-widget.php:265
71
  msgid "Text:"
72
  msgstr ""
73
 
74
- #: class-simple-image-widget.php:343 simple-image-widget.php:85
75
- #: simple-image-widget.php:186
76
  msgid "Full Size"
77
  msgstr ""
78
 
79
- #: simple-image-widget.php:83
80
  msgid "Choose an Attachment"
81
  msgstr ""
82
 
83
- #: simple-image-widget.php:84
84
  msgid "Update Attachment"
85
  msgstr ""
86
 
87
- #: simple-image-widget.php:183
88
  msgid "Thumbnail"
89
  msgstr ""
90
 
91
- #: simple-image-widget.php:184
92
  msgid "Medium"
93
  msgstr ""
94
 
95
- #: simple-image-widget.php:185
96
  msgid "Large"
97
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2013 Simple Image Widget
2
+ # This file is distributed under the same license as the Simple Image Widget package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Simple Image Widget 3.0.4\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/simple-image-"
7
+ "widget\n"
8
+ "POT-Creation-Date: 2013-10-26 20:24:57+00:00\n"
 
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2013-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
 
15
 
16
  #: class-simple-image-widget.php:20
17
  msgid "Image"
21
  msgid "Display an image"
22
  msgstr ""
23
 
24
+ #: class-simple-image-widget.php:180
25
  msgid "Title:"
26
  msgstr ""
27
 
28
+ #: class-simple-image-widget.php:186
29
  msgid "Choose an Image for the Widget"
30
  msgstr ""
31
 
32
+ #: class-simple-image-widget.php:187
33
  msgid "Update Image"
34
  msgstr ""
35
 
36
+ #: class-simple-image-widget.php:196
37
  msgid "Choose an Image"
38
  msgstr ""
39
 
40
+ #: class-simple-image-widget.php:204
41
  msgid "These fields are here to maintain your data from an earlier version."
42
  msgstr ""
43
 
44
+ #: class-simple-image-widget.php:207
45
  msgid ""
46
  "Select an image, then clear these values, and they will disappear when you "
47
  "save the widget."
48
  msgstr ""
49
 
50
+ #: class-simple-image-widget.php:212
51
  msgid "Image URL:"
52
  msgstr ""
53
 
54
+ #: class-simple-image-widget.php:216
55
  msgid "Alternate Text:"
56
  msgstr ""
57
 
58
+ #: class-simple-image-widget.php:230
59
  msgid "Size:"
60
  msgstr ""
61
 
62
+ #: class-simple-image-widget.php:249
63
  msgid "Link:"
64
  msgstr ""
65
 
66
+ #: class-simple-image-widget.php:255
67
+ msgid "Open in new window?"
68
+ msgstr ""
69
+
70
+ #: class-simple-image-widget.php:264
71
  msgid "Link Text:"
72
  msgstr ""
73
 
74
+ #: class-simple-image-widget.php:273
75
  msgid "Text:"
76
  msgstr ""
77
 
78
+ #: class-simple-image-widget.php:352 simple-image-widget.php:79
79
+ #: simple-image-widget.php:180
80
  msgid "Full Size"
81
  msgstr ""
82
 
83
+ #: simple-image-widget.php:77
84
  msgid "Choose an Attachment"
85
  msgstr ""
86
 
87
+ #: simple-image-widget.php:78
88
  msgid "Update Attachment"
89
  msgstr ""
90
 
91
+ #: simple-image-widget.php:177
92
  msgid "Thumbnail"
93
  msgstr ""
94
 
95
+ #: simple-image-widget.php:178
96
  msgid "Medium"
97
  msgstr ""
98
 
99
+ #: simple-image-widget.php:179
100
  msgid "Large"
101
  msgstr ""
102
+
103
+ #. Plugin Name of the plugin/theme
104
+ msgid "Simple Image Widget"
105
+ msgstr ""
106
+
107
+ #. Plugin URI of the plugin/theme
108
+ msgid "https://wordpress.org/extend/plugins/simple-image-widget/"
109
+ msgstr ""
110
+
111
+ #. Description of the plugin/theme
112
+ msgid "A simple image widget utilizing the new WordPress media manager."
113
+ msgstr ""
114
+
115
+ #. Author of the plugin/theme
116
+ msgid "Blazer Six"
117
+ msgstr ""
118
+
119
+ #. Author URI of the plugin/theme
120
+ msgid "http://www.blazersix.com/"
121
+ msgstr ""
readme.txt CHANGED
@@ -2,35 +2,53 @@
2
  Contributors: blazersix, bradyvercher
3
  Tags: image widget, widget, media, media manager, sidebar, image, photo, picture
4
  Requires at least: 3.3
5
- Tested up to: 3.5
6
- Stable tag: 3.0.2
7
  License: GPL-2.0+
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- A simple image widget utilizing the new WordPress media manager.
11
 
12
  == Description ==
13
 
14
- Simple Image Widget provides the absolute easiest method to quicky add an image to a sidebar or any other widget area. Despite its simplicty, it can be extended by developers via the various built in hooks to create additional image-based widgets.
15
 
16
- Contribute to [development on GitHub](http://github.com/blazersix/simple-image-widget).
 
 
 
 
 
 
 
 
17
 
18
  == Installation ==
19
 
20
  Installation is just like installing most other plugins. [Check out the codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) if you have any questions.
21
 
 
 
 
 
 
22
  == Screenshots ==
23
 
24
  1. A new image widget.
25
  2. The widget after selecting an image.
26
 
27
- == Notes ==
28
-
29
- Development and maintenance of this plugin was taken over by Blazer Six starting with version 3.0.
30
 
31
- Read about the original thought behind creating this widget and ways it can be extended in [this blog post](http://www.blazersix.com/blog/wordpress-image-widget/).
 
 
 
 
32
 
33
- == Changelog ==
 
 
 
34
 
35
  = 3.0.2 =
36
  * Implemented feature for opening links in a new tab/window.
2
  Contributors: blazersix, bradyvercher
3
  Tags: image widget, widget, media, media manager, sidebar, image, photo, picture
4
  Requires at least: 3.3
5
+ Tested up to: 3.7
6
+ Stable tag: trunk
7
  License: GPL-2.0+
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
+ A simple image widget that makes it a breeze to add images to your sidebars.
11
 
12
  == Description ==
13
 
14
+ Simple Image Widget provides the absolute easiest method to quicky add an image to a sidebar or any other widget area. Despite its simplicty, it can be extended by developers via the various hooks to create additional image-based widgets.
15
 
16
+ Blazer Six took over development and maintenance of Simple Image Widget with version 3.0, rewriting it from the ground up to take advantage of the media improvements in WordPress 3.5. Read about the original thought behind creating this widget and ways it can be extended in [this blog post](http://www.blazersix.com/blog/wordpress-image-widget/).
17
+
18
+ = Additional Resources =
19
+
20
+ * [Write a review](http://wordpress.org/support/view/plugin-reviews/simple-image-widget#postform)
21
+ * [Have a question?](http://wordpress.org/support/plugin/simple-image-widget)
22
+ * [Contribute on GitHub](https://github.com/blazersix/simple-image-widget)
23
+ * [Follow @bradyvercher](https://twitter.com/bradyvercher)
24
+ * [Hire Blazer Six](http://www.blazersix.com/)
25
 
26
  == Installation ==
27
 
28
  Installation is just like installing most other plugins. [Check out the codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) if you have any questions.
29
 
30
+ == Frequently Asked Questions ==
31
+
32
+ = How do I add alt text to images in the widget? =
33
+ When selecting an image in the media manager (not in the widget itself), the right section will be titled "Attachment Details" and contains a field for entering your alt text. After entering your alt text, click the "Update Image" button to use the selected image in your widget. You won't be able to see the alt text in most browsers without viewing the HTML source of the page.
34
+
35
  == Screenshots ==
36
 
37
  1. A new image widget.
38
  2. The widget after selecting an image.
39
 
40
+ == Changelog ==
 
 
41
 
42
+ = 3.0.4 =
43
+ * Fixed a slash preventing custom translations from loading.
44
+ * Dropped the text domain from custom translation filenames.
45
+ * Loading the text domain earlier so the widget title and description can be filtered.
46
+ * Minor code formatting updates.
47
 
48
+ = 3.0.3 =
49
+ * Fixed PHP class name formatting.
50
+ * Added 'link_open' and 'link_close' args to the $instance when rendering the widget display.
51
+ * Added a 'simple-image' CSS class to the image wrapper.
52
 
53
  = 3.0.2 =
54
  * Implemented feature for opening links in a new tab/window.
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file
simple-image-widget.php CHANGED
@@ -3,13 +3,13 @@
3
  * Plugin Name: Simple Image Widget
4
  * Plugin URI: https://wordpress.org/extend/plugins/simple-image-widget/
5
  * Description: A simple image widget utilizing the new WordPress media manager.
6
- * Version: 3.0.2
7
  * Author: Blazer Six
8
  * Author URI: http://www.blazersix.com/
9
  * License: GPL-2.0+
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  * Text Domain: simple-image-widget
12
- * Domain Path: /languages/
13
  *
14
  * @package SimpleImageWidget
15
  * @author Brady Vercher <brady@blazersix.com>
@@ -22,11 +22,6 @@
22
  */
23
  require_once( plugin_dir_path( __FILE__ ) . 'class-simple-image-widget.php' );
24
 
25
- /**
26
- * Load the plugin when plugins are loaded.
27
- */
28
- add_action( 'plugins_loaded', array( 'Simple_Image_Widget_Loader', 'load' ) );
29
-
30
  /**
31
  * The main plugin class for loading the widget and attaching necessary hooks.
32
  *
@@ -39,31 +34,30 @@ class Simple_Image_Widget_Loader {
39
  * @since 3.0.0
40
  */
41
  public static function load() {
42
- add_action( 'init', array( __CLASS__, 'l10n' ) );
43
  add_action( 'widgets_init', array( __CLASS__, 'register_widget' ) );
44
-
45
  if ( is_simple_image_widget_legacy() ) {
46
  return;
47
  }
48
-
49
  add_action( 'init', array( __CLASS__, 'init' ) );
50
  add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_scripts' ) );
51
  add_action( 'admin_head-widgets.php', array( __CLASS__, 'admin_head_widgets' ) );
52
  add_action( 'admin_footer-widgets.php', array( __CLASS__, 'admin_footer_widgets' ) );
53
  }
54
-
55
  /**
56
  * Plugin localization support.
57
  *
58
  * @since 3.0.0
59
  */
60
- public static function l10n() {
61
- // The "plugin_locale" filter is also used in load_plugin_textdomain()
62
  $locale = apply_filters( 'plugin_locale', get_locale(), 'simple-image-widget' );
63
- load_textdomain( 'simple-image-widget', WP_LANG_DIR . '/simple-image-widget/simple-image-widget-' . $locale . '.mo' );
64
- load_plugin_textdomain( 'simple-image-widget', false, dirname( plugin_basename( __FILE__ ) ) . 'languages/' );
65
  }
66
-
67
  /**
68
  * Register and localize generic script libraries.
69
  *
@@ -78,15 +72,15 @@ class Simple_Image_Widget_Loader {
78
  */
79
  public static function init() {
80
  wp_register_script( 'simple-image-widget', plugin_dir_url( __FILE__ ) . 'js/simple-image-widget.js', array( 'media-upload', 'media-views' ) );
81
-
82
  wp_localize_script( 'simple-image-widget', 'SimpleImageWidget', array(
83
  'frameTitle' => __( 'Choose an Attachment', 'simple-image-widget' ),
84
  'frameUpdateText' => __( 'Update Attachment', 'simple-image-widget' ),
85
  'fullSizeLabel' => __( 'Full Size', 'simple-image-widget' ),
86
- 'imageSizeNames' => self::get_image_size_names()
87
  ) );
88
  }
89
-
90
  /**
91
  * Register the image widget.
92
  *
@@ -95,7 +89,7 @@ class Simple_Image_Widget_Loader {
95
  public static function register_widget() {
96
  register_widget( 'Simple_Image_Widget' );
97
  }
98
-
99
  /**
100
  * Enqueue scripts needed for selecting media.
101
  *
@@ -107,7 +101,7 @@ class Simple_Image_Widget_Loader {
107
  wp_enqueue_script( 'simple-image-widget' );
108
  }
109
  }
110
-
111
  /**
112
  * Output CSS for styling the image widget in the dashboard.
113
  *
@@ -119,13 +113,13 @@ class Simple_Image_Widget_Loader {
119
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control { padding: 20px 0; text-align: center; border: 1px dashed #aaa;}
120
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control.has-image { padding: 10px; text-align: left; border: 1px dashed #aaa;}
121
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control img { display: block; margin-bottom: 10px; max-width: 100%; height: auto;}
122
-
123
  .simple-image-widget-legacy-fields { margin-bottom: 1em; padding: 10px; background-color: #e0e0e0; border-radius: 3px;}
124
  .simple-image-widget-legacy-fields p:last-child { margin-bottom: 0;}
125
  </style>
126
  <?php
127
  }
128
-
129
  /**
130
  * Output custom handler for when an image is selected in the media manager.
131
  *
@@ -141,21 +135,21 @@ class Simple_Image_Widget_Loader {
141
  model = selection.first(),
142
  sizes = model.get('sizes'),
143
  size, image;
144
-
145
  if ( sizes ) {
146
  // The image size to display in the widget.
147
  size = sizes['post-thumbnail'] || sizes.medium;
148
  }
149
-
150
  if ( $sizeField.length ) {
151
  // Builds the option elements for the size dropdown.
152
  SimpleImageWidget.updateSizeDropdownOptions( $sizeField, sizes );
153
  }
154
-
155
  size = size || model.toJSON();
156
-
157
  image = $( '<img />', { src: size.url, width: size.width } );
158
-
159
  $control.find('img').remove().end()
160
  .prepend( image )
161
  .addClass('has-image')
@@ -163,9 +157,9 @@ class Simple_Image_Widget_Loader {
163
  });
164
  });
165
  </script>
166
- <?php
167
  }
168
-
169
  /**
170
  * Get localized image size names.
171
  *
@@ -183,10 +177,11 @@ class Simple_Image_Widget_Loader {
183
  'thumbnail' => __( 'Thumbnail', 'simple-image-widget' ),
184
  'medium' => __( 'Medium', 'simple-image-widget' ),
185
  'large' => __( 'Large', 'simple-image-widget' ),
186
- 'full' => __( 'Full Size', 'simple-image-widget' )
187
  ) );
188
  }
189
  }
 
190
 
191
  /**
192
  * Check to see if the current version of WordPress supports the new media manager.
3
  * Plugin Name: Simple Image Widget
4
  * Plugin URI: https://wordpress.org/extend/plugins/simple-image-widget/
5
  * Description: A simple image widget utilizing the new WordPress media manager.
6
+ * Version: 3.0.4
7
  * Author: Blazer Six
8
  * Author URI: http://www.blazersix.com/
9
  * License: GPL-2.0+
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  * Text Domain: simple-image-widget
12
+ * Domain Path: /languages
13
  *
14
  * @package SimpleImageWidget
15
  * @author Brady Vercher <brady@blazersix.com>
22
  */
23
  require_once( plugin_dir_path( __FILE__ ) . 'class-simple-image-widget.php' );
24
 
 
 
 
 
 
25
  /**
26
  * The main plugin class for loading the widget and attaching necessary hooks.
27
  *
34
  * @since 3.0.0
35
  */
36
  public static function load() {
37
+ self::load_textdomain();
38
  add_action( 'widgets_init', array( __CLASS__, 'register_widget' ) );
39
+
40
  if ( is_simple_image_widget_legacy() ) {
41
  return;
42
  }
43
+
44
  add_action( 'init', array( __CLASS__, 'init' ) );
45
  add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_scripts' ) );
46
  add_action( 'admin_head-widgets.php', array( __CLASS__, 'admin_head_widgets' ) );
47
  add_action( 'admin_footer-widgets.php', array( __CLASS__, 'admin_footer_widgets' ) );
48
  }
49
+
50
  /**
51
  * Plugin localization support.
52
  *
53
  * @since 3.0.0
54
  */
55
+ public static function load_textdomain() {
 
56
  $locale = apply_filters( 'plugin_locale', get_locale(), 'simple-image-widget' );
57
+ load_textdomain( 'simple-image-widget', WP_LANG_DIR . '/simple-image-widget/' . $locale . '.mo' );
58
+ load_plugin_textdomain( 'simple-image-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
59
  }
60
+
61
  /**
62
  * Register and localize generic script libraries.
63
  *
72
  */
73
  public static function init() {
74
  wp_register_script( 'simple-image-widget', plugin_dir_url( __FILE__ ) . 'js/simple-image-widget.js', array( 'media-upload', 'media-views' ) );
75
+
76
  wp_localize_script( 'simple-image-widget', 'SimpleImageWidget', array(
77
  'frameTitle' => __( 'Choose an Attachment', 'simple-image-widget' ),
78
  'frameUpdateText' => __( 'Update Attachment', 'simple-image-widget' ),
79
  'fullSizeLabel' => __( 'Full Size', 'simple-image-widget' ),
80
+ 'imageSizeNames' => self::get_image_size_names(),
81
  ) );
82
  }
83
+
84
  /**
85
  * Register the image widget.
86
  *
89
  public static function register_widget() {
90
  register_widget( 'Simple_Image_Widget' );
91
  }
92
+
93
  /**
94
  * Enqueue scripts needed for selecting media.
95
  *
101
  wp_enqueue_script( 'simple-image-widget' );
102
  }
103
  }
104
+
105
  /**
106
  * Output CSS for styling the image widget in the dashboard.
107
  *
113
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control { padding: 20px 0; text-align: center; border: 1px dashed #aaa;}
114
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control.has-image { padding: 10px; text-align: left; border: 1px dashed #aaa;}
115
  .widget .widget-inside .simple-image-widget-form .simple-image-widget-control img { display: block; margin-bottom: 10px; max-width: 100%; height: auto;}
116
+
117
  .simple-image-widget-legacy-fields { margin-bottom: 1em; padding: 10px; background-color: #e0e0e0; border-radius: 3px;}
118
  .simple-image-widget-legacy-fields p:last-child { margin-bottom: 0;}
119
  </style>
120
  <?php
121
  }
122
+
123
  /**
124
  * Output custom handler for when an image is selected in the media manager.
125
  *
135
  model = selection.first(),
136
  sizes = model.get('sizes'),
137
  size, image;
138
+
139
  if ( sizes ) {
140
  // The image size to display in the widget.
141
  size = sizes['post-thumbnail'] || sizes.medium;
142
  }
143
+
144
  if ( $sizeField.length ) {
145
  // Builds the option elements for the size dropdown.
146
  SimpleImageWidget.updateSizeDropdownOptions( $sizeField, sizes );
147
  }
148
+
149
  size = size || model.toJSON();
150
+
151
  image = $( '<img />', { src: size.url, width: size.width } );
152
+
153
  $control.find('img').remove().end()
154
  .prepend( image )
155
  .addClass('has-image')
157
  });
158
  });
159
  </script>
160
+ <?php
161
  }
162
+
163
  /**
164
  * Get localized image size names.
165
  *
177
  'thumbnail' => __( 'Thumbnail', 'simple-image-widget' ),
178
  'medium' => __( 'Medium', 'simple-image-widget' ),
179
  'large' => __( 'Large', 'simple-image-widget' ),
180
+ 'full' => __( 'Full Size', 'simple-image-widget' ),
181
  ) );
182
  }
183
  }
184
+ add_action( 'plugins_loaded', array( 'Simple_Image_Widget_Loader', 'load' ) );
185
 
186
  /**
187
  * Check to see if the current version of WordPress supports the new media manager.