-
Notifications
You must be signed in to change notification settings - Fork 383
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
Experiment: Add native img
opt-in to prevent conversion to amp-img
/amp-anim
#6518
Changes from 11 commits
4808464
4eab3f8
3bc2fdd
5f2eff7
25ef666
5d56e41
a2e192d
8a32fb9
d2f8d11
404258c
d842d93
35b4189
d04b690
de0f52a
a7da20b
b65171f
21dd207
706a39a
9e634f3
a5e7348
4d2504c
4148e13
35bed57
8097ac9
8f6b531
4a20e77
72b9dd1
9ed515d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,6 @@ | |
* For the custom AMP implementation of the 'playlist' shortcode. | ||
*/ | ||
.wp-playlist .wp-playlist-current-item img { | ||
margin-right: 0; | ||
} | ||
|
||
.wp-playlist .wp-playlist-current-item amp-img { | ||
Comment on lines
-5
to
-8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what was going on here originally, but since |
||
float: left; | ||
margin-right: 10px; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer { | |
* @type string $stylesheet Stylesheet slug. | ||
* @type string $template Template slug. | ||
* @type array $theme_features List of theme features that need to be applied. Features are method names, | ||
* @type bool $use_native_img Whether to use native img. | ||
* } | ||
*/ | ||
protected $args; | ||
|
@@ -76,9 +77,10 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer { | |
* @since 1.5.0 Converted `theme_features` variable into `get_theme_config` function. | ||
* | ||
* @param string $theme_slug Theme slug. | ||
* @param array $args Sanitizer args. | ||
* @return array|null Array comprising of the theme config if its slug is found, null if it is not. | ||
*/ | ||
protected static function get_theme_features_config( $theme_slug ) { | ||
protected static function get_theme_features_config( $theme_slug, $args = [] ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for passing around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because at this point it's a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right I didn't notice the |
||
switch ( $theme_slug ) { | ||
case 'twentytwentyone': | ||
$config = [ | ||
|
@@ -135,9 +137,9 @@ protected static function get_theme_features_config( $theme_slug ) { | |
'add_twentytwenty_modals' => [], | ||
'add_twentytwenty_toggles' => [], | ||
'add_nav_menu_styles' => [], | ||
'add_twentytwenty_masthead_styles' => [], | ||
'add_img_display_block_fix' => [], | ||
'add_twentytwenty_custom_logo_fix' => [], | ||
'add_twentytwenty_masthead_styles' => $args, | ||
'add_img_display_block_fix' => $args, | ||
'add_twentytwenty_custom_logo_fix' => $args, | ||
'add_twentytwenty_current_page_awareness' => [], | ||
]; | ||
|
||
|
@@ -188,7 +190,6 @@ protected static function get_theme_features_config( $theme_slug ) { | |
], | ||
'force_fixed_background_support' => [], | ||
'add_twentyseventeen_masthead_styles' => [], | ||
'add_twentyseventeen_image_styles' => [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See why removed below. |
||
'add_twentyseventeen_sticky_nav_menu' => [], | ||
'add_has_header_video_body_class' => [], | ||
'add_nav_menu_styles' => [ | ||
|
@@ -199,7 +200,7 @@ protected static function get_theme_features_config( $theme_slug ) { | |
'//header[@id = "masthead"]//a[ contains( @class, "menu-scroll-down" ) ]', | ||
], | ||
'set_twentyseventeen_quotes_icon' => [], | ||
'add_twentyseventeen_attachment_image_attributes' => [], | ||
'add_twentyseventeen_attachment_image_attributes' => $args, | ||
]; | ||
|
||
// Twenty Sixteen. | ||
|
@@ -489,7 +490,7 @@ protected static function get_theme_features( $args, $static = false ) { | |
$theme_candidates = wp_array_slice_assoc( $args, [ 'stylesheet', 'template' ] ); | ||
foreach ( $theme_candidates as $theme_candidate ) { | ||
if ( in_array( $theme_candidate, self::$supported_themes, true ) ) { | ||
$theme_features = self::get_theme_features_config( $theme_candidate ); | ||
$theme_features = self::get_theme_features_config( $theme_candidate, $args ); | ||
break; | ||
} | ||
} | ||
|
@@ -563,8 +564,14 @@ static function ( $content ) { | |
* | ||
* @since 1.0 | ||
* @link https://github.com/WordPress/wordpress-develop/blob/ddc8f803c6e99118998191fd2ea24124feb53659/src/wp-content/themes/twentyseventeen/functions.php#L545:L554 | ||
* | ||
* @param array $args Args. | ||
*/ | ||
public static function add_twentyseventeen_attachment_image_attributes() { | ||
public static function add_twentyseventeen_attachment_image_attributes( $args = [] ) { | ||
if ( ! empty( $args['use_native_img'] ) ) { | ||
return; | ||
} | ||
|
||
/* | ||
* The max-height of the `.custom-logo-link img` is defined as being 80px, unless | ||
* there is header media in which case it is 200px. Issues related to vertically-squashed | ||
|
@@ -799,9 +806,16 @@ protected static function get_twentyseventeen_navigation_outer_height() { | |
} | ||
|
||
/** | ||
* Add required styles for featured image header and image blocks in Twenty Twenty. | ||
* Add required styles for featured image header in Twenty Twenty. | ||
* | ||
* @param array $args Args. | ||
*/ | ||
public static function add_twentytwenty_masthead_styles() { | ||
public static function add_twentytwenty_masthead_styles( $args = [] ) { | ||
if ( ! empty( $args['use_native_img'] ) ) { | ||
return; | ||
} | ||
|
||
// @todo This was introduced in <https://github.com/ampproject/amp-wp/commit/e1c7462> but it doesn't seem to have any effect. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't noticed any discrepancies with this either. |
||
add_action( | ||
'wp_enqueue_scripts', | ||
static function() { | ||
|
@@ -811,10 +825,6 @@ static function() { | |
.featured-media amp-img { | ||
position: static; | ||
} | ||
|
||
.wp-block-image img { | ||
display: block; | ||
} | ||
Comment on lines
-815
to
-817
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule is redundant since d976798 added a |
||
</style> | ||
<?php | ||
$styles = str_replace( [ '<style>', '</style>' ], '', ob_get_clean() ); | ||
|
@@ -833,8 +843,14 @@ static function() { | |
* @since 1.5 | ||
* @link https://github.com/ampproject/amp-wp/issues/4418 | ||
* @link https://codepen.io/westonruter/pen/rNVqadv | ||
* | ||
* @param array $args Args. | ||
*/ | ||
public static function add_twentytwenty_custom_logo_fix() { | ||
public static function add_twentytwenty_custom_logo_fix( $args = [] ) { | ||
if ( ! empty( $args['use_native_img'] ) ) { | ||
return; | ||
} | ||
|
||
$method = __METHOD__; | ||
add_filter( | ||
'get_custom_logo', | ||
|
@@ -885,8 +901,14 @@ function ( $attr_name ) { | |
* | ||
* @since 1.5 | ||
* @link https://github.com/ampproject/amp-wp/issues/4419 | ||
* | ||
* @param array $args Args. | ||
*/ | ||
public static function add_img_display_block_fix() { | ||
public static function add_img_display_block_fix( $args = [] ) { | ||
if ( ! empty( $args['use_native_img'] ) ) { | ||
return; | ||
} | ||
|
||
$method = __METHOD__; | ||
// Note that wp_add_inline_style() is not used because this stylesheet needs to be added _before_ style.css so | ||
// that any subsequent style rules for images will continue to override. | ||
|
@@ -958,38 +980,6 @@ static function() { | |
); | ||
} | ||
|
||
/** | ||
* Override the featured image header styling in style.css. | ||
* Used only for Twenty Seventeen. | ||
* | ||
* @since 1.0 | ||
* @link https://github.com/WordPress/wordpress-develop/blob/1af1f65a21a1a697fb5f33027497f9e5ae638453/src/wp-content/themes/twentyseventeen/style.css#L2100 | ||
*/ | ||
public static function add_twentyseventeen_image_styles() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the left is non-AMP and the right AMP, I'm confused as to why in both instances the featured image look the same. Wouldn't the styles only affect the AMP version, and thus a difference on the AMP page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, yes, the left version is the non-AMP and the right is the AMP. In the first screenshot (before) you can see this slight gray bar under the image. This goes away and the image is identical to the non-AMP version when these styles are removed. So it seems the original reason for this code being add in the first place was eliminated at some point, either through a change in AMP core or to the Twenty Seventeen theme. In fact, what confuses me is that this is overriding the display to be |
||
add_action( | ||
'wp_enqueue_scripts', | ||
static function() { | ||
ob_start(); | ||
?> | ||
<style> | ||
/* Override the display: block in twentyseventeen/style.css, as <amp-img> is usually inline-block. */ | ||
.single-featured-image-header amp-img { | ||
display: inline-block; | ||
} | ||
|
||
/* Because the <amp-img> is inline-block, its container needs this rule to center it. */ | ||
.single-featured-image-header { | ||
text-align: center; | ||
} | ||
</style> | ||
<?php | ||
$styles = str_replace( [ '<style>', '</style>' ], '', ob_get_clean() ); | ||
wp_add_inline_style( get_template() . '-style', $styles ); | ||
}, | ||
11 | ||
); | ||
} | ||
|
||
/** | ||
* Add sticky nav menu to Twenty Seventeen. | ||
* | ||
|
@@ -1344,7 +1334,7 @@ static function() { | |
padding-top: 0; /* Override responsive hack which is handled by AMP layout. */ | ||
overflow: visible; | ||
} | ||
.featured-content .post-thumbnail amp-img { | ||
.featured-content .post-thumbnail .wp-post-image { | ||
Comment on lines
-1347
to
+1337
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be changed instead from |
||
position: static; | ||
left: auto; | ||
top: auto; | ||
|
@@ -1420,7 +1410,7 @@ static function() { | |
font-size: 32px; | ||
line-height: 46px; | ||
} | ||
.featured-content .post-thumbnail amp-img { | ||
.featured-content .post-thumbnail .wp-post-image { | ||
object-fit: cover; | ||
object-position: top; | ||
} | ||
|
@@ -1430,7 +1420,7 @@ static function() { | |
float: none; | ||
margin: 0; | ||
} | ||
.featured-content .post-thumbnail amp-img { | ||
.featured-content .post-thumbnail .wp-post-image { | ||
height: 55.49132947vw; | ||
} | ||
.slider-control-paging li { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
amp-img
andimg
alike, havingobject-fit:contain
is really only relevant when the original dimensions are unknown. Otherwise, this is currently resulting in overridingobject-fit
on any processed image. This behavior is retained foramp-img
/amp-anim
for now, but when nativeimg
are enabled we'll only apply it to images with unknown size dimensions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is especially important to retain for
amp-img
/amp-anim
specifically since these custom elements lack intrinsic object sizing in the browser, meaning that if the element hasdisplay:block
the image could end up getting stretched.