Skip to content
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

Image: Fix Lightbox display bug in Classic Themes. #54837

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,27 @@ function block_core_image_render_lightbox( $block_content, $block ) {
$q->set_attribute( 'data-wp-style--object-fit', 'selectors.core.image.lightboxObjectFit' );
$enlarged_image_content = $q->get_updated_html();

$background_color = esc_attr( wp_get_global_styles( array( 'color', 'background' ) ) );
// If the current theme does NOT have a `theme.json`, or the colors are not defined,
// we need to set the background color & close button color to some default values
// because we can't get them from the Global Styles.
$background_color = '#fff';
$close_button_color = '#000';
if ( wp_theme_has_theme_json() ) {
$global_styles_color = wp_get_global_styles( array( 'color' ) );
if ( ! empty( $global_styles_color['background'] ) ) {
$background_color = esc_attr( $global_styles_color['background'] );
}
if ( ! empty( $global_styles_color['text'] ) ) {
$close_button_color = esc_attr( $global_styles_color['text'] );
}
}
$global_styles_color = wp_get_global_styles( array( 'color' ) );
$has_background_color = ! empty( $global_styles_color['background'] );
$has_text_color = ! empty( $global_styles_color['text'] );
$background_color = esc_attr( ( wp_theme_has_theme_json() && $has_background_color ) ? $global_styles_color['background'] : '#fff' );
$close_button_color = esc_attr( ( wp_theme_has_theme_json() && $has_text_color ) ? $global_styles_color['text'] : '#000' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call wp_theme_has_theme_json() once above to avoid duplicate calls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't have a theme.json, I think you shouldn't need to call wp_get_global_styles(). Furthermore, how about an approach like below to run the wp_theme_has_theme_json() function only once?

$background_color   = '#fff';
$close_button_color = '#000';

if ( wp_theme_has_theme_json() ) {
	$global_styles_color = wp_get_global_styles( array( 'color' ) );
	if ( ! empty( $global_styles_color['background'] ) ) {
		$background_color = esc_attr( $global_styles_color['background'] );
	}
	if ( ! empty( $global_styles_color['text'] ) ) {
		$close_button_color = esc_attr( $global_styles_color['text'] );
	}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me! Thank you 🙂 I just updated the code with your suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @SantosGuillamot!

If the diff I'm checking is the latest, then the five lines here shouldn't be necessary 😄


$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';
$close_button_color = esc_attr( wp_get_global_styles( array( 'color', 'text' ) ) );
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' );
$close_button_label = esc_attr__( 'Close' );

Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
outline: 5px auto -webkit-focus-ring-color;
outline-offset: 5px;
}

&:hover,
&:focus {
background: none;
border: none;
}
}
}

Expand All @@ -191,6 +197,12 @@
padding: 0;
cursor: pointer;
z-index: 5000000;

&:hover,
&:focus {
background: none;
border: none;
}
}

.lightbox-image-container {
Expand Down
Loading