[wp-trac] [WordPress Trac] #28878: Create a filter to customize the fileupload_maxk value

WordPress Trac noreply at wordpress.org
Sun Jul 13 18:21:05 UTC 2014


#28878: Create a filter to customize the fileupload_maxk value
-------------------------+----------------------
 Reporter:  virgodesign  |       Owner:
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  Upload       |     Version:  3.9.1
 Severity:  normal       |  Resolution:  invalid
 Keywords:               |     Focuses:
-------------------------+----------------------
Changes (by DrewAPicture):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 Hi virgodesign,

 This is currently possible in multiple ways:

 * For core upload workflows, by filtering on the
 [http://developer.wordpress.org/reference/hooks/upload_size_limit/
 upload_size_limit] hook just as core
 [http://developer.wordpress.org/reference/functions/upload_size_limit_filter/
 already does] for Multisite in wp-includes/ms-functions.php, but on a
 later priority. For example:

 {{{
 #!php
 <?php
 /**
  * Filter the upload size limit for non-administrators.
  *
  * @param string $size Upload size limit (in bytes).
  * @return int (maybe) Filtered size limit.
  */
 function filter_upload_size_limit( $size ) {
         $site = get_current_site();

         // Set the upload size limit to 10 MB for non-administrators of
 site 1.
         if ( ! current_user_can( 'manage_options' ) && 1 === $site->id ) {
                 // 10 MB.
                 $size = 1024 * 10000;
         }
         return $size;
 }
 add_filter( 'upload_size_limit', 'filter_upload_size_limit', 20 );
 }}}

 * Directly, as alluded to by @ocean90 above. For instance, filtering the
 option on the
 [http://developer.wordpress.org/reference/hooks/pre_site_option_option/
 pre_site_option_{$option}] hook (`pre_site_option_fileupload_maxk`) would
 do it, though the issue there is that the core filter,
 [http://developer.wordpress.org/reference/functions/upload_size_limit_filter/
 upload_size_limit_filter] takes the lowest of the incoming size and option
 value for core upload workflows.

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


More information about the wp-trac mailing list