Support

Account

Home Forums General Issues User Profile, Gallery Field, Limit To 'Uploaded to Post' Not Working

Solved

User Profile, Gallery Field, Limit To 'Uploaded to Post' Not Working

  • I’ve added a gallery field to user profile forms as I’d like users to be able to add/manage images associated with their profile. But I would like them to only be able to use images that they have uploaded. As it stands, using the ‘uploaded to post” limiter, this doesn’t really do anything for a user profile. Any ideas on how to work around this? Or should it just be a feature request – a user gallery field?

    Note: I did add the user capability to upload files to this user type. As long as the forms with which the user can interact are restricted, this should be a secure.

  • I kept the field as “library:all”, but filtered the media that could be seen like so (fill in your own USERTYPE):

    
    /**
     * 	Limit media access to only their own media for certain users
     */
    add_filter( 'ajax_query_attachments_args', 'mr_mp_filter_media' );
    function mr_mp_filter_media( $query ) {
        if ( current_user_can( 'USERTYPE' ) || current_user_can( 'USERTYPE2' ) ) {
            $query['author'] = get_current_user_id();
        }
        return $query;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘User Profile, Gallery Field, Limit To 'Uploaded to Post' Not Working’ is closed to new replies.