Skip to content

Commit 3018fdc

Browse files
committed
Merge pull request #267 from ResponsiveImagesCG/dev
Version 3.1.1
2 parents 38b2e76 + 768cec8 commit 3018fdc

File tree

6 files changed

+412
-121
lines changed

6 files changed

+412
-121
lines changed

readme.md

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
##WordPress 4.4 and Native Responsive Images
2+
3+
As of WordPress 4.4, images are responsive by default. If you are on WordPress 4.4 or plan to update, you will not need to install this plugin.
4+
5+
If you have had this plugin installed since before version 2.5 but are running version 4.4 of WordPress, it is important that you leave the plugin installed. This is because all versions of the plugin before version 2.5 relied on a `data-sizes` attribute being present on an image in order to provide the responsive markup needed. If the plugin in this case is removed, then images in posts will be left with invalid markup. We are working to address this issue, and you can [keep track of our progress here](https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/issues/178).
6+
7+
You can still use the plugin for advanced image compression support or as a simple way to include the picturefill script. The plugin will fall back to WordPress default functions if responsive image support is detected in your installation.
8+
19
RICG-responsive-images
210
---
311

@@ -9,7 +17,7 @@ This plugin works by including all available image sizes for each image upload.
917

1018
## Contribution Guidelines
1119

12-
Please submit pull requests to our dev branch. If your contribution requires such, please aim to include appropriate tests with your pr as well.
20+
Please submit pull requests to our dev branch. If your contribution requires such, please aim to include appropriate tests with your PR as well.
1321

1422
## Documentation
1523

@@ -19,7 +27,7 @@ No configuration is needed! Just install the plugin and enjoy automatic responsi
1927

2028
### For Theme Developers
2129

22-
This plugin includes several functions that can be used by theme and plugin developers in templates.
30+
This plugin includes several functions that can be used by theme and plugin developers in templates, as well as hooks to filter their output.
2331

2432
### Advanced Image Compression
2533

@@ -153,6 +161,26 @@ Array of width and height values in pixels (in that order).
153161

154162
`wp_calculate_image_srcset()`
155163

164+
##### Usage Example
165+
166+
```
167+
<?php
168+
// Increase the limit to 2048px if the image is wider than 800px.
169+
170+
function custom_max_srcset_image_width( $max_width, $size_array ) {
171+
$width = $size_array[0];
172+
173+
if ( $width > 800 ) {
174+
$max_width = 2048;
175+
}
176+
177+
return $max_width;
178+
}
179+
add_filter( 'max_srcset_image_width', 'custom_max_srcset_image_width', 10, 2 );
180+
181+
?>
182+
```
183+
156184
---
157185

