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

Remove support for iframes #11

Merged
merged 2 commits into from
Jan 24, 2020
Merged

Remove support for iframes #11

merged 2 commits into from
Jan 24, 2020

Conversation

felixarntz
Copy link
Member

This PR removes support for iframe tags, since they are not part of the currently proposed spec for the loading attribute (see #3 and #5).

@felixarntz felixarntz requested a review from azaozz January 23, 2020 10:15
return $content;
}

return preg_replace_callback(
'/<(' . implode( '|', $tags ) . ')(\s)[^>]+>/',
'/<img(\s)[^>]+>/',
Copy link
Contributor

@azaozz azaozz Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need to capture the space here. Doesn't make sense to reinsert it. We only need to check for its existence.

This is a tiny optimization, but optimization nevertheless :)

In nearly all cases capturing and reinserting the space char will make no difference at all. If the tag is formatted with line breaks between the attributes (cannot happen in post_content, comments, widget text, and pretty much all content entered by the users as it breaks wpautop), capturing and reinserting the space will "push" the attribute to the second line, but still "break" the formatting as there will be two attributes there.

In any case, "white space" is ignored in HTML, and adding another attribute will "shuffle" the existing attributes a bit. Don't see a good reason to make the regex a tiny bit slower in order to "shuffle" the attributes in one way and not the other :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should be '/<img\s[^>]+>/'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine with me

Comment on lines 139 to 143
if ( null === $context ) {
$context = current_filter();
}

if ( wp_lazy_loading_enabled( 'img', $context ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking we should keep this. wp_lazy_loading_enabled() requires context in order to be "most useful". Passing current_filter() is quite helpful. For example it would allows adding of the attribute in post_content, but not adding it in comments, etc. This also would let plugins customize it further if/when they call wp_add_lazy_load_attributes() directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, removing the $context = current_filter() if no context is provided was unintentional - so I agree :)

return $content;
}

return preg_replace_callback(
'/<(' . implode( '|', $tags ) . ')(\s)[^>]+>/',
'/<img(\s)[^>]+>/',
function( array $matches ) {
if ( ! preg_match( '/\sloading\s*=/', $matches[0] ) ) {
Copy link
Contributor

@azaozz azaozz Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex here should look for \b not \s at the beginning. Same considerations as above, if the img tag was formatted with each attribute starting on a new line, there's a chance that loading won't have a white-space char before it.

Actually, nevermind :) Both \b and \s should work, "word boundary" perhaps being a bit more intuitive.

Add the suggested changes so this branch can be used as base for #10.
@felixarntz felixarntz merged commit 5808726 into master Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants