-
Notifications
You must be signed in to change notification settings - Fork 8
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.
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
withaction=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 callsmedia_handle_upload()
- Called when uploading via the media manager
async-upload.php
without anaction
- 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()
- Used by the fallback "browser uploader" (
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
- Called via
media_handle_upload()
- Calls
wp_handle_upload()
- Calls
_wp_handle_upload()
- Calls
- Creates an attachment
- Calls
media_handle_sideload()
- Calls
wp_handle_sideload()
- Calls
_wp_handle_upload()
- Calls
- Creates an attachment
- Calls
Error handling
WP core does expose error messages returned by the uploader during the upload process, no issues there AFAIK