diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 85e9760..90b7003 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -46,7 +46,7 @@ function test_wp_lazy_load_content_media() {
Image, with pre-existing "loading" attribute.
%5$s -Iframe, standard. Should not be modified by default.
+Iframe, standard. Should not be modified.
%4$s'; $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $iframe, $img_eager ); @@ -59,21 +59,16 @@ function test_wp_lazy_load_content_media() { * @ticket 44427 */ function test_wp_lazy_load_content_media_opted_in() { - $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); - $iframe = ''; + $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); - $lazy_img = str_replace( 'Iframe, standard.
- %2$s'; + %1$s'; - $content_unfiltered = sprintf( $content, $img, $iframe ); - $content_filtered = sprintf( $content, $lazy_img, $lazy_iframe ); + $content_unfiltered = sprintf( $content, $img ); + $content_filtered = sprintf( $content, $lazy_img ); // Enable globally for all tags. add_filter( 'wp_lazy_loading_enabled', '__return_true' ); diff --git a/wp-lazy-loading.php b/wp-lazy-loading.php index 57ab518..6bfbca2 100644 --- a/wp-lazy-loading.php +++ b/wp-lazy-loading.php @@ -119,48 +119,31 @@ function wp_lazy_loading_enabled( $tag_name, $context ) { return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context ); } - -// TODO: update docs. /** - * Add `loading="lazy"` to `img` and/or `iframe` HTML tags. + * Add `loading="lazy"` to `img` HTML tags. * * Currently the "loading" attribute is only supported for `img`, and is enabled by default. - * Support for `iframe` is for testing purposes only. * * @since (TBD) * - * @param string $content The raw post content to be filtered. + * @param string $content The HTML content to be filtered. * @param string $context Optional. Additional context to pass to the filters. Defaults to `current_filter()` when not set. * @return string Converted content with 'loading' attributes added to images. */ function wp_add_lazy_load_attributes( $content, $context = null ) { - $tags = array(); - if ( null === $context ) { $context = current_filter(); } - if ( wp_lazy_loading_enabled( 'img', $context ) ) { - $tags[] = 'img'; - } - - // Experimental. Will be removed when merging unless the HTML specs are updated by that time. - if ( wp_lazy_loading_enabled( 'iframe', $context ) ) { - $tags[] = 'iframe'; - } - - if ( empty( $tags ) ) { + if ( ! wp_lazy_loading_enabled( 'img', $context ) ) { return $content; } return preg_replace_callback( - '/<(' . implode( '|', $tags ) . ')(\s)[^>]+>/', + '/