apply_filters( 'upload_dir', array $uploads )

Filters the uploads directory data.


Parameters Parameters

$uploads

(array) Array of information about the upload directory.

  • 'path'
    (string) Base directory and subdirectory or full path to upload directory.
  • 'url'
    (string) Base URL and subdirectory or absolute URL to upload directory.
  • 'subdir'
    (string) Subdirectory if uploads use year/month folders option is on.
  • 'basedir'
    (string) Path without subdir.
  • 'baseurl'
    (string) URL path without subdir.
  • 'error'
    (string|false) False or error message.


Top ↑

More Information More Information

This hook allows you to change the directory where files are uploaded to. The keys and values in the array are used by the wp_upload_dir() function in wordpress core, which is doing the work


Top ↑

Source Source

File: wp-includes/functions.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Collins Mbaka

    This goes into your plugin.

    add_filter('upload_dir', 'awesome_wallpaper_dir');
    
    function awesome_wallpaper_dir( $param ){
        $mydir = '/awesome';
    
        $param['path'] = $param['path'] . $mydir;
        $param['url'] = $param['url'] . $mydir;
    
        return $param;
    }
    

    If your plugin is written as a class, you’ll want to hook to it like this:

    add_filter( 'upload_dir', array( $this, 'awesome_wallpaper_dir' ) );
    

    Using this, in conjunction with the wp_handle_upload_prefilter, you can dynamically determine which directory to upload to, based on the files you upload.

You must log in before being able to contribute a note or feedback.