158186
#### Hook wp_calculate_image_srcset
@@ -179,6 +207,9 @@ $width (array) {
179207
**$size_array** (array)
180208
Array of width and height values in pixels (in that order).
181209

210+
**$image_src** (string)
211+
The `src` of the image.
212+
182213
**$image_meta** (array)
183214
The image meta data as returned by `wp_get_attachment_metadata()`.
184215

@@ -189,6 +220,33 @@ Image attachment ID or 0.
189220

190221
`wp_calculate_image_srcset()`
191222

223+
##### Usage Example
224+
225+
```
226+
<?php
227+
// Remove sources wider than 800px from the 'srcset' for featured images.
228+
229+
function custom_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
230+
if ( array_key_exists( 'post-thumbnail', $image_meta['sizes'] ) ) {
231+
$post_thumbnail_file = $image_meta['sizes']['post-thumbnail']['file'];
232+
$image_src_file = wp_basename( $image_src );
233+
234+
if ( $image_src_file === $post_thumbnail_file ) {
235+
foreach ( $sources as $key => $source ) {
236+
if ( $source['value'] > 800 ) {
237+
unset( $sources[ $key ] );
238+
}
239+
}
240+
}
241+
}
242+
243+
return $sources;
244+
}
245+
add_filter( 'wp_calculate_image_srcset', 'custom_wp_calculate_image_srcset', 10, 5 );
246+
247+
?>
248+
```
249+
192250
---
193251

194252
#### Function wp_get_attachment_image_sizes
@@ -313,6 +371,36 @@ Image attachment ID of the original image or 0.
313371

314372
`wp_calculate_image_sizes()`
315373

374+
##### Usage Example
375+
376+
```
377+
<?php
378+
// Constrain the width of full size images to the content width.
379+
380+
function custom_wp_calculate_image_sizes( $sizes, $size, $image_src, $image_meta, $attachment_id ) {
381+
if ( is_array( $size ) ) {
382+
global $content_width;
383+
$width = $size[0]
384+
385+
if ( $width > $content_width ) {
386+
$upload_dir = wp_upload_dir();
387+
$upload_baseurl = $upload_dir['baseurl'];
388+
$fullsize_file = $image_meta['file'];
389+
$fullsize_url = trailingslashit( $upload_baseurl ) . $fullsize_file;
390+
391+
if ( $image_src === $fullsize_url ) {
392+
$sizes = '(max-width: ' . $content_width . 'px) 100vw, ' . $content_width . 'px';
393+
}
394+
}
395+
}
396+
397+
return $sizes;
398+
}
399+
add_filter( 'wp_calculate_image_sizes', 'custom_wp_calculate_image_sizes', 10, 5 );
400+
401+
?>
402+
```
403+
316404
---
317405

318406
### Backward Compatibility
@@ -360,10 +448,20 @@ We use a hook because if you attempt to dequeue a script before it's enqueued, w
360448

361449
## Version
362450

363-
3.1.0
451+
3.1.1
364452

365453
## Changelog
366454

455+
**3.1.1**
456+
457+
- Fixes a bug where the srcset of images in imported content was missing or broken (issue #263).
458+
- Improved calculation of ratio difference for images to be included in the srcset. (issue #260).
459+
- Fixes a bug where `img` tags without ending slash don't get responsive images (issue #259).
460+
- Deprecates the helper function `tevkori_get_media_embedded_in_content()` which is no longer used.
461+
- Makes sure that the setup of default themes doesn't break the tests (issue #261).
462+
- Adds more examples to the Hook Reference in readme.md.
463+
- Corrections and improvements to inline documentation.
464+
367465
**3.1.0**
368466

369467
- Adds special handling of GIFs in srcset attributes to preserve animation (issue #223).

readme.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: tevko, wilto, joemcgill, jaspermdegroot, chriscoyier, Michael McGi
33
Donate link: https://app.etapestry.com/hosted/BoweryResidentsCommittee/OnlineDonation.html
44
Tags: Responsive, Images, Responsive Images, SRCSET, Picturefill
55
Requires at least: 4.0
6-
Tested up to: 4.3
7-
Stable tag: 3.1.0
6+
Tested up to: 4.4
7+
Stable tag: 3.1.1
88
License: GPLv2
99
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
1010

@@ -18,6 +18,13 @@ This plugin works by including all available image sizes for each image upload.
1818

1919
**Important notes**
2020

21+
* As of WordPress 4.4, images are responsive by default. If you are on WordPress 4.4 or plan to update, you will not need to install this plugin.
22+
23+
If you have had this plugin installed since before version 2.5 but are running version 4.4 of WordPress, it is important that you leave the plugin installed. This is because all versions of the plugin before version 2.5 relied on a `data-sizes` attribute being present on an image in order to provide the responsive markup needed. If the plugin in this case is removed, then images in posts will be left with invalid markup. We are working to address this issue, and you can keep track of our progress here at https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/issues/178.
24+
25+
You can still use the plugin for advanced image compression support or as a simple way to include the picturefill script. The plugin will fall back to WordPress default functions if responsive image support is detected in your installation.
26+
27+
2128
* Version 3.1.0 includes important changes that make this plugin compatible with WordPress version 4.4. Upgrading is highly recommended.
2229

2330
* As of version 2.5.0, the plugin adds `srcset` and `sizes` attributes to images on the front end instead of adding them to the image markup saved in posts.
@@ -32,6 +39,15 @@ This plugin works by including all available image sizes for each image upload.
3239

3340
== Changelog ==
3441

42+
= 3.1.1 =
43+
* Fixes a bug where the srcset of images in imported content was missing or broken.
44+
* Improved calculation of ratio difference for images to be included in the srcset.
45+
* Fixes a bug where `img` tags without ending slash don't get responsive images.
46+
* Deprecates the helper function `tevkori_get_media_embedded_in_content()` which is no longer used.
47+
* Makes sure that the setup of default themes doesn't break the tests.
48+
* Adds more examples to the Hook Reference in readme.md.
49+
* Corrections and improvements to inline documentation.
50+
3551
= 3.1.0 =
3652
* Adds special handling of GIFs in srcset attributes to preserve animation.
3753
* Makes internal srcset/sizes functions more consistent.

0 commit comments

Comments
 (0)