-
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
#841 Improve support for default embeds #889
Conversation
Hi @ThierryA and @westonruter! I'd love to get your input on some of the embed notes listed above. Ones like CollegeHumor and Screencast seem like they may be a bit incompatible here, but we do have some room for improvement with the addition of amp-video and amp-audio playlists. |
/** | ||
* Include the required AMP Reddit scripts. | ||
*/ | ||
public function get_scripts() { |
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.
It should be unnecessary to implement get_scripts()
because now the whitelist sanitizer will automatically discover the amp-reddit
script as being required through sanitization when it runs across the amp-reddit
element.
*/ | ||
|
||
/** | ||
* Class AMP_Reddit_Embed_Handler |
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.
Please add @since
tags to the phpdoc.
* | ||
* @var string | ||
*/ | ||
private static $script_src = 'https://cdn.ampproject.org/v0/amp-reddit-0.1.js'; |
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.
Per below, the $script_src
needn't be defined at the embed level. See #885.
'layout' => 'responsive', | ||
'data-embedtype' => 'post', | ||
'width' => '596', | ||
'height' => '141', |
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.
Why are the width
and height
being hard-coded like this?
*/ | ||
|
||
/** | ||
* Class AMP_Tumblr_Embed_Handler |
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.
Please add @since 0.7
tags to the phpdoc.
@kaitnyl Sorry for the delay:
Leaving the CSS on the embed output should successfully get sanitized by the CSS sanitizer. It will move any inline
Yeah, this embed doesn't work on desktop either. So it is broken on their side and we shouldn't try to fix it on our side.
If it is trying to embed a SWF then I think it should be intentionally not supported. |
Good question. One possibility would be to just create endpoints from WP that render out the playlist in standalone form and then render it in an What would be great to see is a custom AMP implementation of the audio and video playlist which made use of |
Oh, and I should also mention |
…mbed, and use class vars for height/width.
* | ||
* @var int | ||
*/ | ||
protected $DEFAULT_WIDTH = 596; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.MemberNotSnakeCase |
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.
Maybe the oEmbed handler can make a request off to a URL like https://www.reddit.com/comments/7t6msa.json?limit=1&app=embed to obtain the width
/height
specific for the given Reddit embed.
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.
I've gone ahead and made it follow 100%/100% for the responsive layout type. This solves longer embeds using media that were getting cut off by the fixed dimensions, but now suffers from the same issue as reported here.
The dimensions given in https://www.reddit.com/comments/7t6msa.json?limit=1&app=embed are just for the media attachments and wouldn't encompass the entire embed content.
// Outlying style tag from oembed. | ||
if ( isset( $result[0] ) ) { | ||
$css = str_replace( '<style type="text/css">', '<style amp-meetup>', $result[0] ); | ||
echo $css; // WPCS: XSS ok. |
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.
In the builtin paired mode theme, the CSS is getting printed before the <html>
starts. It should get removed entirely I believe.
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.
One additional reason why the CSS should be discarded is that it includes !important
properties, which are illegal in AMP. If it didn't, then maybe it could make sense to move the CSS to the amp-custom
style in the head
. But alas, I think we just have to strip it entirely.
* Add phpdoc for returns * Use -1 priority for embed handlers.
return ''; | ||
} | ||
|
||
$content = wp_oembed_get( $args['url'] ); |
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.
I'm seeing that wp_oembed_get()
here is resulting in an HTTP request with every call. I was expecting it to be cached. Apparently to cache we need to use $wp_embed->shortcode( array(), $args['url'] )
. This seems to be a problem in core as well with the Video widget: https://github.com/WordPress/wordpress-develop/blob/afb4f45e62520397b147e560e051d3940797121e/src/wp-includes/widgets/class-wp-widget-media-video.php#L144
I think core is erroneously doing an HTTP request for every load of a page with a video widget that is a non-YouTube and non-Vimeo oEmbed.
…ix/841-default-embeds
} | ||
|
||
// Must enforce https for amp-iframe, but editors can supply either on desktop. | ||
$args['url'] = str_replace( 'http://', 'https://', $args['url'] ); |
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.
Unfortunately it seems this is not working fully. When attempting to embed https://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930 then Tumblr will redirect from HTTPS to HTTP for some reason. When serving a page over HTTPS, as they should be, then the iframe is blocked from rendering.
Playlist Embeds PR #954 (WIP) is handling playlist embeds. |
This addresses issue #841.
See full list of previous embed compatibility here.
I'm just going to highlight the updated/troubled ones below:
Update: this list is now updated, and located in the project wiki
*Status as of this diff.
Should we try and create our own version of amp-video and amp-audio element playlists? If we do now, they also likely wouldn't be valid AMP elements anymore.