#50089 closed enhancement (invalid)
Allow filtering of image uploads
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.5 |
Component: | Media | Keywords: | has-patch close |
Focuses: | Cc: |
Description
I'd like to be able to filter the response of wp_ajax_upload_attachment to add copyright and duplicate checks to prevent the upload of the image if either fails.
To do this I require an apply_filters at the end of the function.
Suggested fix for ajax-actions.php function wp_ajax_upload_attachment:
Replace:
echo wp_json_encode( array(
'success' => true,
'data' => $attachment,
) );
with:
$response = array(
'success' => true,
'data' => $attachment,
);
$response = apply_filters( 'filter_ajax_upload_attachment_response', $response );
echo wp_json_encode( $response );
Change History (4)
#2
@
5 years ago
But these are hooks and they can NOT be used to set the success to false in case the upload was cancelled by my custom code. (unless I die() in them, but this makes it really hard to debug code for other people, bc if someone hooked already & died, later hooked actions may actually never run)
Note: See
TracTickets for help on using
tickets.
Hi there, welcome back to WordPress Trac! Thanks for the ticket.
Just noting there are some existing hooks called when uploading a new image: