Support » Developing with WordPress » async_upload filter

  • [ Moderator note: moved to Developing With WordPress. ]

    I’ve written some code that uses AJAX to call async-upload.php to upload multiple files. It all works well until I add form data variable ‘type’=’file’ to the AJAX call which results in the filter apply_filters( "async_upload_{$type}", $id ); being called.

    When this is called the response is no longer an attachment ID but rather a Attachment Details form. This is my function for the filter, simply just returning the attachment ID with no changes.

    function filter_async_upload_file( $attachment_id ) { 
        return $attachment_id; 
    };
    
    add_filter( 'async_upload_file', 'filter_async_upload_file', 10, 1 ); 

    What am I doing wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,
    Please try to use this code:-

    function filter_async_upload_file( $get_media_item, $int, $int ) { 
        // make filter magic happen here... 
        return $get_media_item; 
    }; 
             
    // add the filter 
    add_filter( 'async_upload_file', 'filter_async_upload_file', 10, 3 ); 

    Thanks
    Mohammad

    IF you look at the source code it only has one parameter which is the attachment id. You have specified 3 parameters.

    apply_filters( "async_upload_{$type}", $id );

    Hi,
    Is your code working perfect? Have you tried my code?
    Thanks
    Mohammad

    Read my last comment your code is incorrect.

    Hi,
    Please share the code async-upload.php file through pastebin.com. What result are you getting? Can you please show me?
    Thanks
    Mohammad

    “async-upload.php” is a core WordPress file you can view it in the source.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘async_upload filter’ is closed to new replies.