I use acf_form to display a front end form to add some custom post type.
This custom post type has a gallery field.
But unfortunately, when a user with a “Subscriber” role try to click on “Add images to gallery field”, it’s not working.
I have this error in my JS : TypeError: wp.media is undefined
How can i permit to my Subscriber to add pictures ?
Thanks everyone for your time!
This is because subscribers do not have permission to upload files. You will need to either assign them to a role that can upload files or you’ll need to alter the subscriber permissions to allow them to upload. This https://wordpress.org/plugins/user-role-editor/ or similar plugins will let you do that.
But, a word of warning. Allowing subscribers the ability to upload files can be considered a security vulnerability. I would not do this on a site where anyone can join the site. You might want to think about an alternative. For example, you could create a repeater field with image sub fields. Then you can use the repeater in place of the gallery. If you want to keep the gallery you could build either an acf/pre_save_post or acf/save_post filter to copy the images from the repeater into the gallery.
I thought using the repeater with image fields was the best solution for this – but what would happen to the images when a row is deleted?
I guess they would remain in the Media Gallery and then increase the disk usage on the server over time as people upload and change their images?
Would appreciate anyone’s advice on a good way to approach Gallery fields on a front end form for users that have a Subscriber level of access.
Even if you use a gallery field the images will stay in the media library when removed from the gallery. To avoid this in either case you would need to create a filter that removed files no longer present in the fields and you’d need to compare the old values of the field with the new values to figure out what media needs to be deleted. For a front end form this could be done in an acf/pre_save_post filter.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.