humanmade / humanmade/asset-manager-framework
Support for uploads
- Dominant language
- PHP
- Stars
- 188
- Forks
- 6
- Avg merge
- 6d 21h
- Merged PRs (30d)
- 1
Description
Related to #13, if a provider allows users to upload files then AMF should provide the necessary integration with WordPress in order to override file uploads and pass them onto the provider. Then the provider only needs to be responsible for handling the upload of the file and returning relevant information about it.
This is of particular interest to [AMF WordPress](https://github.com/humanmade/amf-wordpress/).
Some work has been done on this already, this is the tracking ticket for moving it into AMF.
## Considerations
### Authentication
* Needs to be handled by the provider, as always
* For AMF-WP specifically, the provider could pass on the client's authentication cookies to the remote site, this would work on a Multisite installation but not elsewhere. Alternatively, there would need to be a mechanism for per-user authentication to the remote site via OAuth, JWTs, application passwords, Basic Auth, etc.
### File handling
Most likely AMF will need to override the default handling of file upload entry points and pass the appropriate `$_FILES` values onto the provider.
Entry points:
* `async-upload.php` with `action=upload-attachment`
- Called when uploading via the media manager
- Note: ACF, CMB2, and Fieldmanager all use the media manager for uploads
- Calls `wp_ajax_upload_attachment()` which calls `media_handle_upload()`
* `async-upload.php` without an `action`
- Called when uploading via the Media admin screen
- Calls `media_handle_upload()`
* `wp-json/wp/v2/media`
- Called when uploading (or dragging and dropping) directly into a block in the block editor
- Called by anything uploading via the REST API
- Calls `wp_handle_sideload()`
* `media-new.php`
- Used by the fallback "browser uploader" (`media-new.php?browser-uploader`)
- Calls `media_handle_upload()`
* `xmlrpc.php`
- TBD
Legacy entry points that almost certainly won't be supported:
* `Custom_Background::handle_upload()`
* `Custom_Image_Header::step_2_manage_upload()`
* `media-upload.php`
Functions:
* `wp_ajax_upload_attachment()`
- Called via `admin-ajax.php`
* `media_handle_upload()`
- Calls `wp_handle_upload()`
- Calls `_wp_handle_upload()`
- Creates an attachment
* `media_handle_sideload()`
- Calls `wp_handle_sideload()`
- Calls `_wp_handle_upload()`
- Creates an attachment
### Error handling
WP core does expose error messages returned by the uploader during the upload process, no issues there AFAIK
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.