| @@ -129,11 +129,11 @@ | ||
| 129 | 129 | |
| 130 | 130 | if ( is_string( $args['size'] ) ) { |
| 131 | 131 | list( $args['thumb_width'], $args['thumb_height'] ) = self::get_thumb_size( $args['size'] ); |
| 132 | 132 | } else { |
| 133 | - $args['thumb_width'] = $args['size'][0]; | |
| 134 | - $args['thumb_height'] = $args['size'][1]; | |
| 135 | - $args['size'] = self::get_appropriate_image_size( $args['size'][0], $args['size'][1] ); | |
| 133 | + $args['thumb_width'] = absint( $args['size'][0] ); | |
| 134 | + $args['thumb_height'] = absint( $args['size'][1] ); | |
| 135 | + $args['size'] = self::get_appropriate_image_size( $args['thumb_width'], $args['thumb_height'] ); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $post_title = esc_attr( $result->post_title ); |
| 139 | 139 | |
| @@ -784,16 +784,11 @@ | ||
| 784 | 784 | |
| 785 | 785 | /** |
| 786 | 786 | * Get an HTML img element. |
| 787 | 787 | * |
| 788 | - * When an attachment ID is available the function delegates to | |
| 789 | - * {@see wp_get_attachment_image()} so that srcset, sizes and all | |
| 790 | - * core image optimisations are applied automatically. | |
| 788 | + * Delegates to {@see wp_get_attachment_image()} when an attachment ID is available; | |
| 789 | + * otherwise builds the tag manually. | |
| 791 | 790 | * |
| 792 | - * When only a URL is available (external images, meta-key URLs, etc.) | |
| 793 | - * the function builds the `<img>` tag manually using the configured | |
| 794 | - * thumbnail dimensions and attributes. | |
| 795 | - * | |
| 796 | 791 | * @param string $attachment_url Image URL. |
| 797 | 792 | * @param array $attr Optional. Attributes for the image markup. |
| 798 | 793 | * @param int $attachment_id Optional. Attachment ID. Default 0. |
| 799 | 794 | * @param string|int[] $size Optional. Registered image size name or |
| @@ -855,9 +850,9 @@ | ||
| 855 | 850 | $attr = apply_filters( self::$prefix . '_get_image_attributes', $attr, $attachment_url ); |
| 856 | 851 | $attr = array_map( 'esc_attr', $attr ); |
| 857 | 852 | |
| 858 | 853 | // Construct the HTML img tag. |
| 859 | - $html = '<img ' . rtrim( $hwstring ); | |
| 854 | + $html = '<img ' . rtrim( $hwstring, " \t\n\r\0\x0B" ); | |
| 860 | 855 | foreach ( $attr as $name => $value ) { |
| 861 | 856 | if ( '' !== $value ) { |
| 862 | 857 | $html .= " $name=" . '"' . $value . '"'; |
| 863 | 858 | } |
| @@ -970,12 +965,24 @@ | ||
| 970 | 965 | ); |
| 971 | 966 | |
| 972 | 967 | $args = wp_parse_args( $args, $default_args ); |
| 973 | 968 | |
| 969 | + $thumb_width = absint( $args['thumb_width'] ); | |
| 970 | + $thumb_height = absint( $args['thumb_height'] ); | |
| 971 | + | |
| 974 | 972 | if ( 'css' === $args['thumb_html'] ) { |
| 975 | - $thumb_html = ' style="max-width:' . $args['thumb_width'] . 'px;max-height:' . $args['thumb_height'] . 'px;" '; | |
| 973 | + $styles = array(); | |
| 974 | + if ( $thumb_width ) { | |
| 975 | + $styles[] = 'max-width:' . $thumb_width . 'px'; | |
| 976 | + } | |
| 977 | + if ( $thumb_height ) { | |
| 978 | + $styles[] = 'max-height:' . $thumb_height . 'px'; | |
| 979 | + } | |
| 980 | + $thumb_html = $styles ? ' style="' . implode( ';', $styles ) . ';" ' : ''; | |
| 976 | 981 | } elseif ( 'html' === $args['thumb_html'] ) { |
| 977 | - $thumb_html = ' width="' . $args['thumb_width'] . '" height="' . $args['thumb_height'] . '" '; | |
| 982 | + $thumb_html = $thumb_width ? ' width="' . $thumb_width . '"' : ''; | |
| 983 | + $thumb_html .= $thumb_height ? ' height="' . $thumb_height . '"' : ''; | |
| 984 | + $thumb_html = $thumb_html ? $thumb_html . ' ' : ''; | |
| 978 | 985 | } else { |
| 979 | 986 | $thumb_html = ''; |
| 980 | 987 | } |
| 981 | 988 | |