@@ -53,16 +53,17 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer {
5353 protected static $ theme_features = array (
5454 // Twenty Nineteen.
5555 'twentynineteen ' => array (
56- 'dequeue_scripts ' => array (
56+ 'dequeue_scripts ' => array (
5757 'twentynineteen-skip-link-focus-fix ' , // This is part of AMP. See <https://github.com/ampproject/amphtml/issues/18671>.
5858 'twentynineteen-priority-menu ' ,
5959 'twentynineteen-touch-navigation ' , // @todo There could be an AMP implementation of this, similar to what is implemented on ampproject.org.
6060 ),
61- 'remove_actions ' => array (
61+ 'remove_actions ' => array (
6262 'wp_print_footer_scripts ' => array (
6363 'twentynineteen_skip_link_focus_fix ' , // See <https://github.com/WordPress/twentynineteen/pull/47>.
6464 ),
6565 ),
66+ 'add_twentynineteen_masthead_styles ' => array (),
6667 ),
6768
6869 // Twenty Seventeen.
@@ -526,6 +527,52 @@ protected static function get_twentyseventeen_navigation_outer_height() {
526527 return 72 ;
527528 }
528529
530+ /**
531+ * Add required styles for featured image header in Twenty Nineteen.
532+ *
533+ * The following is necessary because the styles in the theme apply to the featured img,
534+ * and the CSS parser will then convert the selectors to amp-img. Nevertheless, object-fit
535+ * does not apply on amp-img and it needs to apply on an actual img.
536+ *
537+ * @link https://github.com/WordPress/wordpress-develop/blob/5.0/src/wp-content/themes/twentynineteen/style.css#L2276-L2299
538+ * @since 1.0
539+ */
540+ public static function add_twentynineteen_masthead_styles () {
541+ add_action ( 'wp_enqueue_scripts ' , function () {
542+ ob_start ();
543+ ?>
544+ <style>
545+ .site-header.featured-image .site-featured-image .post-thumbnail amp-img > img {
546+ height: auto;
547+ left: 50%;
548+ max-width: 1000%;
549+ min-height: 100%;
550+ min-width: 100vw;
551+ position: absolute;
552+ top: 50%;
553+ transform: translateX(-50%) translateY(-50%);
554+ width: auto;
555+ z-index: 1;
556+ /* When image filters are active, make it grayscale to colorize it blue. */
557+ }
558+
559+ @supports (object-fit: cover) {
560+ .site-header.featured-image .site-featured-image .post-thumbnail amp-img > img {
561+ height: 100%;
562+ left: 0;
563+ object-fit: cover;
564+ top: 0;
565+ transform: none;
566+ width: 100%;
567+ }
568+ }
569+ </style>
570+ <?php
571+ $ styles = str_replace ( array ( '<style> ' , '</style> ' ), '' , ob_get_clean () );
572+ wp_add_inline_style ( get_template () . '-style ' , $ styles );
573+ }, 11 );
574+ }
575+
529576 /**
530577 * Add required styles for video and image headers.
531578 *
0 commit comments