[wp-hackers] hooking into the media uploader

Lionel Pointet lionel.pointet at globalis-ms.com
Fri Aug 10 09:13:49 UTC 2012

Hello Steffen,

When hooking on "add_attachment, delete_attachment and edit_attachment", 
you get an argument which is the post ID (an attachment is a post 
actually) needed to retrieve the file URL or path for example (with 
get_attached_file function).

    function sample_function($post_id) {
         $path = get_attached_file($post_id);
    add_action('delete_attachment', 'sample_function');

You don't need anything else imho.


Le 10/08/2012 10:34, ssokm at ofir.dk a écrit :
> Hello wp-hackers,
> I am working on a solution where I would like to synchronize my 
> wordpress media-library with a medialibrary on a external server, 
> without using a cron job.
> What I am looking for is some kind of hook that I can hook into and a 
> my script that copies the media item to a new server. Same goes for 
> deleting and editing.
> I think i could use "add_attachment, delete_attachment and 
> edit_attachment", but i cant seem to get the current attachment item.
> Have any of you worked with those hooks, or something similar, that 
> could elaborate on how to work with it? Or maybe im thinking this all 
> wrong and you have a better idea? :)
> Thanks in advance
> Steffen Mortensen
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list