Responsify WP 1.8
Goodbye Picture::create()
! That was the biggest news in the newly released Responsify WP 1.8.
When it comes to plugins that brings responsive images to your WordPress site, RWP has become the underdog. The Responsive Images Community Group, RICG, has an offical plugin which has gotten a lot of attention durning the last months. Especially when people like Chris Coyer and other big profiles in the industry started talking about it.
RWP and the RICG plugin was equally large before it got all this attention. At the time of this writing, RWP has 500 active installs and RICG has 3000. But hey, everybody likes an underdog, right?
So what about RWP 1.8? With this release, I finally deprecated the Picture::create()
method. I’ve introduced five new functions instead:
rwp_img()
rwp_picture()
rwp_span()
rwp_style()
rwp_attributes()
So what was wrong with Picture::create()
? Well, it just was a strange name. It worked in the beginning when the only thing RWP could do was to generate a picture
element.
Picture::create( 'element' );
Then came support for img
and srcset/sizes
and things started to feel strange.
Picture::create( 'img' );
The new functins feels much better and is much more logical.
rwp_img()
rwp_picture()
I don’t like the rwp_
prefix though, but it’s a good practice to prefix plugin functions like that.
Backwards compatibility?
Don’t worry, Picture::create()
will still work. In fact, it’s still used under the hood.
<?php
function rwp_img( $attachment_id, $settings = null ) {
return Picture::create( 'img', $attachment_id, $settings );
}
?>
Edit attributes
Besides of lots of bugfixes in the retina feature, a new filter has been added. rwp_edit_attributes
allows the user to, well, edit the attributes. This filter is applied just before the attributes is added to the generated element.
One use case is to edit the sizes attribute based on the size that the original image had.
<?php
function edit_attributes( $attributes ) {
if ( is_integer( strpos( $attributes['class'], 'size-large') ) ) {
$attributes['sizes'] = '(min-width: 500px) 1024px, (min-width: 300px) 300px, 150px';
}
return $attributes;
}
add_filter( 'rwp_edit_attributes', 'edit_attributes' );
?>
That’s it for this time! Now I’m very exited to start working on RWP 1.9 and a new killer feature…
Until then, thanks for caring about responsive images!