Hi,
Yes you’ve understood me right.
I’ve been playing with this today and think I have part of a solution – if you add this on line 631 of gravity-forms-ajax-upload.php (immediately after initialising the upload handler):
$upload_handler = apply_filters( 'itsg_gf_ajaxupload_validation', $upload_handler );
if ( $upload_handler->response['files'][0]->error ) {
@unlink( $target_path['dirname'] . $upload_handler->response['files'][0]->name );
if ( $upload_handler->response['files'][0]->thumbnailUrl ) {
@unlink( $target_path['dirname'] . '/thumbnail/' . $upload_handler->response['files'][0]->name );
}
}
This allows a filter to be used to pass in a custom error to the object returned by the UploadHandler, and if so, delete the image and thumbnail. Doing it at this stage, rather than using ‘itsg_gf_ajaxupload_post_upload’ means that it happens before the file is added to the Media Library, and importantly the error message you set is shown to the user as a javascript alert.
Example filter use:
function example_callback( $upload_handler ) {
// Run virus scan etc here
$upload_handler->response['files'][0]->error = 'Custom validation error string';
return $upload_handler;
}
add_filter( 'itsg_gf_ajaxupload_validation', 'example_callback' );
However. I haven’t yet looked at how to make the script stop processing at this point and bypass the if ( $ajax_upload_options['import_media_library'] )
function without modifying it. The simple way would be to make it if ( ! $upload_handler->response['files'][0]->error && $ajax_upload_options['import_media_library'] )
, but there may be a better way?
What do you think? For my use I could make it work if you just added the filter. Handling the file deletion through the filter in my functions.php would be a bit of a hack but fine if it wasn’t a feature you wanted to add to your plugin. But I’d appreciate any advice on bypassing the Media Library function.
I’m afraid I have no idea about Windows WebMatrix and getting ClamAV running on it. It does run on Windows – you can build it yourself of there is ClamWin or Immunet which may be able to be called by PHP the same as ClamAV on Linux. Sorry I can’t be more help!
Cheers,
Phil