This isn’t a working example but should help,
Use wp_upload_dir() to define the default uploads folder and append a username to it using wp_get_current_user.
$wp_upload_dir = wp_upload_dir();
$user_folder = wp_get_current_user();
// The actual folder
$custom_upload_folder= $wp_upload_dir['basedir'] . $user_folder->display_name;
//make the dir
mkdir($custom_upload_folder);
You would need to employ security and code that checks for errors/user capabilities and sets the correct file/folder permissions. Also have a look at https://codex.wordpress.org/Filesystem_API which employs mkdir.
Related Posts:
- Include WP_Query in my own PHP file?
- When to use Exceptions vs Error Objects vs just plain false/null
- How to use update and delete query in wordpress
- add_meta_boxes action with refresh on save
- simple wordpress ajax plugin not working when not logged in
- Saving metabox repeatable fields
- Resize Image without cropping
- how to create and show sessions in word press?
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- When is is_admin() available?
- do not show web page section when using advanced custom fields pro
- How to get all existing post types
- Hiding WordPress Plugin Source Code
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- wp_loaded hook block script enquequing
- Custom filter in admin edit custom post type responding with invalid post type?
- How to find error in my code when the error message is pointing to WP core file?
- How to access global variable $menu inside a class function
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Custom user login page by creating a plugin
- Singelton class does not work, multiple initialization on page reload
- Saving an array of dynamic repeater data as post_meta
- How to upload a file to a folder named after the user_id via plugin
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- Improve page speed loading using CDN and async or defer attribute
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- adjust section according to country?
- Store a default value for a transient on plugin activation
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- WordPress Custom field Colors
- how to update and display an option without reloading the page
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Plugin Generate Unexpected output during activation
- WordPress Environment: Dynamic Page using shortcode – how to change the page name for sharing
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Undefined method class::construct() when creating a plugin
- Hook called before text widget save
- zip unzip attachments in wordpress
- wpdb prepare insert table doesn’t work
- wordpress admin plugin menu custom css
- how to Update 15k products on plugin activation with meta_option
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- How can I display Custom Post type Custom Columns and its Content in a Dashboard Widget?
- Adding Additional Variables on Menus Page
- custom plugin with upload files does not work
- What is the difference between Null vs Empty (Zero Length) string?
- PHP: $_SESSION destroyed after page reload for my custom session
- send popup after wp_redirect()
- no_rest_route error on custom routes
- How to correctly escape an echo
- Payment field disappears on custom Paypal plugin
- Create ACF Checkbox to get all ACF Values from Parent Page
- Creating plugin with front-end pages
- How to Send Pingbacks for all Posts in WordPress?
- I am having errors with checkout on wordpress
- File is executed twice if plugin is activating
- product_type_options get saved value [closed]
- Display a custom name when the user has no name settle in his account
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- 400 bad request admin-ajax file upload
- get Woocommerce product format json for WP_Query
- Sum All the Post Meta of Published posts of Current Logged in user
- Update user meta when an external link in admin notice is clicked
- The plugin generated 225 characters of unexpected output during activation
- Autoloading Classes in Plugins
- Ajax in a class instantiated via shortcode
- Comparing Dates within plugin using PHP If statement
- Shortcode Works for Logged in Users but Not Working for Guest
- Singleton plugin activation; create database
- See output of a sql query while plugin installation in wordpress
- Why this plugin is not working?
- Permission error on plugin save
- How to get WordPress Adminmenu items?
- Trouble using wordpress functions in a pop-up modal form
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- MySQL update text field with ‘
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- display php code in header using wp_head()
- base64_encode conflict with convert_smilies in wordpress
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Implement OAuth2 in custom plugin
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to pass and validate nonce in custom REST routes
- How to lock users account until approvation
- Variable ++ in query loop
- ajax problems on loading page [closed]
- WordPress REST API – Custom field not added to pages
- wp_mail – send emails after 24 hours from users registration
- Compare user meta values before update them
- Capture the Selected Radio Button Value between two files in wordpress theme
- Cannot register a custom WP-CLI command
- Why does WordPress not make use of gettext directly?
- Trouble with WordPress Settings API: Form Submits When Fields Called Directly, Fails When Using Callbacks
- Add Imports to Existing WordPress Import Map
- How can I catch WordPress custom settings page slug has already changed?
- Custom plugin with dynamic child pages listing database records