Youtube aspect ratio broken in 1.6.3
-
Hi, the css aspect-ratio of the Youtube embed overlay seems broken in the new Update.
I tested on two different sites, both times I got weird preview image formats like 500 by 750 or 1124 by 1000 when it should be closer to 16/9 Format.
-
There is no change since introducing the automatic aspect ratio in 1.6.0.
Also, the aspect ratio is automatically set depending on the given width and height of the embed, which is received via the oEmbed API from YouTube directly.
Do you have any link where I can check the behavior?
Ok, it might be an older issue. I now looked a bit deeper and have closed in on this problem:
It’s only happening when using Classic Editor.
Embeds are not wrapped in a wp-block element here and line 101 in embed-privacy.css does not come into usage (position: absolute, w & h 100%, etc: https://plugins.trac.www.ads-software.com/browser/embed-privacy/trunk/assets/style/embed-privacy.css#L101 ).
This wouldn’t be a problem, but the aspect ratio values are totally off. They now describe a portrait format instead of the actual landscape format.
Maybe they are just in the wrong order? (should be [width] / [height]).
I’ve shared a link here on my dropbox (So I can keep it somewhat private):
https://www.dropbox.com/s/ozp1p878bkyd45m/embed-privacy-aspect-ratio-link.txt?dl=0It seems that the WordPress oEmbed functionality doesn’t make use of the given width and height attributes at all and just uses static values where the height is always more than the width.
I will look for a solution for that.
Maybe the preview image itself can be used via php’s getimagesize().
just a thoughtThis should have been fixed in version 1.6.4 now.
Thanks, but it’s only working if the content width is 750. Maybe better to check for the content_width global instead at:
https://plugins.trac.www.ads-software.com/browser/embed-privacy/tags/1.6.4/inc/class-embed-privacy.php?rev=2844844#L1910I think it’s usually defined via the global $GLOBALS[‘content_width’], like here:
https://themes.trac.www.ads-software.com/browser/twentytwentyone/1.7/functions.php#L384Thank you for reporting, I will take a look into it!
Hey!
We have broken aspect ratios too.
Demo: https://news.wekiwi.de/2022/10/19/wekiwi-in-videos-erklaert/
Also here: https://blog.drivingralle.de/Some logging I have made right before the inline style is generated:
$args array ( 'width' => 580, 'height' => 870.0, 'post_id' => 41, 'embed_title' => '?Tim Urban: Tribalism, Marxism, Liberalism, Social Justice, and Politics | Lex Fridman Podcast #360“', 'embed_url' => 'https://www.youtube.com/watch?v=GkZz2I6sK08', 'strip_newlines' => true, ) $GLOBALS['content_width'] 580
If I remove the line everything looks fine for my use cases:
aspect-ratio: <?php echo esc_html( $args['width'] . '/' . $args['height'] ); ?>;
Anything I can check to help debugging the problem?
Greetings
derRALF- This reply was modified 1 year, 8 months ago by Drivingralle.
Hm, it should have been fixed within version 1.6.5 with this commit: https://github.com/epiphyt/embed-privacy/commit/515573c20ec7544d7f9af6a5196e9a83f7a6dd5f
Can you confirm that this if clause works for you and the default parameters are unset?
Added some logging:
error_log( var_export( '$args before', true ) ); error_log( var_export( $args, true ) ); // the default dimensions are useless if ( ! empty( $args['height'] ) && $args['height'] === 1000 && ! empty( $args['width'] ) && ( $args['width'] === 750 || $args['width'] === $GLOBALS['content_width'] ) ) { unset( $args['height'], $args['width'] ); $dimensions = $this->get_oembed_dimensions( $output ); if ( ! empty( $dimensions ) ) { $args = array_merge( $args, $dimensions ); } } error_log( var_export( '$args after', true ) ); error_log( var_export( $args, true ) ); // add two click to markup return $this->get_output_template( $embed_provider, $embed_provider_lowercase, $output, $args );
Log output:
[02-Mar-2023 21:25:30 UTC] '$args before' [02-Mar-2023 21:25:30 UTC] array ( 'width' => 580, 'height' => 870.0, 'post_id' => 41, 'embed_title' => '?Tim Urban: Tribalism, Marxism, Liberalism, Social Justice, and Politics | Lex Fridman Podcast #360“', 'embed_url' => 'https://www.youtube.com/watch?v=GkZz2I6sK08', 'strip_newlines' => true, ) [02-Mar-2023 21:25:30 UTC] '$args after' [02-Mar-2023 21:25:30 UTC] array ( 'width' => 580, 'height' => 870.0, 'post_id' => 41, 'embed_title' => '?Tim Urban: Tribalism, Marxism, Liberalism, Social Justice, and Politics | Lex Fridman Podcast #360“', 'embed_url' => 'https://www.youtube.com/watch?v=GkZz2I6sK08', 'strip_newlines' => true, )
I see the problem. Since the height is not the default, these parameters won’t get deleted. Need to check how to solve that problem.
@drivingralle Can you please test the following patch?
diff --git a/inc/class-embed-privacy.php b/inc/class-embed-privacy.php index e679a76..20713ac 100644 --- a/inc/class-embed-privacy.php +++ b/inc/class-embed-privacy.php @@ -1908,9 +1908,12 @@ class Embed_Privacy { $args['strip_newlines'] = true; // the default dimensions are useless + // so ignore them if recognized as such + $defaults = wp_embed_defaults( $url ); + if ( - ! empty( $args['height'] ) && $args['height'] === 1000 - && ! empty( $args['width'] ) && ( $args['width'] === 750 || $args['width'] === $GLOBALS['content_width'] ) + ! empty( $args['height'] ) && $args['height'] === $defaults['height'] + && ! empty( $args['width'] ) && $args['width'] === $defaults['width'] ) { unset( $args['height'], $args['width'] );
@kittmedia Haben den Patch auf den beiden Websites wie oben verlinkt angewendet und es sieht deutlich besser aus.
Wenn das Verhalten dem entspricht was der Plan war würde ich sagen, ein erfolgreicher Patch.
- The topic ‘Youtube aspect ratio broken in 1.6.3’ is closed to new replies.