[wp-hackers] file uploading: maybe worth add a hook?

Jennifer Hodgdon yahgrp at poplarware.com
Wed Feb 21 15:01:01 GMT 2007

Pixline wrote (in part):
> I'm writing some plugins that play around the upload features, my first 
> release is Upload+ [1] which actually have to remove a default action 
> and switch to a clone of the entire wp_upload_tab_upload_action function 
> [2] just to add a unique_filename_callback entry in the $override array 
> before wp_handle_upload (line 117 in my plugin code [1], line 208 in 
> upload-functions.php [3]). With a new hook, my plugin would be 60 lines 
> long, not 180, and more future-proof :-) [...]
> Someone suggested me to submit a patch, but actually I don't know how to 
> add hooks in the core (will learn as soon as I find documentation about 
> it). I think that would be useful add one or two hooks, like one on the 
> $overrides array [3] 

To illustrate how to add hooks to the core, here is what I think you 
are suggesting. Between these two lines of wp_upload_tab_upload_action:

    $overrides = array('action'=>'upload');

    $file = wp_handle_upload($_FILES['image'], $overrides);

add a line like this:

    $overrides = apply_filters( 'upload_overrides', $overrides );

This will allow your plugin to add something to the $overrides array, 
before wp_handle_upload is called. The name of the new filter will be 
"upload_overrides", and your plugin can use add_filter( 
"upload_overrides", "new_plugin_function_name" ) to cause it to happen.

Sounds like a good idea to me! :)


More information about the wp-hackers mailing list