diff --git a/includes/embeds/class-amp-twitter-embed-handler.php b/includes/embeds/class-amp-twitter-embed-handler.php
index c6af54996b0..e71dece6d8d 100644
--- a/includes/embeds/class-amp-twitter-embed-handler.php
+++ b/includes/embeds/class-amp-twitter-embed-handler.php
@@ -16,6 +16,22 @@
*/
class AMP_Twitter_Embed_Handler extends AMP_Base_Embed_Handler {
+ /**
+ * Default width.
+ *
+ * @var int|string
+ */
+ protected $DEFAULT_WIDTH = 'auto';
+
+ /**
+ * Default height.
+ *
+ * This is the minimum height for a tweet, with just a single line of text.
+ *
+ * @var int
+ */
+ protected $DEFAULT_HEIGHT = 197;
+
/**
* URL pattern for a Tweet URL.
*
@@ -97,9 +113,13 @@ public function oembed_timeline( $matches ) {
}
}
- $attributes['layout'] = 'responsive';
$attributes['width'] = $this->args['width'];
$attributes['height'] = $this->args['height'];
+ if ( empty( $attributes['width'] ) || 'auto' === $attributes['width'] ) {
+ $attributes['layout'] = 'fixed-height';
+ } else {
+ $attributes['layout'] = 'responsive';
+ }
$this->did_convert_elements = true;
@@ -161,9 +181,9 @@ private function create_amp_twitter_and_replace_node( Document $dom, DOMElement
}
$attributes = [
- 'width' => $this->DEFAULT_WIDTH,
+ 'width' => 'auto',
'height' => $this->DEFAULT_HEIGHT,
- 'layout' => 'responsive',
+ 'layout' => 'fixed-height',
'data-tweetid' => $tweet_id,
];
diff --git a/tests/php/test-amp-twitter-embed-handler.php b/tests/php/test-amp-twitter-embed-handler.php
index 3300ba184e3..3bbfce65cd8 100644
--- a/tests/php/test-amp-twitter-embed-handler.php
+++ b/tests/php/test-amp-twitter-embed-handler.php
@@ -103,27 +103,27 @@ public function get_conversion_data() {
],
'url_simple' => [
'https://twitter.com/wordpress/status/987437752164737025' . PHP_EOL,
- " Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78 — WordPress (@WordPress) April 20, 2018 Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78 — WordPress (@WordPress) April 20, 2018 On our way to the #GoogleDance! #SMX 💃🏻 pic.twitter.com/N8kZ9M3eN4 — Search Engine Land (@sengineland) March 3, 2016 On our way to the #GoogleDance! #SMX 💃🏻 pic.twitter.com/N8kZ9M3eN4 — Search Engine Land (@sengineland) March 3, 2016\n
\n
\n
\n
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
-- WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '-- WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '-- WordPress (@WordPress) April 20, 2018
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
— WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '— WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '— WordPress (@WordPress) April 20, 2018
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
— WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '— WordPress (@WordPress) April 20, 2018
' . "\n" . 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
' . "\n" . '— WordPress (@WordPress) April 20, 2018
', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - 'Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
-- WordPress (@WordPress) April 20, 2018
Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
-- WordPress (@WordPress) April 20, 2018
Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78
-- WordPress (@WordPress) April 20, 2018