Problem:
The customer noticed that users were able to have multiple photos attached to their profiles in the WordPress Admin, even though only one photo should be allowed. He wanted to ensure that if a user removes their profile photo and resubmits the form, the photo is permanently deleted. Additionally, if a user chooses a new photo, it should replace the existing one.
Solution:
We explained that Toolset Forms does not natively support this feature but provided a workaround using custom code:
1- Use the cred_save_data action hook to trigger a PHP function when a user submits the post form.
2- In the PHP function:
• Retrieve images attached to the current post using get_attached_media.
• Access images stored in the custom repeating image field using get_post_meta.
• Compare these sets of images to identify and remove unused files using wp_delete_attachment.
Relevant Documentation:
https://toolset.com/forums/topic/delete-images-from-server-after-front-end-cred-form-update/#post-1604187
https://toolset.com/documentation/programmer-reference/cred-api/
https://developer.wordpress.org/reference/functions/get_attached_media/
https://codex.wordpress.org/Function_Reference/wp_delete_attachment
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 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Sao_Paulo (GMT-03:00)
Este tema contiene 14 respuestas, tiene 2 mensajes.
Última actualización por hace 10 meses, 1 semana.
Asistido por: Mateus Getulio.