Make WordPress Core

Opened 18 months ago

Last modified 18 months ago

#50089 new enhancement

Allow filtering of image uploads

Reported by: malthert Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Media Keywords: has-patch
Focuses: Cc:


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:


echo wp_json_encode( array(
        'success' => true,
        'data'    => $attachment,
) );


$response = array(
    'success' => true,
    'data'    => $attachment,
$response = apply_filters( 'filter_ajax_upload_attachment_response', $response );

echo wp_json_encode( $response );

Change History (2)

#1 @SergeyBiryukov
18 months ago

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Just noting there are some existing hooks called when uploading a new image:

#2 @malthert
18 months 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.