Please wait...

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.

Back to FAQs 1 0

2 responses to “How to allow my front-end users to upload attachments in front-end uploader?”

  1. CHRIS says:

    DOES THIS WORK ONLY IF I COPY THE CODE IN MY FUNCTION.PHP FILR OR I MUST DO ALSO SOMETHING ELSE

    BECAUSE I COPY IT AND STILL DONT WORK

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

  2. Jon says:

    Chris, check your single quotes to make sure they are proper single quotes. Also try changing the 0 to be a 10.

Leave a Reply

Your email address will not be published.