[wp-trac] [WordPress Trac] #41801: add wp_get_image_extensions() and wp_image_extensions filter

WordPress Trac noreply at wordpress.org
Wed Jan 9 19:28:09 UTC 2019


#41801: add wp_get_image_extensions() and wp_image_extensions filter
------------------------------------+-----------------------
 Reporter:  pbiron                  |       Owner:  pbiron
     Type:  enhancement             |      Status:  assigned
 Priority:  normal                  |   Milestone:  5.1
Component:  Media                   |     Version:  4.9
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:
------------------------------------+-----------------------

Comment (by pbiron):

 I was going to update the patch per
 [[https://wordpress.slack.com/archives/C02SX62S6/p1546978156206900|our
 discussion yesterday on Slack]], however there is another "gotcha" with
 using the list(s) in `wp_get_ext_types()` as the "source of truth": that
 function applies the `ext2type` filter to those lists before returning.
 Hence, unless we temporarily unhook `ext2type` we're not guaranteed to get
 those lists as the defaults.

 And temporarily unhooking (and later rehooking) **every callback** for
 that hook is nasty business.  I've done the following in plugins before,
 but I'm reluctant to do it in core (would set a bad precedence):

 {{{#!php
 global $wp_filter;

 $hooked = null;
 if ( isset( $wp_filter['ext2type'] ) ) {
     $hooked = $wp_filter['ext2type'];
     unset( $wp_filter['ext2type'] );
 }

 $ext_types = wp_get_ext_types();

 if ( $hooked ) {
     $wp_filter['ext2type'] = $hooked;
 }

 ...
 }}}

 I //think// the right thing to do is the following:

 1. move the `image`, `audio` and `video` lists from `wp_get_ext_types()`
 into `wp_get_[image|audio|video]_extensions()`
 2. modify `wp_get_ext_types()` as follows:
 {{{#!php
 return apply_filters(
     'ext2type',
     array(
         'image' => wp_get_image_extensions(),
         'audio' => wp_get_audio_extensions(),
         'video' => wp_get_video_extensions(),
         ...
     )
 );
 }}}

 Given how close we are to 5.1beta (tomorrow), I think we should punt this
 to 5.2 to give us time to consider all the options.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/41801#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list