This support ticket is created 7 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
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.
I am having a problem with the cred_post_expiration_custom_actions hook. I don't understand why my custom function is not being triggered when the post expired.
...and it's in /pesformoney.com/wp-content/plugins/my-functions/custom-functions.php
How can I tell that the post expires but the on_wager_expired function is not triggered? Because the post "Off-Road 2010" in "Listings" changes the status to Draft on expiration, but its field wpcf-status does not change value to 'Full'. Moreover, the error_log instruction in the custom function is not called as nothing is printed in the error logs.
Hello. Thank you for contacting the Toolset support.
Well - could you please give a try and move the "cred_post_expiration_custom_actions" hook from your plugins custom function file to your current theme's functions.php file and check if it works fine.
I have done that as suggested, move the function in the theme's functions.php, but unfortunately still not working.
I have also noticed some other odd behavior that I think it's not correct. The post keeps expiring (status changes to Draft) even though it already expired once and "Automatic expire date for this post" is not checked.
Here are some further observations that I cannot really get my head around:
When I create a new post:
- The cred_post_expiration_custom_actions hook function is triggered immediately although the post is set to expire one minute later
- The status does not change to DRAFT
- 1 minute later the status changes to DRAFT, but the expiration hook is not triggered
When I manually update the post expiration
- The cred_post_expiration_custom_actions hook function is NOT triggered at all
- 1 minute later the status changes to DRAFT, but the expiration hook is not triggered
Well - I checked on your install and it works perfectly fine.
What I've done is - with CRED form you are using I edit that form and I set the post expiration settings to 1 minute. See the following image:
=> hidden link
Once I save the above settings with your CRED form - I've created new entry using the following link:
=> hidden link
I did not make any changes to your code and after exactly 1 minute the post status is set to "FULL". You can check with the entry I've created:
=> hidden link
Ooooooh, I see what's going on. I misinterpreted how the cred_post_expiration_custom_actions works.
I thought that the function will be called when the post expires, instead it is actually called right away when the post is created. The custom actions inside the function are then registered somewhere, and triggered when the post expires.
So, yes, indeed, it works as you suggested. However, my use case is different, so I would kindly ask you to suggest how I can achieve what I need and please let me know if you want me to open a new ticket as this one can be considered resolved.
My use case is:
When the post expires, I want to perform some custom actions, but not just updating a field, but invoking a function. I cannot do this as of now because the function is called right away when the post is created when I put it in my cred_post_expiration_custom_actions hook.