Lot of users request the ability to customize the upload path of WordPress File Upload plugin.
This article describes how we can change the upload path according to our needs. In the following example we have selected the uploaded files to be added in Media folder of our website (medialink attribute set to “true”). When medialink is true, the plugin ignores the path set in uploadpath attribute and uses the default upload folder of WordPress. We will change the upload path to be inside the default upload folder, however files will go to subdirectories based on the username of the user who makes the upload.
To do that we need to install Code Snippets, a 3rd party plugin to assist us implement some filters and actions of WordPress File Upload plugin and also assign to the plugin specific settings. Here are the steps:
1. Install Code Snippets
2. Go to your Dashboard, in Snippets Tab and create a new code snippet.
3. Give it a name, whatever you like. Paste the following code inside Code textbox of your snippet.
4. Leave all other options are they are and press “Save Changes and Activate”.
5. In WordPress File Upload plugin and using the Shortcode Composer go to Interoperability Tab and enable “Add Uploaded Files To Media”. Alternatively, you can just add the following code inside your shortcode: medialink=”true”.
6. We are ready to go. When a logged user uploads a file (image), the file will be added to the Media folder of your website. The upload path of the file will be “/wp-content/uploads/%username%” where %username% is the username of the logged user.
This is just a small example of what can be done using the filters and actions of the plugin. You can customize the above code, to generate your own upload directories. You can even modify the name of the uploaded file.
It is noted that the above code is executed after all the native checks of the plugin. This means that if the upload directory or the filename are invalid, the plugin will not be able to detect it (it will just reject the upload without specific error). You need to implement your own checks inside the code, to make sure that the file path is valid.
For any questions or asiistance please contact the Iptanus team.