Problem:
I want to upload multiple files (one repeating-field) via CRED-form.
After successfull uploads, i want to move and rename the files to a different file-directory (with a little bit php-code via the cred_submit_complete hook). Don´t want to use hooks like "wp_handle_upload_prefilter", "upload_dir", or "cred_form_ajax_upload_validate". After that i have to update the custom repeating field with the new renamed file-paths and file-names.
Unfortunatelly the upload-function by toolset will add the files to the media library automatically and i don´t want that.
So my two questions are
1. Is the hook the right place for renaming, moving and updating uploaded files?
2. How do i prefent to attach files to the media library?
Solution:
Q1) Is the hook the right place for renaming, moving and updating uploaded files?
Yes, I think it is the right place. And it is possible to use action hook "cred_submit_complete" to achieve what you want, for example when user submit the CRED form successfully, use action hook "cred_submit_complete" to trigger a custom PHP function, in this PHP function, get the file/image field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
Then rename the file name to what you want:
http://php.net/manual/en/function.rename.php
Q2) How do i prevent to attach files to the media library?
You can simply remove it from medial library:
https://developer.wordpress.org/reference/functions/wp_delete_post/
For example, use action hook "cred_submit_complete" to trigger a custom PHP function, in this PHP function, get the file/image field value
https://developer.wordpress.org/reference/functions/get_post_meta/
get the post ID of file/image in media library:
https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
Then remove it from media library:
https://developer.wordpress.org/reference/functions/wp_delete_post/
For your reference.
Relevant Documentation:
https://developer.wordpress.org/reference/functions/wp_delete_post/
https://developer.wordpress.org/reference/functions/get_post_meta/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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/Hong_Kong (GMT+08:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years, 11 months ago.
Assisted by: Luo Yang.