Skip to content

Commit

Permalink
Merge branch 'feature/image-caption' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrossi committed Aug 17, 2016
2 parents 641c28d + 50931e0 commit 53e8686
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions widgets/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
?>
<img src="<?php echo $url; ?>" class="<?php echo $classes; ?>" alt="<?php echo $alt; ?>" />
<?php
if ($caption): ?>
<div class="thumbnail">
<img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" class="<?php echo $classes; ?>">
<div class="caption"><?php echo $caption; ?></div>
</div>
<?php else: ?>
<img src="<?php echo $url; ?>" class="<?php echo $classes; ?>" alt="<?php echo $alt; ?>" />
<?php endif;
echo $args['after_widget'];
}

Expand All @@ -50,6 +56,7 @@ public function widget( $args, $instance ) {
public function form( $instance ) {
$this->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 );
Expand Down Expand Up @@ -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 <em>(optional)</em>:' ), compact( 'id', 'placeholder' ), $value );
}

/**
* The image width and height attributes
*
Expand Down Expand Up @@ -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'] );

Expand Down

0 comments on commit 53e8686

Please sign in to comment.