As of USP Pro version 2.2.1, it is possible to display the “Add Media” button on the front-end for all logged-in users. Displaying this button on the front-end enables the user to upload files and media via WordPress’ drag-n-drop interface, just like in the WP Admin Area. This quick tutorial explains the required steps to make it happen.
Default WP Functionality
Before explaining how to enable this feature, it is important to understand how WordPress works by default:
As of WordPress 4.5, only Authors, Editors, and Admins are allowed to upload files via the “Add Media” feature, regardless of whether the user is on the backend or frontend.
Security is the main reason for limiting which users are allowed to upload media. The idea is that you don’t want to give untrusted users full access to WP’s media-upload functionality. Personally I think this is a good idea, but you may have sufficient reason to allow all logged-in users to upload files via the frontend. Continue reading to learn how it’s done..
Enable “Add Media” for lesser user roles
Important: read the notes at the end of this tutorial before making any changes to your site.
To enable all logged-in user roles (i.e., Admin, Editor, Author, Contributor, and Subscriber) to upload files via the “Add Media” button:
- Add/enable the “richtext” attribute to your content shortcode, like so:
[usp_content richtext="true"]
- In the Advanced settings, visit Post Formatting and add the following tags:
img, a
- In the Uploads settings, enable “Non-Admin Media”
- Remember to save all changes and done
Note: you may need to refresh the page that displays your form once or twice in order for the new user capabilities to fully take effect.
Related Action & Filter Hooks
Developers can use the following hooks to customize default functionality as desired:
Filters
usp_allow_media_caps
usp_allow_media_role
Actions
usp_allow_media_caps
usp_allow_media_role
View the source code for more information; the target function usp_custom_enable_frontend_media()
is located in /inc/usp-forms.php
.
Notes
1) Enabling the setting “Non-Admin Media” adds advanced media capabilities to Subscriber and Contributor roles. These capabilities are not removed when the setting “Non-Admin Media” is disabled. So be absolutely sure that you want to allow all logged-in users to upload files before enabling this feature. The next note explains how to revert back to the default capabilities if you change your mind.
2) If you have enabled the setting “Non-Admin Media”, and then later change your mind, you can revert your user capabilities back to their default values by using a plugin such as this (via the “Reset Roles” feature) or this (via the “Restore Role” feature).
3) If you do enable “Add Media” for all users, you may also want to install a plugin that restricts media files to only the current user. That way, the current user can’t select files from the Media Library that belong to other users. Here is a plugin that does a good job of this, very simple and effective.
4) Files uploaded via the “Add Media” button are inserted into the Media Library, but are not attached as Custom Fields to the submitted post. Thus, if you need the file URL attached as a Custom Field, you will need to use the File(s) upload field.
5) If you are using the free version of USP, you can enable non-admins to upload media by using a plugin such as User Role Editor. You want to allow the following capabilities for your specific user role:
edit_others_pages
edit_published_pages