[wp-trac] [WordPress Trac] #21299: upload_mimes filter doesn't work occasionally

WordPress Trac wp-trac at lists.automattic.com
Tue Jul 17 19:59:19 UTC 2012


#21299: upload_mimes filter doesn't work occasionally
--------------------------+------------------------------
 Reporter:  dpacmittal    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.4.1
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by dpacmittal):

 Static variable also should not be used because it makes breaking core
 functionality very easy for a plugin developers. A developer may simply
 call the function get_allowed_mime_types() in his plugin, which might
 cause the static variable to initialize and set with default array.

 Note, at this point no filters would've been added because plugins are
 loaded even before 'init'
 (http://codex.wordpress.org/Plugin_API/Action_Reference) . So if the
 function get_allowed_mime_types() is called at this point, $mimes is
 simply set to default array without running any filters. When the filter
 is added at a later stage, it is simple ignored because $mimes is true in
 the following code:


 {{{
 function get_allowed_mime_types() {
         static $mimes = false;
         if ( !$mimes ) {
                 $mimes = apply_filters( 'upload_mimes', array(
 ...
 }}}

 Performance hit after removing static should not be much because it is not
 a very frequently called function.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21299#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list