Skip to content

Commit

Permalink
Merge pull request #4297 from Codeinwp/bugfix/4260
Browse files Browse the repository at this point in the history
Fixed lightbox issue with alignment control
  • Loading branch information
vytisbulkevicius authored Oct 28, 2024
2 parents 1da5560 + 9afa3f4 commit cd84333
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 0 additions & 1 deletion assets/scss/components/main/_gutenberg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ blockquote {
margin-right: calc(50% - 35vw);
}
}

30 changes: 30 additions & 0 deletions inc/views/template_parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Template_Parts extends Base_View {
public function init() {
add_action( 'wp_enqueue_scripts', array( $this, 'add_featured_post_style' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'add_vertical_spacing_style' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'add_lightbox_style' ) );
add_action( 'neve_do_featured_post', array( $this, 'render_featured_post' ) );
add_action( 'neve_blog_post_template_part_content', array( $this, 'render_post' ) );
add_filter( 'excerpt_more', array( $this, 'link_excerpt_more' ) );
Expand Down Expand Up @@ -559,4 +560,33 @@ public function get_ordered_components( $associative = false ) {

return json_decode( get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default_ordered_components ) ), $associative );
}

/**
* Add inline lightbox style if the post content includes an image block with lightbox.
*/
public function add_lightbox_style() {
global $post;
if ( ! has_block( 'core/image', $post ) ) {
return;
}
$blocks = parse_blocks( $post->post_content );
$blocks = array_filter(
$blocks,
function( $block ) {
return 'core/image' === $block['blockName'] && ! empty( $block['attrs']['lightbox']['enabled'] );
}
);
if ( empty( $blocks ) ) {
return;
}
$inline_style = '
.wp-lightbox-overlay figure img {
height: var(--wp--lightbox-image-height);
min-height: var(--wp--lightbox-image-height);
min-width: var(--wp--lightbox-image-width);
width: var(--wp--lightbox-image-width);
}
';
wp_add_inline_style( 'neve-style', Dynamic_Css::minify_css( $inline_style ) );
}
}

0 comments on commit cd84333

Please sign in to comment.