WordPress.org

Ready to get started?Download WordPress

Forums

Media Upload to Sharehoster (2 posts)

  1. akreuzkamp
    Member
    Posted 11 months ago #

    Hi,

    Our wordpress installation is running on a server, that has a quite slow Internet-connection.
    Because of that I'm trying to write a plugin that automatically uploads any image a user wants to insert into a blog post to a specific sharehoster and insert the image from the sharehoster instead of a local file.
    I want the user to use the normal media upload dialog of wordpress.

    Therefore I somehow need to interfere in the process of uploading and saving the image and inserting it to the blog post.
    I need to access the uploaded image and need to be able to manipulate the piece of markup-code the uploader adds to the blog post, but I have no clue how to interfere in that process. How can I achieve this?

    Thank you.

  2. bcworkz
    Member
    Posted 11 months ago #

    Hook the action 'add_attachment'. The file has been copied to your server by the time this action fires, but the size variants are not yet generated. The attachment post type has been added, as well as any meta data. You must return a WP_Error object to prevent the size variants from being created. I'm not sure what error message gets generated by doing this or how to suppress it, but there's likely a way.

    Not only will your script need to copy the image to the remote host before erasing it from your server, it will also need to update the URL to the image that was stored with the attachment post type, as well as any other related metadata.

    If you want a hook that is before all of this, use 'wp_handle_upload_prefilter'. Here you need to return array('error'=>'Image moved to remote host'); to prevent the rest from happening. Again, not sure where the error message goes or how to suppress it, but there is likely a way.

    If you hook this early, you're on your own in regards to how images are utilized, there will be no attachment or metadata unless you create them.

Reply

You must log in to post.

About this Topic