-
Notifications
You must be signed in to change notification settings - Fork 384
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
Changes from 1 commit
dca629e
6075007
77981c7
30d174d
c6869a9
ca45c7a
fe545a5
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,15 +11,6 @@ | |||||||||||
* Class AMP_Facebook_Embed_Handler | ||||||||||||
*/ | ||||||||||||
class AMP_Facebook_Embed_Handler extends AMP_Base_Embed_Handler { | ||||||||||||
const URL_PATTERN = '#https?://(www\.)?facebook\.com/.*#i'; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Default width. | ||||||||||||
* | ||||||||||||
* @var int | ||||||||||||
*/ | ||||||||||||
protected $DEFAULT_WIDTH = 600; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Default height. | ||||||||||||
* | ||||||||||||
|
@@ -45,57 +36,14 @@ class AMP_Facebook_Embed_Handler extends AMP_Base_Embed_Handler { | |||||||||||
* Registers embed. | ||||||||||||
*/ | ||||||||||||
public function register_embed() { | ||||||||||||
wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, [ $this, 'oembed' ], -1 ); | ||||||||||||
// Not implemented. | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Unregisters embed. | ||||||||||||
*/ | ||||||||||||
public function unregister_embed() { | ||||||||||||
wp_embed_unregister_handler( $this->amp_tag, -1 ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* WordPress OEmbed rendering callback. | ||||||||||||
* | ||||||||||||
* @param array $matches URL pattern matches. | ||||||||||||
* @param array $attr Matched attributes. | ||||||||||||
* @param string $url Matched URL. | ||||||||||||
* @return string HTML markup for rendered embed. | ||||||||||||
*/ | ||||||||||||
public function oembed( $matches, $attr, $url ) { | ||||||||||||
return $this->render( [ 'url' => $url ] ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Gets the rendered embed markup. | ||||||||||||
* | ||||||||||||
* @param array $args Embed rendering arguments. | ||||||||||||
* @return string HTML markup for rendered embed. | ||||||||||||
*/ | ||||||||||||
public function render( $args ) { | ||||||||||||
$args = wp_parse_args( | ||||||||||||
$args, | ||||||||||||
[ | ||||||||||||
'url' => false, | ||||||||||||
] | ||||||||||||
); | ||||||||||||
|
||||||||||||
if ( empty( $args['url'] ) ) { | ||||||||||||
return ''; | ||||||||||||
} | ||||||||||||
|
||||||||||||
$this->did_convert_elements = true; | ||||||||||||
|
||||||||||||
return AMP_HTML_Utils::build_tag( | ||||||||||||
$this->amp_tag, | ||||||||||||
[ | ||||||||||||
'data-href' => $args['url'], | ||||||||||||
'layout' => 'responsive', | ||||||||||||
'width' => $this->args['width'], | ||||||||||||
'height' => $this->args['height'], | ||||||||||||
] | ||||||||||||
); | ||||||||||||
// Not implemented. | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
|
@@ -136,7 +84,13 @@ public function sanitize_raw_embeds( Document $dom ) { | |||||||||||
$scripts[] = $script; | ||||||||||||
} | ||||||||||||
foreach ( $scripts as $script ) { | ||||||||||||
$script->parentNode->removeChild( $script ); | ||||||||||||
$parent_node = $script->parentNode; | ||||||||||||
$parent_node->removeChild( $script ); | ||||||||||||
|
||||||||||||
// Remove parent node if it is an empty <p> tag. | ||||||||||||
if ( 'p' === $parent_node->tagName && null === $parent_node->firstChild ) { | ||||||||||||
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.
Suggested change
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. 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. After looking at some of the other embeds, they are for the most part also wrapped with a |
||||||||||||
$parent_node->parentNode->removeChild( $parent_node ); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
$fb_root->parentNode->removeChild( $fb_root ); | ||||||||||||
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. It turns out that when you have multiple Facebook embeds on a page, each instance will include a
Suggested change
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. In theory this should work, but when it retrieves the 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. Why would it return the same |
||||||||||||
} | ||||||||||||
|
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.
The
script
tag is wrapped with ap
tag (fromwpautop()
), so I've removed the lingering empty tag if it's there.