#55786 closed defect (bug) (fixed)
Thickbox gallery does not recognize webp images
Reported by: | ilunabar | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | 5.9.3 |
Component: | External Libraries | Keywords: | good-first-bug has-patch add-to-field-guide |
Focuses: | javascript | Cc: |
Description (last modified by )
-- The line of code 79 of /wp-includes/js/thickbox/thickbox.js is:
var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
-- It should be something like this:
var urlString = /\.webp|\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
The line of code 82 of /wp-includes/js/thickbox/thickbox.js is:
if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
-- It should be something like this:
if(urlType == '.webp' || urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
I hope this will help.
Change History (12)
#1
@
3 years ago
- Component changed from General to External Libraries
- Description modified (diff)
- Keywords needs-patch good-first-bug added; has-patch removed
This ticket was mentioned in PR #2748 on WordPress/wordpress-develop by graham73may.
3 years ago
#2
- Keywords has-patch added; needs-patch removed
Applied the code changes suggested in the Trac ticket to enable thickbox.js .webp support.
Trac ticket: https://core.trac.wordpress.org/ticket/55786
# To Replicate
- Thickbox enqueued in TwentyTwentyTwo using:
{{{php
function include_thickbox_scripts() {
include the javascript
wp_enqueue_script('thickbox', NULL, jquery?);
include the thickbox styles
wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', NULL, '1.0');
}
add_action('wp_enqueue_scripts', 'include_thickbox_scripts');
}}}
- Upload a test image to the media library
fallback-default.webp.zip
(.zip because github issues don't support .webp!)
- Test code added to any template for the purpose of replicating the issue:
{{{html
<a class="thickbox" href="/wp-content/uploads/2022/05/fallback-default.webp" title="Image 1">
<img alt="Image 1" src="/wp-content/uploads/2022/05/fallback-default.webp"/>
</a>
}}}
# Result before patch
Clicking on a .webp test image produces this result:
# Result after patch
#5
follow-up:
↓ 6
@
3 years ago
- Keywords needs-testing removed
Hi there!
PR working fine for me in the 6.1-alpha-53449 version.
Small concern regarding changes. For consistency of image format can we add $
in webp format also?
var urlString = /\.webp|\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
Should be
var urlString = /\.webp$|\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
#7
@
3 years ago
Thanks for the update.
It looks good to me now. Let's wait for 2nd review on this if anyone finds any issue otherwise, it will marge in the core soon.
Ping @SergeyBiryukov for review.
#9
@
3 years ago
This looks good to me too.
For reference, thickbox.js
is an "adopted" library, which means it's no longer supported upstream and can be safely patched in core. Looking at the commit history, it has already been patched multiple times over the years.
SergeyBiryukov commented on PR #2748:
3 years ago
#11
Thanks for the PR! Merged in https://core.trac.wordpress.org/changeset/53451.
Hi and welcome to Trac! Thanks for the report.
The patch will need to edit the thickbox.js file in the
js/_enqueues
directory.