With credits to petermolnar via irc://freenode.net/wordpress
I can answer my own question. The key is to set an upload-dir
filter in the theme’s functions.php
:
function per_user_upload_dir( $original ){
// use the original array for initial setup
$modified = $original;
// set our own replacements
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$subdir = $current_user->user_login;
$modified['subdir'] = $subdir;
$modified['url'] = $original['baseurl'] . "https://wordpress.stackexchange.com/" . $subdir;
$modified['path'] = $original['basedir'] . DIRECTORY_SEPARATOR . $subdir;
}
return $modified;
}
add_filter( 'upload_dir', 'per_user_upload_dir');
Related Posts:
- Could a large quantity of files in the uploads folder affect performance?
- Set a maximum upload count for users on a specific user role
- How to get profile user id when uploading image via media uploader on profile page
- Saving WordPress generated thumbnails in a subdirectory
- Prevent a folder from being shown within the media library
- move_uploaded_file() not working on wordpress front end
- Move files from flat upload directory to organised by year / month
- How to allow logged out users to upload media?
- Hide images from anonymous user?
- Flat media folder vs multiple directories
- how to change wp upload directory to another domain directory
- How to share /uploads/ directory with another site on the same server?
- Anybody knows if i could upload a leaflet or openlayers3 map to wordpress webpage?
- How to change default upload dir?
- How use custom upload directories in filesystem and url based on media type or category
- Media Upload Directory to MMYY instead of YYYY/MM
- Is there a standard public URL convention used on a WordPress site directly to a page listing all of a user’s public content?
- Question regarding the file path for media_sideload_image and wp_upload_dir()
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Create image formats with different qualities when uploading
- Which filters or actions to use after a media upload and delete?
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Force WordPress 3.3 to use Flash uploader
- Protecting direct access to PDF and ZIP unless user logged in (without plugin)
- How can I speed up a slow loading media library?
- What to do with unattached logos and header uploaded via native wordpress uploader?
- upload_mimes filter has no effect
- Moving Media Library
- Using “media_handle_sideload” to upload images programmatically does not upload image to Media Library
- Convert uploaded PNG to JPEG automatically
- How to check if an image attachment exists before uploading
- Using attachment_fields_to_edit filter inside plugin class
- Incremental number handling on duplicate file names
- add ‘file upload’ field to user details
- Maximum upload size changes in php.ini ignored – How to remove upload size limit?
- Regenerate thumbnails after upload
- Media library storing files in uploads not folders within in uploads
- ACF attachment custom field in rest response
- How to delete uploads not in media library?
- How to decrease the file size upload limit?
- Why does SVG upload in Media Library fail if the file does not have an XML tag at the beginning?
- media_handle_upload : undefined function?
- Site icons with alpha channel for self-hosted WordPress blog network
- Can I stop wordpress generating media sizes
- Using subdomain to upload media/images etc on 2 different blogs
- Unable to create directory uploads/2018/12. Is its parent directory writable by the server?
- Can I upload a file to the site so that it is not accessible via an HTML page?
- Calling WP Gallery Uploader/Selector From Metabox
- Stop WordPress from generating redundant image size
- WordPress 4.9.8 Trying to add filename over image in Media Browser
- Disable image thumbnails for only one upload folder
- Get File Object from wp.Uploader
- media_handle_sideload on a file already on server
- Capability to prevent upload of files
- wp_handle_upload: get custom checkbox value from media uploader
- Edit User Profile From Front End
- How can I upload to wp media library by foundation zurb ajax
- HTTP Error When Uploading Images with HTTPS?
- Saving file to disk receiving fopen error
- Error when upload images larger than 1024px [closed]
- A link (not in the post) to download a specific PDF file
- uploaded images not going to /uploads folder
- Setting image upload absolute path?
- Correctly using the root directory for media uploads?
- Populate a custom attachment metadata field with data from the image’s EXIF data?
- Disable “Create Audio Playlist” and “Create Video Playlist” in Add Media
- Front-End User Profile
- Change file name on upload in Media Page
- What is the URL pattern for image thumbnails + sizes?
- Setting up a HIPAA secured form / file upload
- How to make picture appear on wordpress site shared link? [closed]
- limit media upload to once a day
- How to download files to WordPress?
- How to detect when a file has been uploaded?
- Cant upload larger than 100MB
- PDF Upload from Input Error
- Multiple images are generated in WP-content in wordpress
- Removing extra large generated images disables all crops
- MIME types not recognized by media library
- Missing a temporary folder not fixed
- How to allow .xls file uploads?
- Updating the attachment from front end doesn’t show the new change
- Bulk upload images in upload folder does not show in media library
- Allow users to post their videos to my wordpress website?
- wp_update_attachment_metadata breaks after 10 files
- Media URL slugs without uploads folder path
- Add more field on WordPress media upload
- Frontend media shows “An error occurred in the upload. Please try again later.”
- File Upload Management
- Can i add flickr,imgur etc. up-loader for my WP upload media button?
- Files larger than 500 kilobytes are not allowed
- All files unattached in Media Library
- WordPress media upload multiple images
- Is there a way to force Featured image to show as attachement?
- Auto-Import of WXR File
- how upload images and videos to specific folder like wp-content\uploads\folder-name
- Media upload takes too long
- Problems with defining UPLOADS constant
- Obtaining detailed error information from Media file upload process
- Is it possible to restrict the number of media uploads (photos) per user?