This thread is resolved. Here is a description of the problem and solution.
Problem:
With a CRED form that uses automatic post expiration, is it possible for the user to choose the period and overwrite the form settings?
Solution:
Add a field to your form to select the expiry time. You can then use the cred_save_data hook to run some code when the form is submitted that takes the value of the generic date field (available from the $_POST object), which will be in UNIX timestamp format, and overwrite the default post expiration date set by the form.
This is stored as post meta with a key of _cred_post_expiration_time and is also a UNIX timestamp, so it is simply a question of overwriting the current value with that retrieved from your generic field, using update_post_meta.
Is there a way for the public user/submitter to choose their own post expiration date?
Use case: user-submitted coupons/offers. I have a field for expiration date, which I can display on the page, but would also like to use this data to set an expiration date on the post. Is this possible?
You can then use the cred_save_data hook (https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data) to run some code when the form is submitted that takes the value of the generic date field (available from the $_POST object), which will be in UNIX timestamp format, and overwrite the default post expiration date set by the form.
This is stored as post meta with a key of _cred_post_expiration_time and is also a UNIX timestamp, so it is simply a question of overwriting the current value with that retrieved from your generic field, using update_post_meta (https://developer.wordpress.org/reference/functions/update_post_meta/).
If you try that and run into problems let me know and I will try and help.
Thank you! I was able to hook into cred_save_data and actually use my wpcf-ending-date custom field, rather than a generic date field. This way the submitter only has to put in an ending date once, not twice. Thanks for pointing me in the right direction.
One further question. I have "Check for expired content" set to "Once Daily" in Settings > Forms > Other. At what time each day does the Once Daily check happen?
I am already modifying the timestamp in the function to add one day, to make the expiry occur at 7pm of the date selected instead of 7pm the day before (thanks to being in the UTC -5 time zone.) Depending on when the Once Daily check occurs I might need to adjust that.
The timing of when the checks happen is unpredictable.
It works using a standard WP cron job. These are only triggered when there is any activity on your site (front or back-end, anything that spins up WP), and so if you specify 'daily' it will check to see whether it is 24hours+ since the last time the cron job ran. So it is entirely unpredictable.
This is just the job that checks whether a post expired. So in certain circumstances it could be that when a post "expires" it is only changed to draft or whatever you selected some 23h59m later, or longer if there is no activity on your site.
If you need the time to be more accurate you would need to set a shorter interval (although the shorter the interval the more demands on your server).
It is not expected that you can accurately target the specific moment when a post expires. You should think of the post expiration time as "it won't expire before" rather than "it will have expired by".
Thanks again for the reply. I decided to add 29 hours to the unix timestamp, so that the expiration happens (at earliest) at the conclusion of the defined expiration date. Then I set the cron to check hourly rather than once daily. This way the post should be removed from the site in the overnight after the defined expiration date has fully passed. I appreciate your time.