Posted By

ksantoshp on 11/26/09


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vintagekrug


Wordpress upload for plugin


 / Published in: PHP
 

URL: http://yoast.com/articles/

(Ref: http://yoast.com)

While preparing my previous post on new features in WordPress 2.9, I ran across a ticket in Trac for something I'd been wanting to do for a while: specify a subfolder of the uploads directory for specific plugins, like my Blog Icons plugin, to upload their files to. This way, the blog icons plugin would upload its files to /uploads/blog-icons/, which is a lot better for everyone.

  1. add_filter('upload_dir', 'my_upload_dir');
  2. $upload = wp_upload_dir();
  3. remove_filter('upload_dir', 'my_upload_dir');
  4. function my_upload_dir($upload) {
  5. $upload['subdir'] = '/sub-dir-to-use' . $upload['subdir'];
  6. $upload['path'] = $upload['basedir'] . $upload['subdir'];
  7. $upload['url'] = $upload['baseurl'] . $upload['subdir'];
  8. return $upload;
  9. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: fris on November 26, 2009

this is an exact copy of yoast's blog post, you should mention that

You need to login to post a comment.