By default, WordPress Media Library (used for attachments) allows file uploads only for users who have the upload_files capability. So, everyone who doesn’t have this capability (e.g. a subscriber) will receive an error on trying to upload a file.

To add this capability to subscribers you can e.g. use the User Role Editor plugin. Just enable the upload_files capability for the users which need it and it will work.

Other option is to add this capability dynamically via a hook. To do this you can add e.g. this code to your theme’s functions.php:

            function give_permissions( $allcaps, $cap, $args ) {
                $allcaps['upload_files'] = true;
                return $allcaps;
            }
            add_filter( 'user_has_cap', 'give_permissions', 0, 3 );     

Basically, it enables the upload_files capability to everyone – but you can extend this logic to allow it only for certain users at certain moments.

Was this answer helpful ? Yes No

Comments are closed.

BUT FIRST!

Subscribe to our Newsletter

Be the first to learn about updates and new features. Once you have provided your email address, the download will commence shortly


By continuing, I accept Privacy Policy and T&C
Mail Box