Trigger Function on Send

This snippet demonstrates how to trigger a custom function using a scheduled notification. The notification is suppressed by default but can also be triggered by removing the specified line below. The trigger notification is identified by its subject line.

Code

Filename: gpns-trigger-function-by-scheduled-notification.php

<?php
/**
 * Gravity Perks // Notification Scheduler // Trigger Function on Send
 * https://gravitywiz.com/documentation/gravity-forms-notification-scheduler/
 *
 * This snippet demonstrates how to trigger a custom function using a scheduled notification. The notification
 * is suppressed by default but can also be triggered by removing the specified line below. The trigger
 * notification is identified by its subject line.
 */
add_filter( 'gform_pre_send_email', function( $email, $message_format, $notification, $entry ) {

	// Only intercept emails sent via Notification Scheduler.
	if ( ! doing_action( 'gpns_cron' ) ) {
		return $email;
	}

	// Update "Trigger: My Custom Function" to your trigger notification's subject line.
	if ( $notification['subject'] !== 'Trigger: My Custom Function' ) {
		return $email;
	}

	// Delete this line if you want the notification to still be sent.
	$email['abort_email'] = true;

	// Update this to your own custom function name.
	my_custom_function();

	return $email;
}, 10, 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.