-
Notifications
You must be signed in to change notification settings - Fork 383
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
base: develop
Are you sure you want to change the base?
Changes from all commits
c899c45
0ffcc88
40e9709
17b2dde
b42020b
c719d1c
8b8042a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like |
||
return $cache; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* @package AMP | ||
*/ | ||
|
||
use AmpProject\Extension; | ||
use AmpProject\Dom\Document; | ||
|
||
/** | ||
|
@@ -114,12 +115,7 @@ public function render( $args ) { | |
*/ | ||
public function sanitize_raw_embeds( Document $dom ) { | ||
// If there were any previous embeds in the DOM that were wrapped by `wpautop()`, unwrap them. | ||
$embed_nodes = $dom->xpath->query( "//p/{$this->amp_tag}" ); | ||
if ( $embed_nodes->length ) { | ||
foreach ( $embed_nodes as $embed_node ) { | ||
$this->unwrap_p_element( $embed_node ); | ||
} | ||
} | ||
$this->unwrap_p_element_by_child_tag_name( $dom, Extension::FACEBOOK ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well reuse this constant in where private $amp_tag = Extension::FACEBOOK; |
||
|
||
$nodes = $dom->getElementsByTagName( $this->sanitize_tag ); | ||
$num_nodes = $nodes->length; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Class for handling `amp-iframe` embeds. | ||
* | ||
* @package AMP | ||
* @since 2.4.1 | ||
*/ | ||
|
||
use AmpProject\Html\Tag; | ||
use AmpProject\Extension; | ||
use AmpProject\Dom\Document; | ||
|
||
/** | ||
* Class AMP_Iframe_Embed_Handler | ||
* | ||
* @since 2.4.1 | ||
*/ | ||
class AMP_Iframe_Embed_Handler extends AMP_Base_Embed_Handler { | ||
|
||
/** | ||
* Register embed. | ||
*/ | ||
public function register_embed() { | ||
// Not implemented. | ||
} | ||
|
||
/** | ||
* Unregister embed. | ||
*/ | ||
public function unregister_embed() { | ||
// Not implemented. | ||
} | ||
|
||
/** | ||
* Sanitize `amp-iframe` raw embeds. | ||
* | ||
* @param Document $dom Document. | ||
* | ||
* @return void | ||
*/ | ||
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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Do we need |
||
$this->unwrap_p_element_by_child_tag_name( $dom, $tag_name ); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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 theforeach
will do that: