-
Notifications
You must be signed in to change notification settings - Fork 107
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
Fix Lightbox trigger BUTTON visibility issue on an Image lightbox when Picture Element is enabled #1814
Fix Lightbox trigger BUTTON visibility issue on an Image lightbox when Picture Element is enabled #1814
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1814 +/- ##
==========================================
- Coverage 59.58% 59.53% -0.05%
==========================================
Files 84 84
Lines 6522 6527 +5
==========================================
Hits 3886 3886
- Misses 2636 2641 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
function webp_make_lightbox_trigger_button_visible() { | ||
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { | ||
echo '<style> | ||
.wp-lightbox-container > :hover { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're specifically targeting the Picture element here, might as well make this specific to PICTURE
. More importantly, this is missing the next-child + button
selector:
.wp-lightbox-container > :hover { | |
.wp-lightbox-container picture:hover + button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used .wp-lightbox-container > picture + button
as adding :hover
to picture was not applying the CSS when tested. Let me know it the updated one looks good.
*/ | ||
function webp_make_lightbox_trigger_button_visible() { | ||
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { | ||
echo '<style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can rather be all put on one line.
* @since 2.4.0 | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version we'll supply when creating the release:
* @since 2.4.0 | |
* | |
* @since n.e.x.t |
* @since 2.4.0 | ||
* | ||
*/ | ||
function webp_make_lightbox_trigger_button_visible() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function webp_make_lightbox_trigger_button_visible() { | |
function webp_make_lightbox_trigger_button_visible(): void { |
</style>'; | ||
} | ||
} | ||
add_action( 'wp_footer', 'webp_make_lightbox_trigger_button_visible' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This action should be added conditionally based on whether the picture element is enabled (which we can detect via webp_uploads_is_picture_element_enabled()
). See also:
performance/plugins/webp-uploads/hooks.php
Lines 725 to 728 in 53c410a
function webp_uploads_init(): void { | |
add_filter( 'wp_content_img_tag', webp_uploads_is_picture_element_enabled() ? 'webp_uploads_wrap_image_in_picture' : 'webp_uploads_filter_image_tag', 10, 3 ); | |
} | |
add_action( 'init', 'webp_uploads_init' ); |
echo '<style> | ||
.wp-lightbox-container > :hover { | ||
opacity: 1; | ||
} | ||
</style>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better all on one line:
echo '<style> | |
.wp-lightbox-container > :hover { | |
opacity: 1; | |
} | |
</style>'; | |
echo '<style>.wp-lightbox-container picture:hover + button { opacity: 1 } </style>'; |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @SohamPatel46, this looks on the right track. Two small points of feedback.
/** | ||
* Add an action to wp_footer conditionally for lighbox trigger button visibility. | ||
* | ||
* @since n.e.x.t | ||
*/ | ||
function webp_add_footer_action_for_lightbox_button_visibility(): void { | ||
if ( webp_uploads_is_picture_element_enabled() ) { | ||
add_action( 'wp_footer', 'webp_make_lightbox_trigger_button_visible' ); | ||
} | ||
} | ||
add_action( 'init', 'webp_add_footer_action_for_lightbox_button_visibility' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need two functions for this? I think it would be fine to unconditionally add the webp_make_lightbox_trigger_button_visible()
function to wp_footer
, and simply inside of it include an early return if ! webp_uploads_is_picture_element_enabled()
.
A related question is: Should this be in wp_footer
or wp_head
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For classic themes this needs to be in wp_footer
as otherwise we won't know if there is an Image block using a lightbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, let's stick with wp_footer
then. My other feedback is still applicable I think.
* @since n.e.x.t | ||
*/ | ||
function webp_make_lightbox_trigger_button_visible(): void { | ||
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the code linting failures, see https://github.com/WordPress/performance/actions/runs/12910976968/job/36002299388?pr=1814.
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { | |
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) === false ) { |
*/ | ||
function webp_make_lightbox_trigger_button_visible(): void { | ||
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { | ||
echo '<style> .wp-lightbox-container > picture + button { opacity: 1 } </style>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the :hover
doesn't this mean it will always be shown?
* @since n.e.x.t | ||
*/ | ||
function webp_make_lightbox_trigger_button_visible(): void { | ||
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why, but the has_filter()
check isn't working. This does though:
if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) { | |
if ( false !== has_action( 'wp_footer', 'block_core_image_print_lightbox_overlay' ) ) { |
I'm seeing something problematic with the Interactivity API logic here. It's adding some inline styles to the right: -629px;
top: -405px; When Picture Element is not enabled, it's adding this style instead: right: 16px;
top: 16px; The culprit is --- a/plugins/webp-uploads/picture-element.php
+++ b/plugins/webp-uploads/picture-element.php
@@ -162,7 +162,7 @@ function webp_uploads_wrap_image_in_picture( string $image, string $context, int
}
return sprintf(
- '<picture class="%s" style="display: contents;">%s%s</picture>',
+ '<picture class="%s" style="/*display: contents;*/">%s%s</picture>',
esc_attr( 'wp-picture-' . $attachment_id ),
$picture_sources,
$image
@@ -175,8 +175,8 @@ function webp_uploads_wrap_image_in_picture( string $image, string $context, int
* @since n.e.x.t
*/
function webp_make_lightbox_trigger_button_visible(): void {
- if ( has_filter( 'render_block_core/image', 'block_core_image_render_lightbox' ) ) {
- echo '<style> .wp-lightbox-container > picture + button { opacity: 1 } </style>';
+ if ( false !== has_action( 'wp_footer', 'block_core_image_print_lightbox_overlay' ) ) {
+ echo '<style> .wp-lightbox-container > picture:hover + button { opacity: 1 } </style>';
}
} I was not aware that the Image block was manually placing the button: https://github.com/WordPress/gutenberg/blob/b771bddb91ad74a7a03ee21b1ef311117efd815c/packages/block-library/src/image/view.js#L404-L438 And the addition of But Given all this, it doesn't seem like there is a quick fix which we can apply from our side. |
Thank you for being willing to tackle this! |
Summary
Fixes #1805
Relevant technical choices
render_block_core/image
to detect the above conditions. Ref.