[wp-trac] [WordPress Trac] #41801: add wp_get_image_extensions() and wp_image_extensions filter
WordPress Trac
noreply at wordpress.org
Fri Aug 21 03:27:46 UTC 2020
#41801: add wp_get_image_extensions() and wp_image_extensions filter
------------------------------------+-----------------------------
Reporter: pbiron | Owner: pbiron
Type: enhancement | Status: assigned
Priority: normal | Milestone: Future Release
Component: Media | Version: 4.9
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+-----------------------------
Comment (by gmariani405):
Hello,
I'd like to add to this ticket a suggestion on improving the functionality
here. I have a use-case where I'm trying to display a set of posts using a
custom post type in Elementor. When Elementor goes to render and the
option to display the featured image is selected, it calls
wp_attachment_is_image() on the individual post which in turn calls
wp_attachment_is('image', $post).
That is all fine and dandy, except that if the attachment is a PDF this
will fail. Which shouldn't happen (if ImageMagick is installed), because
as of 4.7, WordPress creates a thumbnail for PDFs. So technically it does
have a valid image that could be displayed.
In order to get this to work, we would need something like what @pbiron
has added, a filter to add the 'pdf' extension (or include it in core).
But we also need it to allow the post_mime_type to allow 'application/pdf'
(or the like). Because right now it fails at this part in WordPress 5.4.2:
{{{#!php
<?php
if ('import' !== $post->post_mime_type) {
return $type === $ext;
}
}}}
testing with something like this and adding 'pdf' to the list of allowed
extensions lets it to work as expected:
{{{#!php
<?php
if ('import' !== $post->post_mime_type && 'application/pdf' !==
$post->post_mime_type) {
return $type === $ext;
}
}}}
Now, not to say that should be the solution, you guys know how WordPress
functions (and should function) better than I. But if something like this
could be customizable or added to core in some fashion that would be
great.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41801#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list