-
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
Ensure iframes in embeds with aspect ratios get responsive layout #5486
Conversation
Plugin builds for 8ea462b are ready 🛎️!
|
@@ -76,10 +76,11 @@ static function ( $class ) use ( &$responsive_width, &$responsive_height ) { | |||
// @todo Should we consider just eliminating the .wp-block-embed__wrapper element since unnecessary? | |||
// For visual parity with blocks in non-AMP pages, override the oEmbed's natural responsive dimensions with the aspect ratio specified in the wp-embed-aspect-* class name. | |||
if ( $responsive_width && $responsive_height ) { | |||
$amp_element = $this->dom->xpath->query( './div[ contains( @class, "wp-block-embed__wrapper" ) ]/*[ @layout = "responsive" ]', $node )->item( 0 ); | |||
$amp_element = $this->dom->xpath->query( './div[ contains( @class, "wp-block-embed__wrapper" ) ]/*[ @layout = "responsive" or @layout = "intrinsic" ]', $node )->item( 0 ); |
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.
Alternatively you could use:
$amp_element = $this->dom->xpath->query( './div[ contains( @class, "wp-block-embed__wrapper" ) ]/*[ @layout = "responsive" or @layout = "intrinsic" ]', $node )->item( 0 ); | |
$amp_element = $this->dom->xpath->query( './div[ contains( @class, "wp-block-embed__wrapper" ) ]/*[ @layout = ( "responsive" or "intrinsic" ) ]', $node )->item( 0 ); |
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.
Interesting. I wasn't aware that works in XPath. So it's distinctly not like PHP where this definitely wouldn't work:
if ( $layout === ( 'responsive' || 'intrinsic' ) ) {
Where instead you'd need to do:
if ( in_array( $layout, [ 'responsive', 'intrinsic' ], true ) ) {
That seems like somewhat of an esoteric feature of XPath. Where did you come across it?
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.
Yea since XPath is it's own query language I doubt PHP would have any influence on the query itself. I have a cheatsheet that I refer to from time to time when I'm writing queries: https://devhints.io/xpath.
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.
Some examples there are only XPath 2.0 compatible so YMMV.
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 actually don't see the @layout = ( "responsive" or "intrinsic" )
syntax mentioned on that cheatsheet.
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 any case, I like the conciseness, but given the boolean logic is foreign to the syntax of how other languages do booleans, I think I'll leave it as is.
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 actually don't see the
@layout = ( "responsive" or "intrinsic" )
syntax mentioned on that cheatsheet.
Oh right, that was inspired by some of the logic operator examples on the page. The syntax is indeed a bit esoteric so I'm fine with what's there currently.
…nt/2204-default-amp-endpoint * 'develop' of github.com:ampproject/amp-wp: Fix hard-coded SSR tests Change string rendition of float numbers for sizers Update spec tests Ensure iframes in embeds with aspect ratios get responsive layout (#5486) Include additional sandbox tokens for converted iframes (#5483) Fix alignment for phpcs Update dependency sirbrillig/phpcs-variable-analysis to v2.9.0 Fix PHPStan issue Update dependency terser-webpack-plugin to v4.2.3 Update dependency mini-css-extract-plugin to v0.12.0 Add issue reference to TODO Add expiry to stylesheet cache transients that exceed cache expiry Add test to assert stylesheet cache is not autoloaded Fix rendering translations in JS (#5461) Extract regex into constant Add tests for other doctypes Fix PSR2.Methods.FunctionCallSignature Ensure at least one space after doctype Always normalize to use HTML5 doctype
Summary
I noticed that responsive Embed blocks that have videos were not getting
layout=responsive
as they should.Given this
post_content
:This issue has not been noticed before very often because YouTube videos, for example, are getting generated with
layout=responsive
from the start. This is specifically to fix responsiveness foriframe
elements that we pass through which get converted toamp-iframe
withlayout=intrinsic
by default in the iframe sanitizer.Checklist