Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove registration of Facebook embed handler #4384

Merged
merged 7 commits into from
Mar 17, 2020

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Mar 14, 2020

Summary

This PR removes the custom WordPress embed handler for Facebook and instead relies on \AMP_Facebook_Embed_Handler::sanitize_raw_embeds to convert such embeds to their appropriate AMP components.

Fixes #4358.

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Mar 14, 2020
$parent_node->removeChild( $script );

// Remove parent node if it is an empty <p> tag.
if ( 'p' === $parent_node->tagName && null === $parent_node->firstChild ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The script tag is wrapped with a p tag (from wpautop()), so I've removed the lingering empty tag if it's there.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Is this unique just to Facebook or is it an issue shared across other embeds as well?

$parent_node->removeChild( $script );

// Remove parent node if it is an empty <p> tag.
if ( 'p' === $parent_node->tagName && null === $parent_node->firstChild ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( 'p' === $parent_node->tagName && null === $parent_node->firstChild ) {
if ( 'p' === $parent_node->nodeName && null === $parent_node->firstChild ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its also an issue for TikTok, Twitter and Instagram.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After looking at some of the other embeds, they are for the most part also wrapped with a <p> tag. That isn't an issue per se, but if this PR is merged we should probably standardize the other embeds to not be wrapped with a paragraph element.

@westonruter
Copy link
Member

westonruter commented Mar 16, 2020

Humm, there are phpunit test errors.

Comment on lines +92 to +95
// Remove parent node if it is an empty <p> tag.
if ( 'p' === $parent_node->nodeName && null === $parent_node->firstChild ) {
$parent_node->parentNode->removeChild( $parent_node );
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in c6869a9.

// Remove parent node if it is an empty <p> tag.
if ( 'p' === $parent_node->nodeName && null === $parent_node->firstChild ) {
$parent_node->parentNode->removeChild( $parent_node );
}
}
$fb_root->parentNode->removeChild( $fb_root );
Copy link
Member

Choose a reason for hiding this comment

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

It turns out that when you have multiple Facebook embeds on a page, each instance will include a div#fb-root. So I suppose this should be changed to:

Suggested change
$fb_root->parentNode->removeChild( $fb_root );
while ( $fb_root ) {
$fb_root->parentNode->removeChild( $fb_root );
$fb_root = $dom->getElementById( 'fb-root' );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory this should work, but when it retrieves the #fb_root div again it's returning the same div as before. I'll adapt this to use an XPath query instead.

Copy link
Member

Choose a reason for hiding this comment

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

Why would it return the same div as before if it was removed from the document?

@pierlon pierlon requested a review from westonruter March 16, 2020 23:35
@westonruter westonruter added this to the v1.5 milestone Mar 17, 2020
@westonruter westonruter merged commit ff8e61c into develop Mar 17, 2020
@westonruter westonruter deleted the fix/4358-wrapped-facebook-component branch March 17, 2020 19:18
@westonruter
Copy link
Member

Note: It appears Facebook tests don't have mocks for the non-external-http test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-facebook is wrapped in a <p> tag when it should be in post root like amp-twitter
3 participants