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

Update embeds handlers to unwrap embeds from <p> tag #7564

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

thelovekesh
Copy link
Collaborator

Summary

Fixes #4450

Checklist

  • 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).

@@ -360,7 +360,7 @@ jobs:
WP_CORE_DIR: /tmp/wordpress
services:
mysql:
image: mariadb:latest
image: mariadb:10
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note

The most recent MariaDB images appear to have a problem that prevents DB services from starting up. Once this is rectified in a future release, this change may be undone. In the meantime, mearidb:10 will work for us going forward.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thelovekesh Here's a more future-proof workaround: swissspidy/preferred-languages@ce3f0d5

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @swissspidy. This will be updated as a part of #7560.

@thelovekesh thelovekesh force-pushed the fix/wrapped-embeds-in-p-tags branch from 9f5d3fc to 775b6fa Compare July 7, 2023 20:31
@thelovekesh thelovekesh force-pushed the fix/wrapped-embeds-in-p-tags branch from 775b6fa to 8b8042a Compare July 7, 2023 20:32
@@ -39,7 +39,7 @@ public function unregister_embed() {
*/
public function filter_embed_oembed_html( $cache, $url, $attr ) {
$parsed_url = wp_parse_url( $url );
if ( empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || ! preg_match( '#(^|\.)(?P<host>polldaddy\.com|crowdsignal\.com|survey\.fm|poll\.fm)#', $parsed_url['host'], $matches ) ) {
if ( empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || ! preg_match( '#(^|\.)(?P<host>polldaddy\.com|poll\.fm|crowdsignal\.com|survey\.fm|poll\.fm)#', $parsed_url['host'], $matches ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like poll.fm is now duplicated in the regex.

protected function unwrap_p_element_by_child_tag_name( $dom, $child_tag_name ) {
$nodes = $dom->xpath->query( "//p/{$child_tag_name}" );

if ( $nodes->length && $nodes instanceof DOMNodeList ) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the order is backwards, and I don't think $nodes->length needs to be checked since the foreach will do that:

Suggested change
if ( $nodes->length && $nodes instanceof DOMNodeList ) {
if ( $nodes instanceof DOMNodeList ) {

*/
public function sanitize_raw_embeds( Document $dom ) {
// If there were any previous embeds in the DOM that were wrapped by `wpautop()`, unwrap them.
foreach ( [ Extension::IFRAME, Tag::IFRAME ] as $tag_name ) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wary of doing this for all iframes. I think it should be targeted specifically to embeds we know about. There could legitimately be a non-embed iframe which is inside of a p, and this could break styling.

Do we need AMP_Iframe_Embed_Handler?

$this->unwrap_p_element( $embed_node );
}
}
$this->unwrap_p_element_by_child_tag_name( $dom, Extension::FACEBOOK );
Copy link
Member

Choose a reason for hiding this comment

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

Might as well reuse this constant in where $this->amp_tag is set in the class above, i.e.:

private $amp_tag = Extension::FACEBOOK;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-iframe, amp-instagram, amp-youtube, amp-soundcloud wrapped in unnecessary p tags
3 participants