• ccruapa

    (@ccruapa)


    Users in my web page are created with the role “subscriptors”, so they are not author or above.

    They can register themselves in the web and edit their own profile.
    I included this code to allow them upload their own avatar:
    <?php echo do_action(‘edit_user_avatar’, $current_user); ?>

    And so far, they can choose the image they want but the ‘Upload’ button is doing nothing.
    (class-wp-user-avatar.php)

    The code works perfectly fine if i change the user role to Author, but not as subscriber.
    They can do it properly via the wordpress profile editor, but not via my front page.

    Any ideas to solve it?
    Thanks in advanced!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi ccruapa

    You might need to grant your subscribers some extra capabilities in order to let them upload stuff to your server using the WP media uploader.

    You can do this by installing a plugin to allow you change subscribers capabilities.

    I recommend you to search for Members, by Justin Tadlock. It is in WP repository and will let you change the capabilities of subscribers.

    You’ll need to grant the following capabilities:

    upload_files
    edit_posts

    Maybe you’ll need some more from the posts side, like delete_posts, delete_published_posts and some more.

    Remember that by doing so, you should work around some coding to disallow your subscribers from accessing the dashboard and thereby editing the posts for real.

    I have the same issue: the avatar upload button doesn’t work for subscribers, but only for authors and up. I could change roles to authors, except I don’t want to grant access to the media library. I have also tried to add_cap(‘upload_files’) to the subscriber role, but that doesn’t work either. I will continue to try adding more caps per your recommendation, but I’m not sure why adding editing posts, etc would affect just this media upload issue, and again, I don’t want to allow subscribers to see the media library.

    here’s code I’m using, still not working.

    function add_theme_caps() {
    $subscriber = get_role( ‘subscriber’ ); // I also tried ‘Subscriber’
    $caps = array( ‘upload_files’, ‘edit_posts’, ‘edit_published_posts’, ‘delete_posts’, ‘delete_published_posts’, ‘publish_posts’ );
    foreach( $caps as $cap ) {
    $subscriber->add_cap( $cap );
    }
    }

    add_action( ‘admin_init’, ‘add_theme_caps’);

    ok, I got it to work by changing this: add_action( ‘admin_init’, ‘add_theme_caps’);

    to

    add_action( ‘init’, ‘add_theme_caps’);

    I also only needed to add the one ‘upload_files’ cap; however, now subscribers have access to the media library which is not what I want.

    ok, this worked for me: https://wpsnipp.com/index.php/functions-php/restricting-users-to-view-only-media-library-items-they-upload/

    – this allows the current user to only see photos they have uploaded to the media library.

    there are also ways to hid the library entirely if you google it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Subscriptors can’t upload an image’ is closed to new replies.