Skip Navigation

[Closed] Custom post expiry date and email notifications of expiry

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/Karachi (GMT+05:00)

This topic contains 16 replies, has 3 voices.

Last updated by Waqar 11 months ago.

Assisted by: Waqar.

Author
Posts
#2640959

I have used this solution to expire posts to pending review status based on a user entered date in a form https://toolset.com/forums/topic/set-the-post-expiration-date-within-a-form/

I have used this code

add_action('cred_save_data', 'set_expiry_date', 10, 2);

function set_expiry_date($post_id, $form_data){

	// if a specific form - create package or edit package

	if ($form_data['id']==193702 OR $form_data['id']==193801)

	{

		if (isset($_POST['expiry']['datepicker']))

		{

			// add it to saved post meta

			
			
            
           
			
			$new_status_arr = array( 'post_status' => 'pending', 'custom_actions' => array() );
            update_post_meta($post_id, '_cred_post_expiration_action', $new_status_arr);
			
			
                    
			
			update_post_meta($post_id, '_cred_post_expiration_time', $_POST['expiry']['datepicker']);
			

		}

	}

}

It works well, but I have also set up a notification in the form to alert the post author by email when the post status changes to pending review. The email is not sent for some reason.

#2641205

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this, I'll need to see how this form and the notification are set up in the admin area.

Can you please share temporary admin login details, along with the link to the form page?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2641661

Thank you for sharing these details, but I'm getting the error 'The username or password you entered is incorrect'.

Can you please check them again?

Note: I'm setting your next reply as private.

#2643105

Thank you for sharing the access details.

Just wanted to let you know that I'm still working on this and will be able to share an update, within the next few hours.

Thank you for your patience.

#2643655

Thank you for waiting.

I've been running some tests with the same custom code and the form and notification settings, on a couple of different testing servers and everything worked as expected.

The post status was changed as per the expiry date field and the form notification was sent too.

I've now added a couple of test package posts through that form, on your website and will wait for the notification to fire after midnight today.
( For the test admin user you've provided, I've updated my email address so that I can receive the notification, as the post author )

I'll keep you updated with those packages and the notifications accordingly.

#2644935

Thank you for waiting.

After several tests with the notifications on my test website and yours, I can confirm that the issue is specific to your specific website.

Do we have your permission to download the clone/snapshot of your website to investigate this further on a different server? This will allow us to debug this, without affecting the actual website.

#2644973

Yes. Thanks for being so thorough on this. You have my permission to take a clone of the site

#2645315

Thank you for the permission and I have downloaded the website's clone.

I'll be running some tests on this clone and will share the findings, as soon as this testing completes.

#2647003

Just wanted to update you that I'm still working on this.

I'll share the results as soon as some existing tests are completed.

#2647331

Thanks a lot for keeping me up to date

#2649319

Thank you for waiting, as I was able to narrow down the conflict on your website.

On your website's clone, I noticed that there were many custom time intervals registered, for the forms to check for the post-expiration date/time.

This option is available at WP Admin -> Toolset -> Settings -> Forms, under the section 'Post expiration'.

I couldn't find any custom code that was being used to register these custom intervals, so these intervals must be coming from some existing or past third-party plugins.

Here are the steps, that I'll recommend:

1. You can register a custom interval that checks for the post-expirations, every 12 hours, using the following code:
( it can be included in the active child theme's 'functions.php' file )


add_filter ('cred_post_expiration_cron_schedules', 'custom_function_12hours_interval', 10,1);
  
function custom_function_12hours_interval ($schedules) {
    $schedules['twelve'] = array( 'interval' => 720 * MINUTE_IN_SECONDS, 'display' => __( 'Every 12 hours' ) );
    return $schedules;
}

2. Next, from WP Admin -> Toolset -> Settings -> Forms, under the section 'Post expiration', select this newly registered time interval 'Every 12 hours'.

3. Using the form 'Create package', add 3 new package posts, with the expiration date set to tomorrow, the day after tomorrow, and the two days after tomorrow, respectively.

Important note: When we select a date through the date field, the time for the selected date is set to 12 at midnight of the selected date. And since we've set the form to check every 12 hours, you can expect the post-expiration code to work for those posts, around and after midday of the selected dates.

Please run this test and you'll see that the expiration code and notification will be working as scheduled.

#2650117

Thanks; I will test this and report back. I really appreciate all your help.

#2650123

Glad I could help and I'll wait to hear back from you.

#2652093

The test worked well for the 1 day later expiry date.

Following that, I amended slightly the content of the message being sent by the form but made not other changes. The 2 day out and 3 day out notifications did not send/ Can you think why this might be? Thanks.

#2652413

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Nick

Waqar is off this week, let me step in here.

I logged in to your site to check the setup.

The code you shared at the outset applies to 2 forms, Create package, and Edit package.

Only the Create package form adds a notification, a single notification for when the post status changes to Pending.

Your code takes a date field from the form and sets the post to expire (change status to pending) at that date.

So only one notification can ever be sent.

Hence, I don't understand your last update: "the 2 day out and 3 day out notifications did not send".

What 2 day out and 3 day out notifications?

One notification should be sent, when the post expires (is changed to pending).

The topic ‘[Closed] Custom post expiry date and email notifications of expiry’ is closed to new replies.