[wp-trac] [WordPress Trac] #43751: Attachments controller should respect "Max upload file size" and "Site upload space" in multisite

WordPress Trac noreply at wordpress.org
Fri Apr 13 12:22:11 UTC 2018


#43751: Attachments controller should respect "Max upload file size" and "Site
upload space" in multisite
--------------------------------------+----------------------------------
 Reporter:  danielbachhuber           |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  5.0
Component:  Media                     |     Version:  4.7
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  multisite, rest-api
--------------------------------------+----------------------------------
Changes (by flixos90):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests


Comment:

 Working on this was quite terrible, but at least I was able to figure out
 the sources of the issue, and [attachment:43751.diff] is "working".
 Thoughts:

 * The logic to check both these things with an upload is in
 `check_upload_size()`.
 * This function is hooked into `wp_handle_upload_prefilter`, but not into
 `wp_handle_sideload_prefilter`. That is one problem, because depending on
 how you upload the file via the REST API, it may use the latter.
 * Related to that, in unit tests, we need to hook the function into yet
 another filter, `wp_handle_mock_upload_filter` because the REST API uses
 that with tests and `$_FILES` leveraged.
 * The worst part about all of this (and the second problem) is that
 `check_upload_size()` has a terrible condition that it may just `wp_die()`
 under certain circumstances. I added the condition of a `REST_REQUEST` in
 there, so that it no longer dies during a REST API request. However, since
 that constant cannot be set during tests, I included a hack for unit tests
 in the `WP_REST_Attachments_Controller` that set `$_POST['html-upload']`,
 just so that it doesn't die. I'd love for this to not be necessary,
 therefore I vote for reopening #42061 and introducing that function, if
 only for the sake of unit tests. If that gets available, this hack would
 no longer be necessary.

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


More information about the wp-trac mailing list