Skip to content
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

Filter the attachment image attributes for the Twenty Seventeen theme. #1321

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions includes/sanitizers/class-amp-core-theme-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer {
'//header[@id = "masthead"]//a[ contains( @class, "menu-scroll-down" ) ]',
),
'set_twentyseventeen_quotes_icon' => array(),
'add_twentyseventeen_attachment_image_attributes' => array(),
),

// Twenty Sixteen.
Expand Down Expand Up @@ -344,6 +345,29 @@ public static function set_twentyseventeen_quotes_icon() {
} );
}

/**
* Add filter to adjust the attachment image attributes to ensure attachment pages have a consistent <amp-img> rendering.
*
* This is only used in Twenty Seventeen.
*
* @since 1.0
* @link https://github.com/WordPress/wordpress-develop/blob/ddc8f803c6e99118998191fd2ea24124feb53659/src/wp-content/themes/twentyseventeen/functions.php#L545:L554
*/
public static function add_twentyseventeen_attachment_image_attributes() {
add_filter( 'wp_get_attachment_image_attributes', function ( $attr, $attachment, $size ) {
if ( ! is_attachment() ) {
return $attr;
}

$sizes = wp_get_attachment_image_sizes( $attachment->ID, $size );
if ( false !== $sizes ) {
$attr['sizes'] = $sizes;
}

return $attr;
}, 11, 3 );
}

/**
* Fix up core themes to do things in the AMP way.
*
Expand Down