diff options
Diffstat (limited to 'plugins/jetpack/modules/widgets/image-widget.php')
-rw-r--r-- | plugins/jetpack/modules/widgets/image-widget.php | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/plugins/jetpack/modules/widgets/image-widget.php b/plugins/jetpack/modules/widgets/image-widget.php index aabbb43f..37a353c1 100644 --- a/plugins/jetpack/modules/widgets/image-widget.php +++ b/plugins/jetpack/modules/widgets/image-widget.php @@ -27,8 +27,8 @@ class Jetpack_Image_Widget extends WP_Widget { /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', esc_html__( 'Image', 'jetpack' ) ), array( - 'classname' => 'widget_image', - 'description' => __( 'Display an image in your sidebar', 'jetpack' ), + 'classname' => 'widget_image', + 'description' => __( 'Display an image in your sidebar', 'jetpack' ), 'customize_selective_refresh' => true, ) ); @@ -58,10 +58,12 @@ class Jetpack_Image_Widget extends WP_Widget { public function widget( $args, $instance ) { echo $args['before_widget']; - $instance = wp_parse_args( $instance, array( - 'title' => '', - 'img_url' => '' - ) ); + $instance = wp_parse_args( + $instance, array( + 'title' => '', + 'img_url' => '', + ) + ); /** This filter is documented in core/src/wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $instance['title'] ); @@ -75,19 +77,19 @@ class Jetpack_Image_Widget extends WP_Widget { $output = '<img src="' . esc_url( $instance['img_url'] ) . '" '; if ( '' != $instance['alt_text'] ) { - $output .= 'alt="' . esc_attr( $instance['alt_text'] ) .'" '; + $output .= 'alt="' . esc_attr( $instance['alt_text'] ) . '" '; } if ( '' != $instance['img_title'] ) { - $output .= 'title="' . esc_attr( $instance['img_title'] ) .'" '; + $output .= 'title="' . esc_attr( $instance['img_title'] ) . '" '; } if ( '' == $instance['caption'] ) { $output .= 'class="align' . esc_attr( $instance['align'] ) . '" '; } if ( '' != $instance['img_width'] ) { - $output .= 'width="' . esc_attr( $instance['img_width'] ) .'" '; + $output .= 'width="' . esc_attr( $instance['img_width'] ) . '" '; } if ( '' != $instance['img_height'] ) { - $output .= 'height="' . esc_attr( $instance['img_height'] ) .'" '; + $output .= 'height="' . esc_attr( $instance['img_height'] ) . '" '; } $output .= '/>'; @@ -104,8 +106,8 @@ class Jetpack_Image_Widget extends WP_Widget { if ( '' != $instance['caption'] ) { /** This filter is documented in core/src/wp-includes/default-widgets.php */ $caption = apply_filters( 'widget_text', $instance['caption'] ); - $img_width = ( ! empty( $instance['img_width'] ) ? 'style="width: ' . esc_attr( $instance['img_width'] ) .'px"' : '' ); - $output = '<figure ' . $img_width .' class="wp-caption align' . esc_attr( $instance['align'] ) . '"> + $img_width = ( ! empty( $instance['img_width'] ) ? 'style="width: ' . esc_attr( $instance['img_width'] ) . 'px"' : '' ); + $output = '<figure ' . $img_width . ' class="wp-caption align' . esc_attr( $instance['align'] ) . '"> ' . $output . ' <figcaption class="wp-caption-text">' . $caption . '</figcaption> </figure>'; // wp_kses_post caption on update @@ -135,16 +137,16 @@ class Jetpack_Image_Widget extends WP_Widget { */ public function update( $new_instance, $old_instance ) { $allowed_caption_html = array( - 'a' => array( - 'href' => array(), - 'title' => array(), - ), - 'b' => array(), - 'em' => array(), - 'i' => array(), - 'p' => array(), - 'strong' => array() - ); + 'a' => array( + 'href' => array(), + 'title' => array(), + ), + 'b' => array(), + 'em' => array(), + 'i' => array(), + 'p' => array(), + 'strong' => array(), + ); $instance = $old_instance; @@ -152,7 +154,7 @@ class Jetpack_Image_Widget extends WP_Widget { $instance['img_url'] = esc_url( trim( $new_instance['img_url'] ) ); $instance['alt_text'] = strip_tags( $new_instance['alt_text'] ); $instance['img_title'] = strip_tags( $new_instance['img_title'] ); - $instance['caption'] = wp_kses( stripslashes($new_instance['caption'] ), $allowed_caption_html ); + $instance['caption'] = wp_kses( stripslashes( $new_instance['caption'] ), $allowed_caption_html ); $instance['align'] = $new_instance['align']; $instance['link'] = esc_url( trim( $new_instance['link'] ) ); $instance['link_target_blank'] = isset( $new_instance['link_target_blank'] ) ? (bool) $new_instance['link_target_blank'] : false; @@ -166,10 +168,10 @@ class Jetpack_Image_Widget extends WP_Widget { if ( ! is_wp_error( $tmp_file ) ) { $size = getimagesize( $tmp_file ); - $width = $size[0]; + $width = $size[0]; $instance['img_width'] = absint( $width ); - $height = $size[1]; + $height = $size[1]; $instance['img_height'] = absint( $height ); unlink( $tmp_file ); @@ -194,7 +196,20 @@ class Jetpack_Image_Widget extends WP_Widget { */ public function form( $instance ) { // Defaults - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'img_url' => '', 'alt_text' => '', 'img_title' => '', 'caption' => '', 'align' => 'none', 'img_width' => '', 'img_height' => '', 'link' => '', 'link_target_blank' => false ) ); + $instance = wp_parse_args( + (array) $instance, array( + 'title' => '', + 'img_url' => '', + 'alt_text' => '', + 'img_title' => '', + 'caption' => '', + 'align' => 'none', + 'img_width' => '', + 'img_height' => '', + 'link' => '', + 'link_target_blank' => false, + ) + ); $title = esc_attr( $instance['title'] ); $img_url = esc_url( $instance['img_url'], null, 'display' ); @@ -217,7 +232,7 @@ class Jetpack_Image_Widget extends WP_Widget { <p><label for="' . $this->get_field_id( 'alt_text' ) . '">' . esc_html__( 'Alternate text:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-alt-text" target="_blank">( ? )</a> <input class="widefat" id="' . $this->get_field_id( 'alt_text' ) . '" name="' . $this->get_field_name( 'alt_text' ) . '" type="text" value="' . $alt_text . '" /> </label></p> - <p><label for="' . $this->get_field_id( 'img_title' ) . '">' . esc_html__( 'Image title:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-title" target="_blank">( ? )</a> + <p><label for="' . $this->get_field_id( 'img_title' ) . '">' . esc_html__( 'Image title:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-title" target="_blank">( ? )</a> <input class="widefat" id="' . $this->get_field_id( 'img_title' ) . '" name="' . $this->get_field_name( 'img_title' ) . '" type="text" value="' . $img_title . '" /> </label></p> <p><label for="' . $this->get_field_id( 'caption' ) . '">' . esc_html__( 'Caption:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-caption" target="_blank">( ? )</a> @@ -230,23 +245,24 @@ class Jetpack_Image_Widget extends WP_Widget { 'center' => __( 'Center', 'jetpack' ), 'right' => __( 'Right', 'jetpack' ), ); - echo '<p><label for="' . $this->get_field_id( 'align' ) . '">' . esc_html__( 'Image Alignment:', 'jetpack' ) . ' + echo '<p><label for="' . $this->get_field_id( 'align' ) . '">' . esc_html__( 'Image Alignment:', 'jetpack' ) . ' <select id="' . $this->get_field_id( 'align' ) . '" name="' . $this->get_field_name( 'align' ) . '">'; foreach ( $alignments as $alignment => $alignment_name ) { echo '<option value="' . esc_attr( $alignment ) . '" '; - if ( $alignment == $align ) + if ( $alignment == $align ) { echo 'selected="selected" '; - echo '>' . esc_html($alignment_name) . "</option>\n"; + } + echo '>' . esc_html( $alignment_name ) . "</option>\n"; } echo '</select></label></p>'; - echo '<p><label for="' . $this->get_field_id( 'img_width' ) . '">' . esc_html__( 'Width in pixels:', 'jetpack' ) . ' - <input size="3" id="' . $this->get_field_id( 'img_width' ) . '" name="' . $this->get_field_name( 'img_width' ) . '" type="text" value="' . $img_width . '" /> + echo '<p><label for="' . $this->get_field_id( 'img_width' ) . '">' . esc_html__( 'Width in pixels:', 'jetpack' ) . ' + <input size="3" id="' . $this->get_field_id( 'img_width' ) . '" name="' . $this->get_field_name( 'img_width' ) . '" type="text" value="' . $img_width . '" /> </label> <label for="' . $this->get_field_id( 'img_height' ) . '">' . esc_html__( 'Height in pixels:', 'jetpack' ) . ' <input size="3" id="' . $this->get_field_id( 'img_height' ) . '" name="' . $this->get_field_name( 'img_height' ) . '" type="text" value="' . $img_height . '" /> </label><br /> - <small>' . esc_html__( "If empty, we will attempt to determine the image size.", 'jetpack' ) . '</small></p> + <small>' . esc_html__( 'If empty, we will attempt to determine the image size.', 'jetpack' ) . '</small></p> <p><label for="' . $this->get_field_id( 'link' ) . '">' . esc_html__( 'Link URL (when the image is clicked):', 'jetpack' ) . ' <input class="widefat" id="' . $this->get_field_id( 'link' ) . '" name="' . $this->get_field_name( 'link' ) . '" type="text" value="' . $link . '" /> </label> |