Skip to content

Commit

Permalink
Remove obsolete add_auto_width_to_figure from #1086
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Apr 2, 2019
1 parent a82a87f commit 65f1c0c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
35 changes: 0 additions & 35 deletions includes/sanitizers/class-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ private function adjust_and_replace_node( $node ) {
$noscript = $this->dom->createElement( 'noscript' );
$noscript->appendChild( $node );
$img_node->appendChild( $noscript );

$this->add_auto_width_to_figure( $img_node );
}

/**
Expand Down Expand Up @@ -320,37 +318,4 @@ private function is_gif_url( $url ) {
$path = wp_parse_url( $url, PHP_URL_PATH );
return substr( $path, -strlen( $ext ) ) === $ext;
}

/**
* Add an inline style to set the `<figure>` element's width to `auto` instead of `fit-content`.
*
* @since 1.0
* @see https://github.com/ampproject/amp-wp/issues/1086
*
* @param DOMElement $node The DOMNode to adjust and replace.
*/
protected function add_auto_width_to_figure( $node ) {
$figure = $node->parentNode;
if ( ! ( $figure instanceof DOMElement ) || 'figure' !== $figure->tagName ) {
return;
}

$class = $figure->getAttribute( 'class' );
// Target only the <figure> with a 'wp-block-image' class attribute.
if ( false === strpos( $class, 'wp-block-image' ) ) {
return;
}

// Target only <figure> without a 'is-resized' class attribute.
if ( false !== strpos( $class, 'is-resized' ) ) {
return;
}

$new_style = 'width: auto;';
if ( $figure->hasAttribute( 'style' ) ) {
$figure->setAttribute( 'style', $new_style . $figure->getAttribute( 'style' ) );
} else {
$figure->setAttribute( 'style', $new_style );
}
}
}
8 changes: 4 additions & 4 deletions tests/test-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ public function get_data() {

'wide_image' => array(
'<figure class="wp-block-image"><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" /></figure>',
'<figure class="wp-block-image" style="width: auto;"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
'<figure class="wp-block-image"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
),

'wide_image_center_aligned' => array(
'<figure class="wp-block-image aligncenter"><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" /></figure>',
'<figure class="wp-block-image aligncenter" style="width: auto;"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
'<figure class="wp-block-image aligncenter"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
),

'wide_image_left_aligned_custom_style' => array(
'<figure class="wp-block-image alignleft" style="border:solid 1px red;"><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" /></figure>',
'<figure class="wp-block-image alignleft" style="width: auto;border:solid 1px red;"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
'<figure class="wp-block-image alignleft" style="border:solid 1px red;"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
),

'wide_image_right_aligned' => array(
'<figure class="wp-block-image alignright"><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" /></figure>',
'<figure class="wp-block-image alignright" style="width: auto;"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
'<figure class="wp-block-image alignright"><amp-img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967 amp-wp-enforced-sizes" width="580" height="300" layout="intrinsic"><noscript><img src="http://placehold.it/580x300" alt="Image Alignment 580x300" class="wp-image-967" width="580" height="300"></noscript></amp-img></figure>',
),

'wide_image_is_resized' => array(
Expand Down

0 comments on commit 65f1c0c

Please sign in to comment.