Skip to content

Commit ea5e1e6

Browse files
committed
Merge pull request #122 from ResponsiveImagesCG/dev
Version 2.3.1
2 parents 724c8d3 + 664d6e2 commit ea5e1e6

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,17 @@ We use a hook because if you attempt to dequeue a script before it's enqueued, w
135135

136136
##Version
137137

138-
2.3.0
138+
2.3.1
139139

140140
##Changelog
141141

142+
- First char no longer stripped from file name if there's no slash
143+
- Adding test for when uploads directory not organized by date
144+
- Don't calculate a srcset when the image data returns no width
145+
- Add test for image_downsize returning 0 as a width
146+
147+
**2.3.0**
148+
142149
- Improved performance of `get_srcset_array`
143150
- Added advanced image compression option (available by adding hook to functions.php)
144151
- Duplicate entires now filtered out from srcset array

tests/test-suite.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ function test_tevkori_get_srcset_array() {
147147
$this->assertSame( $expected, $sizes );
148148
}
149149

150+
function test_tevkori_get_srcset_array_no_date_upoads() {
151+
// Save the current setting for uploads folders
152+
$uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
153+
154+
// Disable date organized uploads
155+
update_option( 'uploads_use_yearmonth_folders', 0 );
156+
157+
// make an image
158+
$id = $this->_test_img();
159+
$sizes = tevkori_get_srcset_array( $id, 'medium' );
160+
161+
$image = wp_get_attachment_metadata( $id );
162+
$filename_base = substr( $image['file'], 0, strrpos($image['file'], '.png') );
163+
164+
$expected = array(
165+
'http://example.org/wp-content/uploads/' . $image['sizes']['medium']['file'] . ' ' . $image['sizes']['medium']['width'] . 'w',
166+
'http://example.org/wp-content/uploads/' . $image['sizes']['large']['file'] . ' ' . $image['sizes']['large']['width'] . 'w',
167+
'http://example.org/wp-content/uploads/' . $image['file'] . ' ' . $image['width'] .'w'
168+
);
169+
170+
$this->assertSame( $expected, $sizes );
171+
172+
// Leave the uploads option the way you found it.
173+
update_option( 'uploads_use_yearmonth_folders', $uploads_use_yearmonth_folders );
174+
}
175+
150176
function test_tevkori_get_srcset_array_thumb() {
151177
// make an image
152178
$id = $this->_test_img();
@@ -171,6 +197,28 @@ function test_tevkori_get_srcset_array_false() { // make an image
171197
$this->assertFalse( $sizes );
172198
}
173199

200+
function test_tevkori_get_srcset_array_no_width() {
201+
// Filter image_downsize() output.
202+
add_filter( 'image_downsize', array( $this, '_test_tevkori_get_srcset_array_no_width_filter' ) );
203+
204+
// Make our attachement.
205+
$id = $this->_test_img();
206+
$srcset = tevkori_get_srcset_array( $id, 'medium' );
207+
208+
// The srcset should be false
209+
$this->assertFalse( $srcset );
210+
211+
// Remove filter.
212+
remove_filter( 'image_downsize', array( $this, '_test_tevkori_get_srcset_array_no_width_filter' ) );
213+
}
214+
215+
/**
216+
* Helper funtion to filter image_downsize and return zero values for width and height.
217+
*/
218+
public function _test_tevkori_get_srcset_array_no_width_filter() {
219+
return array( 'http://example.org/foo.jpg', 0, 0, false );
220+
}
221+
174222
function test_tevkori_get_srcset_string() {
175223
// make an image
176224
$id = $this->_test_img();

wp-tevko-responsive-images.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Plugin Name: RICG Responsive Images
1111
* Plugin URI: http://www.smashingmagazine.com/2015/02/24/ricg-responsive-images-for-wordpress/
1212
* Description: Bringing automatic default responsive images to wordpress
13-
* Version: 2.3.0
13+
* Version: 2.3.1
1414
* Author: The RICG
1515
* Author URI: http://responsiveimages.org/
1616
* License: GPL-2.0+
@@ -153,6 +153,11 @@ function tevkori_get_srcset_array( $id, $size = 'thumbnail' ) {
153153
// Break image data into url, width, and height.
154154
list( $img_url, $img_width, $img_height ) = $img;
155155

156+
// If we have no width to work with, we should bail (see issue #118).
157+
if ( 0 == $img_width ) {
158+
return false;
159+
}
160+
156161
// Get the image meta data.
157162
$img_meta = wp_get_attachment_metadata( $id );
158163

@@ -163,8 +168,11 @@ function tevkori_get_srcset_array( $id, $size = 'thumbnail' ) {
163168
$img_sizes['full'] = array(
164169
'width' => $img_meta['width'],
165170
'height' => $img_meta['height'],
166-
'file' => substr( $img_meta['file'], strrpos( $img_meta['file'], '/' ) + 1 )
171+
'file' => $img_meta['file']
167172
);
173+
if ( strrpos( $img_meta['file'], '/' ) !== false ) {
174+
$img_sizes['full']['file'] = substr( $img_meta['file'], strrpos( $img_meta['file'], '/' ) + 1 );
175+
}
168176

169177
// Get the image base url.
170178
$img_base_url = substr( $img_url, 0, strrpos( $img_url, '/' ) + 1 );

0 commit comments

Comments
 (0)