Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions classes/Webp/Picture/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function build_picture_tag( $image ) {
*/
$attributes = apply_filters( 'imagify_picture_attributes', $attributes, $image );

$output = '<picture' . $this->build_attributes( $attributes ) . ">\n";
$output = '<picture' . $this->build_attributes( $attributes, 'picture' ) . ">\n";
/**
* Allow to add more <source> tags to the <picture> tag.
*
Expand Down Expand Up @@ -273,7 +273,7 @@ protected function build_source_tag( $image ) {
*/
$attributes = apply_filters( 'imagify_picture_source_attributes', $attributes, $image );

return '<source' . $this->build_attributes( $attributes ) . "/>\n";
return '<source' . $this->build_attributes( $attributes, 'source' ) . "/>\n";
}

/**
Expand Down Expand Up @@ -310,7 +310,7 @@ protected function build_img_tag( $image ) {
*/
$attributes = apply_filters( 'imagify_picture_img_attributes', $attributes, $image );

return '<img' . $this->build_attributes( $attributes ) . "/>\n";
return '<img' . $this->build_attributes( $attributes, 'img' ) . "/>\n";
}

/**
Expand All @@ -323,15 +323,27 @@ protected function build_img_tag( $image ) {
* @param array $attributes A list of attribute pairs.
* @return string HTML attributes.
*/
protected function build_attributes( $attributes ) {
protected function build_attributes( $attributes, $type = false ) {
if ( ! $attributes || ! is_array( $attributes ) ) {
return '';
}

$out = '';
$css = array();

foreach ( $attributes as $attribute => $value ) {
$out .= ' ' . $attribute . '="' . esc_attr( $value ) . '"';

if( $attribute === "width" || $attribute === "height" ) { $css[] = $attribute . ':' . $value .'px'; }

}

if( $type && $type === "picture" && !empty($css) ) {

$css = implode(';', $css);

$out .= ' style="' . $css . ';"';

}

return $out;
Expand Down