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

Commit 5808726

Browse files
authored
Merge pull request #11 from WordPress/remove/iframe-support
Remove support for iframes
2 parents 9ed2bb6 + dcc6a32 commit 5808726

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

tests/phpunit/tests/media.php

Lines changed: 6 additions & 11 deletions
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' );

wp-lazy-loading.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,48 +119,31 @@ function wp_lazy_loading_enabled( $tag_name, $context ) {
119119
return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
120120
}
121121

122-
123-
// TODO: update docs.
124122
/**
125-
* Add `loading="lazy"` to `img` and/or `iframe` HTML tags.
123+
* Add `loading="lazy"` to `img` HTML tags.
126124
*
127125
* Currently the "loading" attribute is only supported for `img`, and is enabled by default.
128-
* Support for `iframe` is for testing purposes only.
129126
*
130127
* @since (TBD)
131128
*
132-
* @param string $content The raw post content to be filtered.
129+
* @param string $content The HTML content to be filtered.
133130
* @param string $context Optional. Additional context to pass to the filters. Defaults to `current_filter()` when not set.
134131
* @return string Converted content with 'loading' attributes added to images.
135132
*/
136133
function wp_add_lazy_load_attributes( $content, $context = null ) {
137-
$tags = array();
138-
139134
if ( null === $context ) {
140135
$context = current_filter();
141136
}
142137

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 ) ) {
138+
if ( ! wp_lazy_loading_enabled( 'img', $context ) ) {
153139
return $content;
154140
}
155141

156142
return preg_replace_callback(
157-
'/<(' . implode( '|', $tags ) . ')(\s)[^>]+>/',
143+
'/<img\s[^>]+>/',
158144
function( array $matches ) {
159145
if ( ! preg_match( '/\sloading\s*=/', $matches[0] ) ) {
160-
$tag = $matches[1];
161-
$space = $matches[2];
162-
163-
return str_replace( '<' . $tag . $space, '<' . $tag . $space . 'loading="lazy" ', $matches[0] );
146+
return str_replace( '<img', '<img loading="lazy"', $matches[0] );
164147
}
165148

166149
return $matches[0];

0 commit comments

Comments
 (0)