Version Description
Download this release
Release Info
Developer | ggwicz |
Plugin | Image Widget |
Version | 4.4.6 |
Comparing to | |
See all releases |
Code changes from version 4.4.5 to 4.4.6
- image-widget.php +135 -77
- readme.txt +6 -1
image-widget.php
CHANGED
@@ -4,7 +4,7 @@ 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.
|
8 |
Author URI: http://m.tri.be/iwpdoc
|
9 |
Text Domain: image-widget
|
10 |
Domain Path: /lang
|
@@ -21,12 +21,9 @@ function tribe_load_image_widget() {
|
|
21 |
}
|
22 |
add_action( 'widgets_init', 'tribe_load_image_widget' );
|
23 |
|
24 |
-
/**
|
25 |
-
* Tribe_Image_Widget class
|
26 |
-
**/
|
27 |
class Tribe_Image_Widget extends WP_Widget {
|
28 |
|
29 |
-
const VERSION = '4.4.
|
30 |
|
31 |
const CUSTOM_IMAGE_SIZE_SLUG = 'tribe_image_widget_custom';
|
32 |
|
@@ -34,13 +31,13 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
34 |
|
35 |
/**
|
36 |
* Tribe Image Widget constructor
|
37 |
-
*
|
38 |
-
* @author Modern Tribe, Inc.
|
39 |
*/
|
40 |
public function __construct() {
|
41 |
load_plugin_textdomain( 'image-widget', false, trailingslashit( basename( dirname( __FILE__ ) ) ) . 'lang/' );
|
42 |
-
|
|
|
43 |
$control_ops = array( 'id_base' => 'widget_sp_image' );
|
|
|
44 |
parent::__construct( 'widget_sp_image', __( 'Image Widget', 'image-widget' ), $widget_ops, $control_ops );
|
45 |
|
46 |
if ( $this->use_old_uploader() ) {
|
@@ -64,10 +61,14 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
64 |
|
65 |
/**
|
66 |
* Test to see if this version of WordPress supports the new image manager.
|
67 |
-
*
|
|
|
68 |
*/
|
69 |
private function use_old_uploader() {
|
70 |
-
if ( defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) )
|
|
|
|
|
|
|
71 |
return ! function_exists( 'wp_enqueue_media' );
|
72 |
}
|
73 |
|
@@ -78,17 +79,18 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
78 |
wp_enqueue_media();
|
79 |
|
80 |
wp_enqueue_style( 'tribe-image-widget', plugins_url( 'resources/css/admin.css', __FILE__ ), array(), self::VERSION );
|
81 |
-
|
82 |
wp_enqueue_script( 'tribe-image-widget', plugins_url( 'resources/js/image-widget.js', __FILE__ ), array( 'jquery', 'media-upload', 'media-views' ), self::VERSION );
|
83 |
|
84 |
wp_localize_script( 'tribe-image-widget', 'TribeImageWidget', array(
|
85 |
-
'frame_title'
|
86 |
'button_title' => __( 'Insert Into Widget', 'image-widget' ),
|
87 |
) );
|
88 |
}
|
89 |
|
|
|
|
|
|
|
90 |
public function maybe_admin_setup() {
|
91 |
-
// Only load on widget admin page and in the "Customizer" view.
|
92 |
$screen = get_current_screen();
|
93 |
|
94 |
if ( 'customize' !== $screen->base ) {
|
@@ -103,31 +105,33 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
103 |
*
|
104 |
* @param array $args
|
105 |
* @param array $instance
|
106 |
-
* @author Modern Tribe, Inc.
|
107 |
*/
|
108 |
public function widget( $args, $instance ) {
|
109 |
extract( $args );
|
|
|
110 |
$instance = wp_parse_args( (array) $instance, self::get_defaults() );
|
|
|
111 |
if ( ! empty( $instance['imageurl'] ) || ! empty( $instance['attachment_id'] ) ) {
|
112 |
|
113 |
-
$instance['title']
|
114 |
$instance['description'] = apply_filters( 'widget_text', $instance['description'], $args, $instance );
|
115 |
-
$instance['link']
|
116 |
-
$instance['linkid']
|
117 |
-
$instance['linktarget']
|
118 |
-
$instance['width']
|
119 |
-
$instance['height']
|
120 |
-
$instance['maxwidth']
|
121 |
-
$instance['maxheight']
|
122 |
-
$instance['align']
|
123 |
-
$instance['alt']
|
124 |
-
$instance['rel']
|
125 |
|
126 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
127 |
$instance['attachment_id'] = ( $instance['attachment_id'] > 0 ) ? $instance['attachment_id'] : $instance['image'];
|
128 |
$instance['attachment_id'] = apply_filters( 'image_widget_image_attachment_id', abs( $instance['attachment_id'] ), $args, $instance );
|
129 |
-
$instance['size']
|
130 |
}
|
|
|
131 |
$instance['imageurl'] = apply_filters( 'image_widget_image_url', esc_url( $instance['imageurl'] ), $args, $instance );
|
132 |
|
133 |
// No longer using extracted vars. This is here for backwards compatibility.
|
@@ -143,28 +147,44 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
143 |
* @param object $new_instance Widget Instance
|
144 |
* @param object $old_instance Widget Instance
|
145 |
* @return object
|
146 |
-
* @author Modern Tribe, Inc.
|
147 |
*/
|
148 |
public function update( $new_instance, $old_instance ) {
|
149 |
-
|
|
|
150 |
$new_instance = wp_parse_args( (array) $new_instance, self::get_defaults() );
|
|
|
151 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
|
|
152 |
if ( current_user_can( 'unfiltered_html' ) ) {
|
153 |
$instance['description'] = $new_instance['description'];
|
154 |
} else {
|
155 |
-
$instance['description'] =
|
156 |
}
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
$instance['linktarget'] = $new_instance['linktarget'];
|
160 |
-
$instance['width']
|
161 |
-
$instance['height']
|
|
|
162 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
163 |
$instance['size'] = $new_instance['size'];
|
164 |
}
|
|
|
165 |
$instance['align'] = $new_instance['align'];
|
166 |
-
$instance['alt']
|
167 |
-
$instance['rel']
|
168 |
|
169 |
// Reverse compatibility with $image, now called $attachement_id
|
170 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) && $new_instance['attachment_id'] > 0 ) {
|
@@ -175,8 +195,8 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
175 |
$instance['imageurl'] = ImageWidgetDeprecated::get_image_url( $instance['image'], $instance['width'], $instance['height'] ); // image resizing not working right now
|
176 |
}
|
177 |
}
|
178 |
-
$instance['imageurl'] = $new_instance['imageurl']; // deprecated
|
179 |
|
|
|
180 |
$instance['aspect_ratio'] = $this->get_image_aspect_ratio( $instance );
|
181 |
|
182 |
return $instance;
|
@@ -186,7 +206,6 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
186 |
* Form UI
|
187 |
*
|
188 |
* @param object $instance Widget Instance
|
189 |
-
* @author Modern Tribe, Inc.
|
190 |
*/
|
191 |
public function form( $instance ) {
|
192 |
$instance = wp_parse_args( (array) $instance, self::get_defaults() );
|
@@ -205,24 +224,24 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
205 |
private static function get_defaults() {
|
206 |
|
207 |
$defaults = array(
|
208 |
-
'title'
|
209 |
'description' => '',
|
210 |
-
'link'
|
211 |
-
'linkid'
|
212 |
-
'linktarget'
|
213 |
-
'width'
|
214 |
-
'height'
|
215 |
-
'maxwidth'
|
216 |
-
'maxheight'
|
217 |
-
'image'
|
218 |
-
'imageurl'
|
219 |
-
'align'
|
220 |
-
'alt'
|
221 |
-
'rel'
|
222 |
);
|
223 |
|
224 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
225 |
-
$defaults['size']
|
226 |
$defaults['attachment_id'] = 0;
|
227 |
}
|
228 |
|
@@ -246,17 +265,21 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
246 |
$output = '';
|
247 |
|
248 |
if ( $include_link && ! empty( $instance['link'] ) ) {
|
|
|
249 |
$attr = array(
|
250 |
-
'href'
|
251 |
-
'id'
|
252 |
'target' => $instance['linktarget'],
|
253 |
-
'class'
|
254 |
-
'title'
|
255 |
-
'rel'
|
256 |
);
|
|
|
257 |
$attr = apply_filters( 'image_widget_link_attributes', $attr, $instance );
|
258 |
$attr = array_map( 'esc_attr', $attr );
|
|
|
259 |
$output = '<a';
|
|
|
260 |
foreach ( $attr as $name => $value ) {
|
261 |
if ( ! empty( $value ) ) {
|
262 |
$output .= sprintf( ' %s="%s"', $name, $value );
|
@@ -266,16 +289,17 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
266 |
}
|
267 |
|
268 |
$size = $this->get_image_size( $instance );
|
|
|
269 |
if ( is_array( $size ) ) {
|
270 |
-
$instance['width']
|
271 |
$instance['height'] = $size[1];
|
272 |
} elseif ( ! empty( $instance['attachment_id'] ) ) {
|
273 |
//$instance['width'] = $instance['height'] = 0;
|
274 |
$image_details = wp_get_attachment_image_src( $instance['attachment_id'], $size );
|
275 |
if ( $image_details ) {
|
276 |
$instance['imageurl'] = $image_details[0];
|
277 |
-
$instance['width']
|
278 |
-
$instance['height']
|
279 |
}
|
280 |
|
281 |
$image_srcset = function_exists( 'wp_get_attachment_image_srcset' )
|
@@ -292,7 +316,8 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
292 |
}
|
293 |
}
|
294 |
}
|
295 |
-
|
|
|
296 |
$instance['height'] = abs( $instance['height'] );
|
297 |
|
298 |
$attr = array();
|
@@ -329,19 +354,30 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
329 |
if ( ! empty( $instance['sizes'] ) ) {
|
330 |
$attr['sizes'] = $instance['sizes'];
|
331 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
$attr = apply_filters( 'image_widget_image_attributes', $attr, $instance );
|
333 |
|
334 |
// If there is an imageurl, use it to render the image. Eventually we should kill this and simply rely on attachment_ids.
|
335 |
if ( ! empty( $instance['imageurl'] ) ) {
|
336 |
// If all we have is an image src url we can still render an image.
|
337 |
$attr['src'] = $instance['imageurl'];
|
338 |
-
$attr
|
339 |
-
$hwstring
|
|
|
340 |
$output .= rtrim( "<img $hwstring" );
|
|
|
341 |
foreach ( $attr as $name => $value ) {
|
342 |
$output .= sprintf( ' %s="%s"', $name, $value );
|
343 |
}
|
|
|
344 |
$output .= ' />';
|
|
|
345 |
} elseif ( abs( $instance['attachment_id'] ) > 0 ) {
|
346 |
$output .= wp_get_attachment_image( $instance['attachment_id'], $size, false, $attr );
|
347 |
}
|
@@ -371,6 +407,11 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
371 |
self::CUSTOM_IMAGE_SIZE_SLUG => __( 'Custom', 'image-widget' ),
|
372 |
) );
|
373 |
|
|
|
|
|
|
|
|
|
|
|
374 |
return (array) apply_filters( 'image_size_names_choose', $possible_sizes );
|
375 |
}
|
376 |
|
@@ -389,6 +430,7 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
389 |
} else {
|
390 |
$size = 'full';
|
391 |
}
|
|
|
392 |
return $size;
|
393 |
}
|
394 |
|
@@ -419,19 +461,24 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
419 |
*
|
420 |
* @param string $template template file to search for
|
421 |
* @return template path
|
422 |
-
|
423 |
-
**/
|
424 |
|
425 |
public function getTemplateHierarchy( $template ) {
|
426 |
// whether or not .php was added
|
427 |
$template_slug = rtrim( $template, '.php' );
|
428 |
-
$template
|
429 |
|
430 |
if ( $theme_file = locate_template( array( 'image-widget/' . $template ) ) ) {
|
431 |
$file = $theme_file;
|
432 |
} else {
|
433 |
$file = 'views/' . $template;
|
434 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
return apply_filters( 'sp_template_image-widget_' . $template, $file );
|
436 |
}
|
437 |
|
@@ -483,8 +530,12 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
483 |
* AJAX handler to store the state of dismissible notices.
|
484 |
*/
|
485 |
public function ajax_notice_handler() {
|
486 |
-
if ( empty( $_POST['key'] ) )
|
|
|
|
|
|
|
487 |
$key = $this->generate_key( sanitize_text_field( $_POST['key'] ) );
|
|
|
488 |
update_site_option( $key, self::VERSION );
|
489 |
}
|
490 |
|
@@ -494,12 +545,8 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
494 |
* @param string $key
|
495 |
* @return string option key
|
496 |
*/
|
497 |
-
private function generate_key( $key ) {
|
498 |
-
|
499 |
-
self::VERSION_KEY,
|
500 |
-
$key,
|
501 |
-
) );
|
502 |
-
return $option_key;
|
503 |
}
|
504 |
|
505 |
/**
|
@@ -508,14 +555,19 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
508 |
* @return string alert message.
|
509 |
*/
|
510 |
private function upgrade_nag_plugins_admin_msg() {
|
511 |
-
$key
|
512 |
$option_key = $this->generate_key( $key );
|
513 |
-
|
|
|
|
|
|
|
|
|
514 |
$msg = sprintf(
|
515 |
__( '<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' ),
|
516 |
'http://m.tri.be/19my',
|
517 |
'http://m.tri.be/19my'
|
518 |
);
|
|
|
519 |
return "<div class='notice notice-info is-dismissible image-widget-notice' data-key='$key'>$msg</div>";
|
520 |
}
|
521 |
|
@@ -525,27 +577,33 @@ class Tribe_Image_Widget extends WP_Widget {
|
|
525 |
* @return string alert message.
|
526 |
*/
|
527 |
private function upgrade_nag_widget_admin_msg() {
|
528 |
-
$key
|
529 |
$option_key = $this->generate_key( $key );
|
530 |
-
|
|
|
|
|
|
|
|
|
531 |
$msg = sprintf(
|
532 |
__( '<p class="dashicons-before dashicons-star-filled"><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' ),
|
533 |
'http://m.tri.be/19mx'
|
534 |
);
|
|
|
535 |
return "<div class='notice notice-info is-dismissible image-widget-notice' data-key='$key'>$msg</div>";
|
536 |
}
|
537 |
|
538 |
/**
|
539 |
* Display an informational section in the plugin admin ui.
|
|
|
540 |
* @param $meta
|
541 |
* @param $file
|
542 |
-
*
|
543 |
* @return array
|
544 |
*/
|
545 |
public function plugin_row_meta( $meta, $file ) {
|
546 |
if ( $file == plugin_basename( dirname( __FILE__ ) . '/image-widget.php' ) ) {
|
547 |
$meta[] = '<strong><a href="http://m.tri.be/19ma" target="_blank">' . esc_html__( 'Image Widget Plus', 'image-widget' ) . '</a></strong>';
|
548 |
}
|
|
|
549 |
return $meta;
|
550 |
}
|
551 |
}
|
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.6
|
8 |
Author URI: http://m.tri.be/iwpdoc
|
9 |
Text Domain: image-widget
|
10 |
Domain Path: /lang
|
21 |
}
|
22 |
add_action( 'widgets_init', 'tribe_load_image_widget' );
|
23 |
|
|
|
|
|
|
|
24 |
class Tribe_Image_Widget extends WP_Widget {
|
25 |
|
26 |
+
const VERSION = '4.4.6';
|
27 |
|
28 |
const CUSTOM_IMAGE_SIZE_SLUG = 'tribe_image_widget_custom';
|
29 |
|
31 |
|
32 |
/**
|
33 |
* Tribe Image Widget constructor
|
|
|
|
|
34 |
*/
|
35 |
public function __construct() {
|
36 |
load_plugin_textdomain( 'image-widget', false, trailingslashit( basename( dirname( __FILE__ ) ) ) . 'lang/' );
|
37 |
+
|
38 |
+
$widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', 'image-widget' ) );
|
39 |
$control_ops = array( 'id_base' => 'widget_sp_image' );
|
40 |
+
|
41 |
parent::__construct( 'widget_sp_image', __( 'Image Widget', 'image-widget' ), $widget_ops, $control_ops );
|
42 |
|
43 |
if ( $this->use_old_uploader() ) {
|
61 |
|
62 |
/**
|
63 |
* Test to see if this version of WordPress supports the new image manager.
|
64 |
+
*
|
65 |
+
* @return bool True if the current version of WordPress does NOT support the current image management tech.
|
66 |
*/
|
67 |
private function use_old_uploader() {
|
68 |
+
if ( defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
69 |
+
return true;
|
70 |
+
}
|
71 |
+
|
72 |
return ! function_exists( 'wp_enqueue_media' );
|
73 |
}
|
74 |
|
79 |
wp_enqueue_media();
|
80 |
|
81 |
wp_enqueue_style( 'tribe-image-widget', plugins_url( 'resources/css/admin.css', __FILE__ ), array(), self::VERSION );
|
|
|
82 |
wp_enqueue_script( 'tribe-image-widget', plugins_url( 'resources/js/image-widget.js', __FILE__ ), array( 'jquery', 'media-upload', 'media-views' ), self::VERSION );
|
83 |
|
84 |
wp_localize_script( 'tribe-image-widget', 'TribeImageWidget', array(
|
85 |
+
'frame_title' => __( 'Select an Image', 'image-widget' ),
|
86 |
'button_title' => __( 'Insert Into Widget', 'image-widget' ),
|
87 |
) );
|
88 |
}
|
89 |
|
90 |
+
/**
|
91 |
+
* Trigger the enqueueing of admin scripts and styles on widget admin page and in the "Customizer" view.
|
92 |
+
*/
|
93 |
public function maybe_admin_setup() {
|
|
|
94 |
$screen = get_current_screen();
|
95 |
|
96 |
if ( 'customize' !== $screen->base ) {
|
105 |
*
|
106 |
* @param array $args
|
107 |
* @param array $instance
|
|
|
108 |
*/
|
109 |
public function widget( $args, $instance ) {
|
110 |
extract( $args );
|
111 |
+
|
112 |
$instance = wp_parse_args( (array) $instance, self::get_defaults() );
|
113 |
+
|
114 |
if ( ! empty( $instance['imageurl'] ) || ! empty( $instance['attachment_id'] ) ) {
|
115 |
|
116 |
+
$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'] );
|
117 |
$instance['description'] = apply_filters( 'widget_text', $instance['description'], $args, $instance );
|
118 |
+
$instance['link'] = apply_filters( 'image_widget_image_link', esc_url( $instance['link'] ), $args, $instance );
|
119 |
+
$instance['linkid'] = apply_filters( 'image_widget_image_link_id', esc_attr( $instance['linkid'] ), $args, $instance );
|
120 |
+
$instance['linktarget'] = apply_filters( 'image_widget_image_link_target', esc_attr( $instance['linktarget'] ), $args, $instance );
|
121 |
+
$instance['width'] = apply_filters( 'image_widget_image_width', abs( $instance['width'] ), $args, $instance );
|
122 |
+
$instance['height'] = apply_filters( 'image_widget_image_height', abs( $instance['height'] ), $args, $instance );
|
123 |
+
$instance['maxwidth'] = apply_filters( 'image_widget_image_maxwidth', esc_attr( $instance['maxwidth'] ), $args, $instance );
|
124 |
+
$instance['maxheight'] = apply_filters( 'image_widget_image_maxheight', esc_attr( $instance['maxheight'] ), $args, $instance );
|
125 |
+
$instance['align'] = apply_filters( 'image_widget_image_align', esc_attr( $instance['align'] ), $args, $instance );
|
126 |
+
$instance['alt'] = apply_filters( 'image_widget_image_alt', esc_attr( $instance['alt'] ), $args, $instance );
|
127 |
+
$instance['rel'] = apply_filters( 'image_widget_image_rel', esc_attr( $instance['rel'] ), $args, $instance );
|
128 |
|
129 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
130 |
$instance['attachment_id'] = ( $instance['attachment_id'] > 0 ) ? $instance['attachment_id'] : $instance['image'];
|
131 |
$instance['attachment_id'] = apply_filters( 'image_widget_image_attachment_id', abs( $instance['attachment_id'] ), $args, $instance );
|
132 |
+
$instance['size'] = apply_filters( 'image_widget_image_size', esc_attr( $instance['size'] ), $args, $instance );
|
133 |
}
|
134 |
+
|
135 |
$instance['imageurl'] = apply_filters( 'image_widget_image_url', esc_url( $instance['imageurl'] ), $args, $instance );
|
136 |
|
137 |
// No longer using extracted vars. This is here for backwards compatibility.
|
147 |
* @param object $new_instance Widget Instance
|
148 |
* @param object $old_instance Widget Instance
|
149 |
* @return object
|
|
|
150 |
*/
|
151 |
public function update( $new_instance, $old_instance ) {
|
152 |
+
|
153 |
+
$instance = $old_instance;
|
154 |
$new_instance = wp_parse_args( (array) $new_instance, self::get_defaults() );
|
155 |
+
|
156 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
157 |
+
|
158 |
if ( current_user_can( 'unfiltered_html' ) ) {
|
159 |
$instance['description'] = $new_instance['description'];
|
160 |
} else {
|
161 |
+
$instance['description'] = wp_kses_post( $new_instance['description'] );
|
162 |
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Make the description filterable; especially useful for working with allowing/disallowing HTML and other content.
|
166 |
+
*
|
167 |
+
* @since 4.4.6
|
168 |
+
*
|
169 |
+
* @param $description The current value of $instance['description'].
|
170 |
+
* @param $new_instance The new instance of the widget, i.e. the new values being saved for it.
|
171 |
+
* @param $old_instance The pre-existing instance of the widget, i.e. the values that are potentially being updated.
|
172 |
+
*/
|
173 |
+
$instance['description'] = apply_filters( 'tribe_image_widget_instance_description', $instance['description'], $new_instance, $old_instance );
|
174 |
+
|
175 |
+
$instance['link'] = $new_instance['link'];
|
176 |
+
$instance['linkid'] = $new_instance['linkid'];
|
177 |
$instance['linktarget'] = $new_instance['linktarget'];
|
178 |
+
$instance['width'] = abs( $new_instance['width'] );
|
179 |
+
$instance['height'] = abs( $new_instance['height'] );
|
180 |
+
|
181 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
182 |
$instance['size'] = $new_instance['size'];
|
183 |
}
|
184 |
+
|
185 |
$instance['align'] = $new_instance['align'];
|
186 |
+
$instance['alt'] = $new_instance['alt'];
|
187 |
+
$instance['rel'] = $new_instance['rel'];
|
188 |
|
189 |
// Reverse compatibility with $image, now called $attachement_id
|
190 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) && $new_instance['attachment_id'] > 0 ) {
|
195 |
$instance['imageurl'] = ImageWidgetDeprecated::get_image_url( $instance['image'], $instance['width'], $instance['height'] ); // image resizing not working right now
|
196 |
}
|
197 |
}
|
|
|
198 |
|
199 |
+
$instance['imageurl'] = $new_instance['imageurl']; // deprecated
|
200 |
$instance['aspect_ratio'] = $this->get_image_aspect_ratio( $instance );
|
201 |
|
202 |
return $instance;
|
206 |
* Form UI
|
207 |
*
|
208 |
* @param object $instance Widget Instance
|
|
|
209 |
*/
|
210 |
public function form( $instance ) {
|
211 |
$instance = wp_parse_args( (array) $instance, self::get_defaults() );
|
224 |
private static function get_defaults() {
|
225 |
|
226 |
$defaults = array(
|
227 |
+
'title' => '',
|
228 |
'description' => '',
|
229 |
+
'link' => '',
|
230 |
+
'linkid' => '',
|
231 |
+
'linktarget' => '',
|
232 |
+
'width' => 0,
|
233 |
+
'height' => 0,
|
234 |
+
'maxwidth' => '100%',
|
235 |
+
'maxheight' => '',
|
236 |
+
'image' => 0, // reverse compatible - now attachement_id
|
237 |
+
'imageurl' => '', // reverse compatible.
|
238 |
+
'align' => 'none',
|
239 |
+
'alt' => '',
|
240 |
+
'rel' => '',
|
241 |
);
|
242 |
|
243 |
if ( ! defined( 'IMAGE_WIDGET_COMPATIBILITY_TEST' ) ) {
|
244 |
+
$defaults['size'] = self::CUSTOM_IMAGE_SIZE_SLUG;
|
245 |
$defaults['attachment_id'] = 0;
|
246 |
}
|
247 |
|
265 |
$output = '';
|
266 |
|
267 |
if ( $include_link && ! empty( $instance['link'] ) ) {
|
268 |
+
|
269 |
$attr = array(
|
270 |
+
'href' => $instance['link'],
|
271 |
+
'id' => $instance['linkid'],
|
272 |
'target' => $instance['linktarget'],
|
273 |
+
'class' => $this->widget_options['classname'] . '-image-link',
|
274 |
+
'title' => ( ! empty( $instance['alt'] ) ) ? $instance['alt'] : $instance['title'],
|
275 |
+
'rel' => $instance['rel'],
|
276 |
);
|
277 |
+
|
278 |
$attr = apply_filters( 'image_widget_link_attributes', $attr, $instance );
|
279 |
$attr = array_map( 'esc_attr', $attr );
|
280 |
+
|
281 |
$output = '<a';
|
282 |
+
|
283 |
foreach ( $attr as $name => $value ) {
|
284 |
if ( ! empty( $value ) ) {
|
285 |
$output .= sprintf( ' %s="%s"', $name, $value );
|
289 |
}
|
290 |
|
291 |
$size = $this->get_image_size( $instance );
|
292 |
+
|
293 |
if ( is_array( $size ) ) {
|
294 |
+
$instance['width'] = $size[0];
|
295 |
$instance['height'] = $size[1];
|
296 |
} elseif ( ! empty( $instance['attachment_id'] ) ) {
|
297 |
//$instance['width'] = $instance['height'] = 0;
|
298 |
$image_details = wp_get_attachment_image_src( $instance['attachment_id'], $size );
|
299 |
if ( $image_details ) {
|
300 |
$instance['imageurl'] = $image_details[0];
|
301 |
+
$instance['width'] = $image_details[1];
|
302 |
+
$instance['height'] = $image_details[2];
|
303 |
}
|
304 |
|
305 |
$image_srcset = function_exists( 'wp_get_attachment_image_srcset' )
|
316 |
}
|
317 |
}
|
318 |
}
|
319 |
+
|
320 |
+
$instance['width'] = abs( $instance['width'] );
|
321 |
$instance['height'] = abs( $instance['height'] );
|
322 |
|
323 |
$attr = array();
|
354 |
if ( ! empty( $instance['sizes'] ) ) {
|
355 |
$attr['sizes'] = $instance['sizes'];
|
356 |
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Allow filtering of the image attributes used on the front-end.
|
360 |
+
*
|
361 |
+
* @param array $attr Image attributes to be filtered.
|
362 |
+
* @param array $instance The current widget instance.
|
363 |
+
*/
|
364 |
$attr = apply_filters( 'image_widget_image_attributes', $attr, $instance );
|
365 |
|
366 |
// If there is an imageurl, use it to render the image. Eventually we should kill this and simply rely on attachment_ids.
|
367 |
if ( ! empty( $instance['imageurl'] ) ) {
|
368 |
// If all we have is an image src url we can still render an image.
|
369 |
$attr['src'] = $instance['imageurl'];
|
370 |
+
$attr = array_map( 'esc_attr', $attr );
|
371 |
+
$hwstring = image_hwstring( $instance['width'], $instance['height'] );
|
372 |
+
|
373 |
$output .= rtrim( "<img $hwstring" );
|
374 |
+
|
375 |
foreach ( $attr as $name => $value ) {
|
376 |
$output .= sprintf( ' %s="%s"', $name, $value );
|
377 |
}
|
378 |
+
|
379 |
$output .= ' />';
|
380 |
+
|
381 |
} elseif ( abs( $instance['attachment_id'] ) > 0 ) {
|
382 |
$output .= wp_get_attachment_image( $instance['attachment_id'], $size, false, $attr );
|
383 |
}
|
407 |
self::CUSTOM_IMAGE_SIZE_SLUG => __( 'Custom', 'image-widget' ),
|
408 |
) );
|
409 |
|
410 |
+
/**
|
411 |
+
* Allow filtering the image sizes available for use in the Image Widget dropdown
|
412 |
+
*
|
413 |
+
* @param array $possible_sizes The array of available sizes.
|
414 |
+
*/
|
415 |
return (array) apply_filters( 'image_size_names_choose', $possible_sizes );
|
416 |
}
|
417 |
|
430 |
} else {
|
431 |
$size = 'full';
|
432 |
}
|
433 |
+
|
434 |
return $size;
|
435 |
}
|
436 |
|
461 |
*
|
462 |
* @param string $template template file to search for
|
463 |
* @return template path
|
464 |
+
*/
|
|
|
465 |
|
466 |
public function getTemplateHierarchy( $template ) {
|
467 |
// whether or not .php was added
|
468 |
$template_slug = rtrim( $template, '.php' );
|
469 |
+
$template = $template_slug . '.php';
|
470 |
|
471 |
if ( $theme_file = locate_template( array( 'image-widget/' . $template ) ) ) {
|
472 |
$file = $theme_file;
|
473 |
} else {
|
474 |
$file = 'views/' . $template;
|
475 |
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Allow filtering of currently-retrieved Image Widget template file's path.
|
479 |
+
*
|
480 |
+
* @param string $file The retrieved template file's path.
|
481 |
+
*/
|
482 |
return apply_filters( 'sp_template_image-widget_' . $template, $file );
|
483 |
}
|
484 |
|
530 |
* AJAX handler to store the state of dismissible notices.
|
531 |
*/
|
532 |
public function ajax_notice_handler() {
|
533 |
+
if ( empty( $_POST['key'] ) ) {
|
534 |
+
return;
|
535 |
+
}
|
536 |
+
|
537 |
$key = $this->generate_key( sanitize_text_field( $_POST['key'] ) );
|
538 |
+
|
539 |
update_site_option( $key, self::VERSION );
|
540 |
}
|
541 |
|
545 |
* @param string $key
|
546 |
* @return string option key
|
547 |
*/
|
548 |
+
private function generate_key( $key ) {
|
549 |
+
return join( '_', array( self::VERSION_KEY, $key, ) );
|
|
|
|
|
|
|
|
|
550 |
}
|
551 |
|
552 |
/**
|
555 |
* @return string alert message.
|
556 |
*/
|
557 |
private function upgrade_nag_plugins_admin_msg() {
|
558 |
+
$key = 'plugin';
|
559 |
$option_key = $this->generate_key( $key );
|
560 |
+
|
561 |
+
if ( get_site_option( $option_key ) == self::VERSION ) {
|
562 |
+
return;
|
563 |
+
}
|
564 |
+
|
565 |
$msg = sprintf(
|
566 |
__( '<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' ),
|
567 |
'http://m.tri.be/19my',
|
568 |
'http://m.tri.be/19my'
|
569 |
);
|
570 |
+
|
571 |
return "<div class='notice notice-info is-dismissible image-widget-notice' data-key='$key'>$msg</div>";
|
572 |
}
|
573 |
|
577 |
* @return string alert message.
|
578 |
*/
|
579 |
private function upgrade_nag_widget_admin_msg() {
|
580 |
+
$key = 'widget';
|
581 |
$option_key = $this->generate_key( $key );
|
582 |
+
|
583 |
+
if ( get_site_option( $option_key ) == self::VERSION ) {
|
584 |
+
return;
|
585 |
+
}
|
586 |
+
|
587 |
$msg = sprintf(
|
588 |
__( '<p class="dashicons-before dashicons-star-filled"><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' ),
|
589 |
'http://m.tri.be/19mx'
|
590 |
);
|
591 |
+
|
592 |
return "<div class='notice notice-info is-dismissible image-widget-notice' data-key='$key'>$msg</div>";
|
593 |
}
|
594 |
|
595 |
/**
|
596 |
* Display an informational section in the plugin admin ui.
|
597 |
+
*
|
598 |
* @param $meta
|
599 |
* @param $file
|
|
|
600 |
* @return array
|
601 |
*/
|
602 |
public function plugin_row_meta( $meta, $file ) {
|
603 |
if ( $file == plugin_basename( dirname( __FILE__ ) . '/image-widget.php' ) ) {
|
604 |
$meta[] = '<strong><a href="http://m.tri.be/19ma" target="_blank">' . esc_html__( 'Image Widget Plus', 'image-widget' ) . '</a></strong>';
|
605 |
}
|
606 |
+
|
607 |
return $meta;
|
608 |
}
|
609 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
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.8
|
7 |
-
Stable tag: 4.4.
|
8 |
|
9 |
A simple image widget that uses the native WordPress media manager to add image widgets to your site.
|
10 |
|
@@ -206,6 +206,11 @@ For more info on the philosophy here, check out our [blog post](http://tri.be/de
|
|
206 |
|
207 |
== Changelog ==
|
208 |
|
|
|
|
|
|
|
|
|
|
|
209 |
= [4.4.5] 2017-06-14 =
|
210 |
|
211 |
* Fix issue with image URLs in the widget admin interface [80659]
|
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.8
|
7 |
+
Stable tag: 4.4.6
|
8 |
|
9 |
A simple image widget that uses the native WordPress media manager to add image widgets to your site.
|
10 |
|
206 |
|
207 |
== Changelog ==
|
208 |
|
209 |
+
= [4.4.6] 2017-09-12 =
|
210 |
+
|
211 |
+
* New - Added new filter `tribe_image_widget_instance_description` for more control over how the description field is handled.
|
212 |
+
* Fix - Prevent broken HTML in the "description" field that sometimes arose with certain user roles. Props to users @bridgetashley and @JoshRoy spotting this one!
|
213 |
+
|
214 |
= [4.4.5] 2017-06-14 =
|
215 |
|
216 |
* Fix issue with image URLs in the widget admin interface [80659]
|