[wp-hackers] Uploading image attachments from the front-end

Eric Marden wp at xentek.net
Thu Nov 12 20:12:54 UTC 2009


On Nov 12, 2009, at 1:28 PM, Matthew Gerring wrote:

> I had to require /wp-admin/includes/admin.php to have access to all  
> of the functions I needed- is this the best way to do it?


No. Your upload processing code should be in a plugin so it can take  
advantage of WP API functions.
I usually hook into init:

add_action('init','upload_handler_function');

function upload_handler_function()
{
   // check for your form being submitted (via hidden field) and  
validate the nonce
   // then process the rest with the media_* api functions or whatever
}



- Eric Marden
__________________________________
http://xentek.net/code/wordpress/
tw: @xentek






More information about the wp-hackers mailing list