Skip Navigation

[Resolved] Allow specific users to share media uploads

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2658515

Tell us what you are trying to do?
I have a directory setup.
I've created an intermediary CTP - 'Members' and each 'member' has 1 author/user
and then a many to many relationship so:
MANY 'Members" CTP can be related to MANY 'Companies' CPT

So we can have for example:
5 'Members' managing content for 1 'Company' OR
1 'Member' managing content for 5 'Companies'

or any other number of permutations between 'members' and 'companies'

However - as it is now - each 'Member' / User can only access their own media files (IE: Media files uploaded by themselves).

a) Is there any way to grant permissions so that 1 specific user can access not only their own files - but also those of another specific user?
b) And secondly - Is there a hook / way of categorising media files when they are uploaded through the Toolset create or edit forms media uploader? (So I can somehow spearate the files uploaded by this user role from the general files on the site).

Really I just want a way of saying User A can also manage the files of User B (and vice versa).
Or a custom role that says these 5 users can manage each others media files.

Is this possible in Toolset?
If not - any pointers as to where I could look for a solution?

Thanks

#2658697

Hi,

Thank you for contacting us and I'd be happy to assist.

Based on what you've shared, am I correct in assuming that these files will need to be grouped/linked by an individual company and only user attached to that particular company should be able to view and manage these files?

If that assumption is correct, you can add a 'file' type repeating custom field to the 'Company' post type. On the single company post, you can include the form to add/edit these files, so that only the user linked to the current company can access this form.

This way, you won't have to change the default user role and capabilities for the media uploads.

I hope this helps and let me know if you have any follow-up questions.

regards,
Waqar

#2658735

Thanks Waqar,
It's a bit more complicated than that.
I'm happy enough with the setup I have for many users being able to update many companies using the relationship (IE: managing posts)

The issue I have is around sharing access to files/images through the media uploader in a wysiwyg block (toolset edit form).
In the media uploader - users can either see their own files - or all of the files (which I definitely do not want).

So I'm looking for a way for that user to have access to their own files - plus 1 or more other users files.

In all honesty I don't think it's possible using toolset alone - but maybe you know of a similar instance where someone has requested a similar setup (IE: 2 or more users managing 1 directory entry (including associated files))

I feel like it's probably something you've come across before...

Second issue is how I separate these user generated/uploaded files from the rest of the files on the site (uploaded by site admins and editors)

Again - I'm not sure it's something Toolset can do in it's own but a pointer in the right direction might help speed things up for me.

Thanks

Karl

#2659105
Screenshot 2023-11-01 at 11.12.34.png

Hi again,

I'm a bit closer - allowing access to all files for a certain user role in Toolset and then using php ajax_query_attachments_args to do the limiting rather than Toolset (so I can set the attachments to show those from multiple authors).

It's working for the field uploads in the form (EG: image, file, featured image) - but using the ADD MEDIA button on a paragraph / WYSIWYG field - it still only shows the files of that specific user/author.

Is there a separate place I'm missing in Toolset to modify what this ADD MEDIA button shows?

#2659157

Thank you for sharing this update and glad that you're making progress.

1. You can disable the 'Add Media' button from the WYSIWYG and content editor fields of the form, by disabling the option
'Include the Add Media button in the rich text editors from this form' in the form's settings.

OR

2. You can try using the 'pre_get_posts' or 'ajax_query_attachments_args' filters to change the query that is used to get the attachments:
https://developer.wordpress.org/reference/hooks/pre_get_posts/
https://developer.wordpress.org/reference/hooks/ajax_query_attachments_args/

In my basic testing, both these filter are engaged when that 'Add Media' button is used and the library files are loaded through the AJAX.

#2661063

Hi Waqar - you can close this for now please.

For reference - ajax_query_attachments_args would ONLY work on the individual image fields (and not the Add Media button)

But pre_get_posts worked on those fields AND the Add Media buttom on the WYSIWYG

Thanks for your help.