Skip to content
This repository was archived by the owner on Dec 23, 2020. It is now read-only.

Commit bf0f36b

Browse files
committed
Remove support for iframes.
1 parent 0767b6c commit bf0f36b

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

Diff for: tests/phpunit/tests/media.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function test_wp_lazy_load_content_media() {
4646
<p>Image, with pre-existing "loading" attribute.</p>
4747
%5$s
4848
49-
<p>Iframe, standard. Should not be modified by default.</p>
49+
<p>Iframe, standard. Should not be modified.</p>
5050
%4$s';
5151

5252
$content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $iframe, $img_eager );
@@ -59,21 +59,16 @@ function test_wp_lazy_load_content_media() {
5959
* @ticket 44427
6060
*/
6161
function test_wp_lazy_load_content_media_opted_in() {
62-
$img = get_image_tag( self::$large_id, '', '', '', 'medium' );
63-
$iframe = '<iframe src="https://www.example.com"></iframe>';
62+
$img = get_image_tag( self::$large_id, '', '', '', 'medium' );
6463

65-
$lazy_img = str_replace( '<img ', '<img loading="lazy" ', $img );
66-
$lazy_iframe = str_replace( '<iframe ', '<iframe loading="lazy" ', $iframe );
64+
$lazy_img = str_replace( '<img ', '<img loading="lazy" ', $img );
6765

6866
$content = '
6967
<p>Image, standard.</p>
70-
%1$s
71-
72-
<p>Iframe, standard.</p>
73-
%2$s';
68+
%1$s';
7469

75-
$content_unfiltered = sprintf( $content, $img, $iframe );
76-
$content_filtered = sprintf( $content, $lazy_img, $lazy_iframe );
70+
$content_unfiltered = sprintf( $content, $img );
71+
$content_filtered = sprintf( $content, $lazy_img );
7772

7873
// Enable globally for all tags.
7974
add_filter( 'wp_lazy_loading_enabled', '__return_true' );

Diff for: wp-lazy-loading.php

+5-22
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ function wp_lazy_loading_enabled( $tag_name, $context ) {
122122

123123
// TODO: update docs.
124124
/**
125-
* Add `loading="lazy"` to `img` and/or `iframe` HTML tags.
125+
* Add `loading="lazy"` to `img` HTML tags if enabled.
126126
*
127127
* Currently the "loading" attribute is only supported for `img`, and is enabled by default.
128-
* Support for `iframe` is for testing purposes only.
129128
*
130129
* @since (TBD)
131130
*
@@ -134,33 +133,17 @@ function wp_lazy_loading_enabled( $tag_name, $context ) {
134133
* @return string Converted content with 'loading' attributes added to images.
135134
*/
136135
function wp_add_lazy_load_attributes( $content, $context = null ) {
137-
$tags = array();
138-
139-
if ( null === $context ) {
140-
$context = current_filter();
141-
}
142-
143-
if ( wp_lazy_loading_enabled( 'img', $context ) ) {
144-
$tags[] = 'img';
145-
}
146-
147-
// Experimental. Will be removed when merging unless the HTML specs are updated by that time.
148-
if ( wp_lazy_loading_enabled( 'iframe', $context ) ) {
149-
$tags[] = 'iframe';
150-
}
151-
152-
if ( empty( $tags ) ) {
136+
if ( ! wp_lazy_loading_enabled( 'img', $context ) ) {
153137
return $content;
154138
}
155139

156140
return preg_replace_callback(
157-
'/<(' . implode( '|', $tags ) . ')(\s)[^>]+>/',
141+
'/<img(\s)[^>]+>/',
158142
function( array $matches ) {
159143
if ( ! preg_match( '/\sloading\s*=/', $matches[0] ) ) {
160-
$tag = $matches[1];
161-
$space = $matches[2];
144+
$space = $matches[1];
162145

163-
return str_replace( '<' . $tag . $space, '<' . $tag . $space . 'loading="lazy" ', $matches[0] );
146+
return str_replace( '<img' . $space, '<img' . $space . 'loading="lazy" ', $matches[0] );
164147
}
165148

166149
return $matches[0];

0 commit comments

Comments
 (0)