wpseek.com
A WordPress-centric search engine for devs and theme authors
block_core_gallery_get_responsive_aspect_ratio_style_rules › WordPress Function
Since7.1.0
Deprecatedn/a
› block_core_gallery_get_responsive_aspect_ratio_style_rules ( $selector, $viewport_style, $media_query )
| Parameters: (3) |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Returns Gallery-specific responsive aspect ratio rules for a viewport.
Unlike the column and crop rules, these are not scoped to the Flex layout: the aspect ratio applies to the images in every Gallery layout. They also cover dynamic galleries, whose images are rendered by the Gallery rather than carrying their own block attributes.Source
function block_core_gallery_get_responsive_aspect_ratio_style_rules( $selector, $viewport_style, $media_query ) {
if ( ! is_array( $viewport_style ) || ! is_string( $media_query ) ) {
return array();
}
$aspect_ratio = $viewport_style['aspectRatio'] ?? null;
if ( ! block_core_gallery_is_valid_aspect_ratio( $aspect_ratio ) ) {
return array();
}
$aspect_ratio = trim( $aspect_ratio );
/*
* The base aspect ratio is an inline style on each image, so these
* declarations have to be important to win for the viewport.
*
* Original cancels the base ratio, which means rolling the declaration out
* of the cascade rather than giving it a value. `auto` - and `initial`,
* `unset` and `revert`, which all compute to it - would override the
* `width`/`height` presentational hint that gives a lazy-loaded image its
* placeholder ratio, collapsing the image to zero height until it loads:
* the Featured Image bug fixed in #80386. `revert-layer` drops the
* declaration instead, so the image falls back to that hint while loading,
* to its natural ratio once loaded, and to any ratio a theme set in a lower
* cascade layer. `object-fit` is left as the base set it, so a cropped
* Gallery still crops.
*/
$declarations = 'auto' === $aspect_ratio
? array( 'aspect-ratio' => 'revert-layer !important' )
: array(
'aspect-ratio' => "{$aspect_ratio} !important",
'object-fit' => 'cover !important',
);
return array(
array(
'selector' => "{$selector}.wp-block-gallery.has-nested-images figure.wp-block-image:not(#individual-image) img",
'declarations' => $declarations,
'rules_group' => $media_query,
),
);
}