From 60c262716c6ee996b64c2a795df8064ef10fb546 Mon Sep 17 00:00:00 2001 From: side777 Date: Mon, 18 May 2015 12:49:49 +0200 Subject: [PATCH 1/6] Update wp-tevko-responsive-images.php fixed: first char gets stripped from file name if there's no slash --- wp-tevko-responsive-images.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wp-tevko-responsive-images.php b/wp-tevko-responsive-images.php index 96e1f88..452256c 100644 --- a/wp-tevko-responsive-images.php +++ b/wp-tevko-responsive-images.php @@ -163,8 +163,11 @@ function tevkori_get_srcset_array( $id, $size = 'thumbnail' ) { $img_sizes['full'] = array( 'width' => $img_meta['width'], 'height' => $img_meta['height'], - 'file' => substr( $img_meta['file'], strrpos( $img_meta['file'], '/' ) + 1 ) + 'file' => $img_meta['file'] ); + if ( strrpos( $img_meta['file'], '/' ) !== false ) { + $img_sizes['full']['file'] = substr( $img_meta['file'], strrpos( $img_meta['file'], '/' ) + 1 ); + } // Get the image base url. $img_base_url = substr( $img_url, 0, strrpos( $img_url, '/' ) + 1 ); From e5db35135cbe0178bee9b66b5b740a78476f82cd Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Mon, 18 May 2015 22:12:38 -0500 Subject: [PATCH 2/6] add test for when uploads dir not organized by date --- tests/test-suite.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test-suite.php b/tests/test-suite.php index 95546dd..c88ef96 100644 --- a/tests/test-suite.php +++ b/tests/test-suite.php @@ -147,6 +147,32 @@ function test_tevkori_get_srcset_array() { $this->assertSame( $expected, $sizes ); } + function test_tevkori_get_srcset_array_no_date_upoads() { + // Save the current setting for uploads folders + $uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' ); + + // Disable date organized uploads + update_option( 'uploads_use_yearmonth_folders', 0 ); + + // make an image + $id = $this->_test_img(); + $sizes = tevkori_get_srcset_array( $id, 'medium' ); + + $image = wp_get_attachment_metadata( $id ); + $filename_base = substr( $image['file'], 0, strrpos($image['file'], '.png') ); + + $expected = array( + 'http://example.org/wp-content/uploads/' . $image['sizes']['medium']['file'] . ' ' . $image['sizes']['medium']['width'] . 'w', + 'http://example.org/wp-content/uploads/' . $image['sizes']['large']['file'] . ' ' . $image['sizes']['large']['width'] . 'w', + 'http://example.org/wp-content/uploads/' . $image['file'] . ' ' . $image['width'] .'w' + ); + + $this->assertSame( $expected, $sizes ); + + // Leave the uploads option the way you found it. + update_option( 'uploads_use_yearmonth_folders', $uploads_use_yearmonth_folders ); + } + function test_tevkori_get_srcset_array_thumb() { // make an image $id = $this->_test_img(); From 285627e80bd70129a86bca9d767ddfdb7b9a70b8 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Wed, 20 May 2015 12:36:05 -0500 Subject: [PATCH 3/6] Don't calculate a srcset when the image data returns no width. --- wp-tevko-responsive-images.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wp-tevko-responsive-images.php b/wp-tevko-responsive-images.php index 96e1f88..f4b9fa1 100644 --- a/wp-tevko-responsive-images.php +++ b/wp-tevko-responsive-images.php @@ -153,6 +153,11 @@ function tevkori_get_srcset_array( $id, $size = 'thumbnail' ) { // Break image data into url, width, and height. list( $img_url, $img_width, $img_height ) = $img; + // If we have no width to work with, we should bail (see issue #118). + if ( 0 == $img_width ) { + return false; + } + // Get the image meta data. $img_meta = wp_get_attachment_metadata( $id ); From 8185ca165aed2a21bb6a073e1c1ce143be37c7bc Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Thu, 21 May 2015 07:13:49 -0500 Subject: [PATCH 4/6] Add test for image_downsize returning 0 as a width. --- tests/test-suite.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test-suite.php b/tests/test-suite.php index 95546dd..70bb6e7 100644 --- a/tests/test-suite.php +++ b/tests/test-suite.php @@ -171,6 +171,28 @@ function test_tevkori_get_srcset_array_false() { // make an image $this->assertFalse( $sizes ); } + function test_tevkori_get_srcset_array_no_width() { + // Filter image_downsize() output. + add_filter( 'image_downsize', array( $this, '_test_tevkori_get_srcset_array_no_width_filter' ) ); + + // Make our attachement. + $id = $this->_test_img(); + $srcset = tevkori_get_srcset_array( $id, 'medium' ); + + // The srcset should be false + $this->assertFalse( $srcset ); + + // Remove filter. + remove_filter( 'image_downsize', array( $this, '_test_tevkori_get_srcset_array_no_width_filter' ) ); + } + + /** + * Helper funtion to filter image_downsize and return zero values for width and height. + */ + public function _test_tevkori_get_srcset_array_no_width_filter() { + return array( 'http://example.org/foo.jpg', 0, 0, false ); + } + function test_tevkori_get_srcset_string() { // make an image $id = $this->_test_img(); From 56f097eddf0ff1b63e7eb593c9648f29d6830baf Mon Sep 17 00:00:00 2001 From: Tim Evko Date: Tue, 26 May 2015 20:41:55 -0400 Subject: [PATCH 5/6] update version to 2.3.1 --- wp-tevko-responsive-images.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-tevko-responsive-images.php b/wp-tevko-responsive-images.php index d2e1f38..550b838 100644 --- a/wp-tevko-responsive-images.php +++ b/wp-tevko-responsive-images.php @@ -10,7 +10,7 @@ * Plugin Name: RICG Responsive Images * Plugin URI: http://www.smashingmagazine.com/2015/02/24/ricg-responsive-images-for-wordpress/ * Description: Bringing automatic default responsive images to wordpress - * Version: 2.3.0 + * Version: 2.3.1 * Author: The RICG * Author URI: http://responsiveimages.org/ * License: GPL-2.0+ From 664d6e207f85722978d1976bb09cc51f817ff4bd Mon Sep 17 00:00:00 2001 From: Tim Evko Date: Tue, 26 May 2015 20:45:23 -0400 Subject: [PATCH 6/6] Version 2.3.1 changelog --- readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0b8c5cc..a7072ad 100644 --- a/readme.md +++ b/readme.md @@ -131,10 +131,17 @@ We use a hook because if you attempt to dequeue a script before it's enqueued, w ##Version -2.3.0 +2.3.1 ##Changelog +- First char no longer stripped from file name if there's no slash +- Adding test for when uploads directory not organized by date +- Don't calculate a srcset when the image data returns no width +- Add test for image_downsize returning 0 as a width + +**2.3.0** + - Improved performance of `get_srcset_array` - Added advanced image compression option (available by adding hook to functions.php) - Duplicate entires now filtered out from srcset array