Skip to content

Commit

Permalink
Move the enqueued stylesheet into a callback for 'wp_print_styles'
Browse files Browse the repository at this point in the history
As Weston mentioned, it's not necessary to enqueue a stylesheet
that only has one rule.
So output it in a callback for 'wp_print_styles'
  • Loading branch information
kienstra committed Nov 20, 2018
1 parent 443bd9b commit 6b7d305
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
9 changes: 0 additions & 9 deletions assets/css/amp-gallery-block.css

This file was deleted.

26 changes: 15 additions & 11 deletions includes/embeds/class-amp-gallery-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler {
*/
public function register_embed() {
add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
}

/**
Expand Down Expand Up @@ -236,19 +236,23 @@ public function render( $args ) {
}

/**
* Enqueues the Gallery block styling.
* Prints the Gallery block styling.
*
* It would be better to enqueue this in AMP_Gallery_Block_Sanitizer,
* but by the time that runs, it's too late to call wp_enqueue_style().
* It would be better to print this in AMP_Gallery_Block_Sanitizer,
* but by the time that runs, it's too late.
* This rule is copied exactly from block-library/style.css, but the selector here has amp-img >.
* The image sanitizer normally converts the <img> from that original stylesheet <amp-img>,
* but that doesn't have the same effect as applying it to the <img>.
*
* @return void
*/
public function enqueue_styles() {
wp_enqueue_style(
'amp-gallery-block',
amp_get_asset_url( 'css/amp-gallery-block.css' ),
array(),
AMP__VERSION
);
public function print_styles() {
?>
<style>
.wp-block-gallery.is-cropped .blocks-gallery-item amp-img > img {
object-fit: cover;
}
</style>
<?php
}
}

0 comments on commit 6b7d305

Please sign in to comment.