gpns_schedule_timestamp

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Send notification on the last day of every month
    2. Send notification at the beginning of the next work week
  5. Since

Description

Filter the timestamp (Unix epoch) used to schedule a notification

Usage

Apply to all applicable fields on all forms.

add_filter( 'gpns_schedule_timestamp', 'my_custom_function' );

Apply to all applicable fields on a specific form.

add_filter( 'gpns_schedule_timestamp_FORMID', 'my_custom_function' );

Parameters

  • schedule_datetime int

    Unix epoch (seconds) that will be used as the time of when the notification should send.

  • notification array

    The notification.

  • entry array

    The current entry.

  • is_recurring boolean

    Whether the notification is being scheduled as a recurring notification.

  • current_time int

    The current server Unix epoch timestamp.

Examples

Send notification on the last day of every month

<?php
/**
 * Gravity Perks // Notification Scheduler // Send Notification on the Last Day of Every Month
 * https://gravitywiz.com/documentation/gravity-forms-notification-scheduler/
 */
add_filter( 'gpns_schedule_timestamp', function ( $timestamp, $notification, $entry, $is_recurring, $current_time ) {

	// Update "123" to the form ID.
	$form_id = 123;

	// Update "1a23bc456def7" to the notification ID.
	$notification_id = '1a23bc456def7';

	// See https://www.php.net/manual/en/datetime.formats.php for supported date/time formats.
	if ( $is_recurring ) { // If the notification has just been triggered to send and the next recurring notification is being scheduled (if repeat is enabled)
		$desired_time = 'last day of next month 12:00 PM';
	} else {
		$desired_time = 'last day of this month 12:00 PM';
	}

	if ( (int) $entry['form_id'] !== (int) $form_id || $notification['id'] !== $notification_id ) {
		return $timestamp;
	}

	$local_timestamp = gmdate( 'Y-m-d H:i:s', strtotime( $desired_time ) );
	$utc_timestamp   = strtotime( get_gmt_from_date( $local_timestamp ) );

	return $utc_timestamp;
}, 10, 5 );

Send notification at the beginning of the next work week

<?php
/**
 * Gravity Perks // Notification Scheduler // Send Notification at the Beginning of the Next Work Week
 * https://gravitywiz.com/documentation/gravity-forms-notification-scheduler/
 */
add_filter( 'gpns_schedule_timestamp', function ( $timestamp, $notification, $entry, $is_recurring, $current_time ) {

	// See https://www.php.net/manual/en/datetime.formats.php for supported date/time formats.
	$desired_time = 'next monday 12:00 PM';

	// Update "123" to the form ID.
	$form_id = 123;

	// Update "1a23bc456def7" to the notificaiton ID.
	$notification_id = '1a23bc456def7';

	if ( (int) $entry['form_id'] !== (int) $form_id || $notification['id'] !== $notification_id ) {
		return $timestamp;
	}

	$local_timestamp = gmdate( 'Y-m-d H:i:s', strtotime( $desired_time ) );
	$utc_timestamp   = strtotime( get_gmt_from_date( $local_timestamp ) );

	return $utc_timestamp;
}, 10, 5 );

Since

This filter is available since Gravity Forms Notification Scheduler 1.0.2.