Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active September 16, 2021 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save spivurno/667e6c1ed3a64fe53b58 to your computer and use it in GitHub Desktop.
Save spivurno/667e6c1ed3a64fe53b58 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Send Manual Notifications
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-manual-notifications.php
*/
/**
* Gravity Wiz // Gravity Forms // Send Manual Notifications
*
* Provides a custom notification event that allows you to create notifications that can be sent
* manually (via Gravity Forms "Resend Notifications" feature).
*
* @version 1.2
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/send-manual-notifications-with-gravity-forms/
*/
class GW_Manual_Notifications {
private static $instance = null;
public static function get_instance() {
if( null == self::$instance )
self::$instance = new self;
return self::$instance;
}
private function __construct() {
add_filter( 'gform_notification_events', array( $this, 'add_manual_notification_event' ) );
add_filter( 'gform_before_resend_notifications', array( $this, 'add_notification_filter' ) );
}
public function add_notification_filter( $form ) {
add_filter( 'gform_notification', array( $this, 'evaluate_notification_conditional_logic' ), 10, 3 );
return $form;
}
public function add_manual_notification_event( $events ) {
$events['manual'] = __( 'Send Manually' );
return $events;
}
public function evaluate_notification_conditional_logic( $notification, $form, $entry ) {
// if it fails conditional logic, suppress it
if( $notification['event'] == 'manual' && ! GFCommon::evaluate_conditional_logic( rgar( $notification, 'conditionalLogic' ), $form, $entry ) ) {
add_filter( 'gform_pre_send_email', array( $this, 'abort_next_notification' ) );
}
return $notification;
}
public function abort_next_notification( $args ) {
remove_filter( 'gform_pre_send_email', array( $this, 'abort_next_notification' ) );
$args['abort_email'] = true;
return $args;
}
}
function gw_manual_notifications() {
return GW_Manual_Notifications::get_instance();
}
gw_manual_notifications();
@spivurno
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment