diff --git a/widgets/image.php b/widgets/image.php index 64cca9b..0ef2c8c 100644 --- a/widgets/image.php +++ b/widgets/image.php @@ -31,12 +31,18 @@ public function __construct() { public function widget( $args, $instance ) { $classes = $instance['responsive']; $classes .= ' ' . $instance['shape']; - $alt = $instance['alt']; - $url = isset( $instance['url'] ) ? $instance['url'] : ''; + $alt = $instance['alt']; + $caption = isset( $instance['caption'] ) ? trim($instance['caption']) : ''; + $url = isset( $instance['url'] ) ? $instance['url'] : ''; echo $args['before_widget']; - ?> - <?php echo $alt; ?> - +
+ <?php echo $alt; ?> +
+
+ + <?php echo $alt; ?> + form_field_url( $instance ); $this->form_field_alt( $instance ); + $this->form_field_caption( $instance ); $this->form_field_dimensions( $instance ); $this->form_field_responsive( $instance ); $this->form_field_shape( $instance ); @@ -84,6 +91,19 @@ public function form_field_alt( $instance ) { wpbw_field_text( $name, __( 'Descriptive Text (alt):' ), compact( 'id', 'placeholder' ), $value ); } + /** + * The image caption text + * + * @param $instance + */ + public function form_field_caption( $instance ) { + $id = $this->get_field_id( 'caption' ); + $name = $this->get_field_name( 'caption' ); + $value = isset( $instance['caption'] ) ? $instance['caption'] : ''; + $placeholder = 'eg. Photo of cat pouncing'; + wpbw_field_text( $name, __( 'Caption (optional):' ), compact( 'id', 'placeholder' ), $value ); + } + /** * The image width and height attributes * @@ -148,6 +168,7 @@ public function update( $new_instance, $old_instance ) { $instance = array(); $instance['url'] = filter_var( $new_instance['url'], FILTER_VALIDATE_URL ); $instance['alt'] = strip_tags( $new_instance['alt'] ); + $instance['caption'] = strip_tags( $new_instance['caption'] ); $instance['responsive'] = strip_tags( $new_instance['responsive'] ); $instance['shape'] = strip_tags( $new_instance['shape'] );