Upload file to remote storage

Two options:

  1. Hook into 'wp_handle_upload', a filter provided by the function wp_handle_upload() in wp-admin/includes/file.php:

    apply_filters( 
        'wp_handle_upload', 
        array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' 
    )
    

    Replace the new file URI with your remote URI.

  2. The function wp_insert_attachment() in wp-includes/post.php offers two actions:

    do_action('edit_attachment', $post_ID);
    do_action('add_attachment', $post_ID);
    

    You can get the attachment data by $post_ID and change any value here.

Leave a Comment