Skip Navigation

[Resolved] cred_post_expiration_custom_actions

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Noriko Sugiura 7 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#565725

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.

My function looks like this:

    add_action('cred_post_expiration_custom_actions', 'on_wager_expired',10,3);
    function on_wager_expired($custom_actions, $post_id, $form_data)
    {
        error_log("wager expired 1");
	
        $custom_actions[] = array( 'meta_key' => 'wpcf-status', 'meta_value' =>'Full' );
        return $custom_actions;
    }

...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.

#565757

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#565928

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.

#566103

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

#566460

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please tell me which CRED form you are using to create posts with custom actions?

#566534

Yes, the posts are created using this link: hidden link

The post form is "Add new free ad ".

The output of the logger function can be found at /pesformoney.com/wp-content/plugins/wp-monolog-master/log

#566795

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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

#566933

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.

Any idea how I can achieve this?

Thanks a lot,

#567038

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that you know now how post expiration works.

Yes - it will be great if you open a new ticket for your each new question. This will help other users searching on the forum. Have a great day!! 🙂

#567398

Thank you. I will open a different ticket for my use case