Opened 10 years ago
Last modified 5 years ago
#28774 new enhancement
Hooking into wp_ajax_upload_attachment
Reported by: | jshreve | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | General | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
If you want to do something before/after an attachment has been uploaded - or replace the upload function entirely -- there doesn't seem to be a way to do that:
For other wp_ajax_* calls
, you can unhook them and then hook in your own. This doesn't work for wp_ajax_upload_attachment
because it ends up getting called directly from async-upload.php.
If we replace the direct call with another set of do_action/add_action
(like admin-ajax has) you can now hook into upload like the other ajax actions.
See the proposed patch.
Attachments (1)
Change History (4)
#2
in reply to:
↑ 1
@
10 years ago
Replying to nacin:
What are you trying to do?
There are a few places where we are embedding stuff from core (like the media manager or wplink) on NewDash (WordPress.com / blog id 1) - for example in the new posting experience at WordPress.com/post/.
To embed/use the functionality outside of wp-admin we pass in a blog ID to the ajax call and unhook some of the wp_ajax_* hooks, switch_to_blog; cap check, call the wp_ajax_* function, restore_current_blog.
I don't think I ended up needing to do anything with wp_ajax_upload_attachment itself - but I think the patch is still valid (its the only wp_ajax_* action you can't touch with hooks).
I think unhooking core wp_ajax_* hooks is kind of at-your-risk. I'm not going to pretend that those are API, and I imagine we've already broken them a number of times at this point.
An action in wp_ajax_upload_attachment() could make sense, but really, there should already be hooks deeper in the process, such as in wp_handle_upload(). What are you trying to do?