From dcb6262a52082a5ca4641423afe4a528e19c0cd1 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Wed, 4 Nov 2015 19:29:49 -0600 Subject: [PATCH] Add back compatability shim for data-sizes at all times. This comes after reverting 0163649 since we have to transform data-sizes attributes no matter which version of WP is installed. Since this filter uses a simple `str_replace()` instead of a preg_match, it's probably cleaner to add a separate filter than trying to piggyback on our `wp_make_content_images_responsive()` filter, and the performance should be similar either way. --- wp-tevko-responsive-images.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wp-tevko-responsive-images.php b/wp-tevko-responsive-images.php index eb4195b..993c56e 100644 --- a/wp-tevko-responsive-images.php +++ b/wp-tevko-responsive-images.php @@ -59,3 +59,20 @@ function tevkori_get_picturefill() { wp_enqueue_script( 'picturefill', plugins_url( 'js/picturefill.min.js', __FILE__ ), array(), '3.0.1', true ); } add_action( 'wp_enqueue_scripts', 'tevkori_get_picturefill' ); + +/** + * Back compatability shim for 'data-sizes' attributes in content. + * + * Prior to version 2.5 a 'srcset' and 'data-sizes' attribute were added to the image + * while inserting the image in the content. We replace the 'data-sizes' attribute by + * a 'sizes' attribute. + * + * @since 3.0.0 + * + * @param string $content The content to filter; + * @return string The filtered content with `data-sizes` repaced by `sizes` attributes. + */ +function tevkori_replace_data_sizes( $content ) { + return str_replace( ' data-sizes="', ' sizes="', $content ); +} +add_filter( 'the_content', 'tevkori_replace_data_sizes' );