• I want to run a function when something is uploaded to wordpress.

    It seems so simple but I can’t figure it out, does anyone know how I can accomplish this?
    Thankyou

Viewing 5 replies - 1 through 5 (of 5 total)
  • When what is uploaded by who?

    What function?

    Thread Starter migueldecali89

    (@migueldecali89)

    I apologize for not making my question clear.

    I want to run my own function when a wordpress author(that has access to the wp dashboard) uploads a file through the media uploader.

    I tried editing my functions.php within my theme and added:

    add_action(‘wp_handle_upload’, ‘my_own_function’);

    this seemed like it worked but it seemed to have disrupted something in the media uploader, as I can no longer upload anything (It looks like something gets uploaded but it is just blank with no file path or file name). It disrupts the uploader even if my_own_function is empty.

    I tried looking into the codex as much as I could to figure it out, everything that I have read suggests that what I am doing is right, but doesn’t work.

    Thank you.

    I am moving this to the advanced forum.

    Ben

    (@leobenkim)

    The wp_handle_upload action passes data you can modify to your function and expects the data or modified data to be returned in the same format that was passed in.

    Modify your function this way:

    function my_own_function( $data )
    {
       /**
        * $data contains array(
        *	'file' => $new_file,
        *	'url'  => $url,
        *	'type' => $type
        * )
        */
       //do your stuff within the function here
       return $data;
    }

    You can use your code like this :

    add_action('wp_handle_upload', 'uploadMyFile');
    
    function uploadMyFile(){
      /* Put your function code here*/
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I run a function when something is uploaded?’ is closed to new replies.