diff --git a/includes/embeds/class-amp-twitter-embed.php b/includes/embeds/class-amp-twitter-embed.php index c6410ff1fa0..3b3849c1501 100644 --- a/includes/embeds/class-amp-twitter-embed.php +++ b/includes/embeds/class-amp-twitter-embed.php @@ -229,15 +229,23 @@ private function create_amp_twitter_and_replace_node( $dom, $node ) { return; } + $attributes = [ + 'width' => $this->DEFAULT_WIDTH, + 'height' => $this->DEFAULT_HEIGHT, + 'layout' => 'responsive', + 'data-tweetid' => $tweet_id, + ]; + + if ( $node->hasAttributes() ) { + foreach ( $node->attributes as $attr ) { + $attributes[ $attr->nodeName ] = $attr->nodeValue; + } + } + $new_node = AMP_DOM_Utils::create_node( $dom, $this->amp_tag, - [ - 'width' => $this->DEFAULT_WIDTH, - 'height' => $this->DEFAULT_HEIGHT, - 'layout' => 'responsive', - 'data-tweetid' => $tweet_id, - ] + $attributes ); $this->sanitize_embed_script( $node ); diff --git a/tests/php/test-amp-twitter-embed.php b/tests/php/test-amp-twitter-embed.php index df3c917f815..df2843c8a1d 100644 --- a/tests/php/test-amp-twitter-embed.php +++ b/tests/php/test-amp-twitter-embed.php @@ -114,23 +114,33 @@ public function test__get_scripts( $source, $expected ) { */ public function get_raw_embed_dataset() { return [ - 'no_embed' => [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

', ], - 'embed_blockquote_without_twitter' => [ + 'embed_blockquote_without_twitter' => [ '
lorem ipsum
', '
lorem ipsum
', ], - 'blockquote_embed' => [ + 'blockquote_embed' => [ wpautop( '

Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78

— WordPress (@WordPress) April 20, 2018
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - '' . "\n\n", + '' . "\n\n", ], - 'blockquote_embed_not_autop' => [ + 'blockquote_embed_with_data_conversation' => [ + wpautop( '

Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78

— WordPress (@WordPress) April 20, 2018
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine + '' . "\n\n", + ], + + 'blockquote_embed_with_data_theme' => [ + wpautop( '

Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78

— WordPress (@WordPress) April 20, 2018
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine + '' . "\n\n", + ], + + 'blockquote_embed_not_autop' => [ '

Celebrate the WordPress 15th Anniversary on May 27 https://t.co/jv62WkI9lr pic.twitter.com/4ZECodSK78

— WordPress (@WordPress) April 20, 2018
', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine - ' ', + ' ', ], ]; }