Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save swoboda/4b97090229c61cf4629c00fa68913f05 to your computer and use it in GitHub Desktop.
Save swoboda/4b97090229c61cf4629c00fa68913f05 to your computer and use it in GitHub Desktop.
Programmatically Trigger Gravity Forms Notification on Help Scout Error
<?php
// Do NOT include the opening php tag
add_action( 'gform_gravityformshelpscout_post_process_feed', 'wpdesk_helpscout_authentication_mail', 10, 4 );
/**
* Email notification to admin about Gravity Forms Help Scout API authentication problem and create Help Scout conversation
*
*/
function wpdesk_helpscout_authentication_mail( $feed, $entry, $form, $addon ) {
// Only run this code if there is a problem with Help Scout API authentication
if ( ! $addon->is_authenticated() ) {
// Create message and headers
$message = sprintf( __( 'Unable to create conversation %s because API was not initialized. %s', 'wpdesk' ), '<a href="' . admin_url( 'admin.php?page=gf_entries&view=entry&id=' . absint( $form['id'] ) . '&lid=' . esc_attr( $entry['id'] ) . '">' . $entry['id'] ) . '</a>', '<a href="' . $addon->get_redirect_url() . '">' . __( 'Click here to authenticate with Help Scout.', 'wpdesk') . '</a>' );
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
// Send admin notification
wp_mail( get_option( 'admin_email' ), __( 'Help Scout API problem', 'wpdesk' ), $message, $headers );
// Send Help Scout notification to create conversation
GFAPI::send_notifications( $form, $entry, 'help_scout_conversation_error' );
}
}
add_filter( 'gform_notification_events', 'wpdesk_gf_notification_events' );
/**
* Add notification events
*
*/
function wpdesk_gf_notification_events( $notification_events ) {
$notification_events['help_scout_conversation_error'] = __( 'Help Scout Conversation Error', 'wpdesk' );
return $notification_events;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment