Last active
March 18, 2021 06:15
-
-
Save bhubbard/22afd107e57dd0f8b0c1c4645bae73b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Postmark Headers for Gravity Forms. | |
* | |
* @param [type] $email Email. | |
* @param [type] $message_format Message Format. | |
* @param [type] $notification Notification. | |
*/ | |
function postmark_headers_for_gravityforms( $email, $message_format, $notification, $entry ) { | |
$entry_id = $entry['id'] ?? ''; | |
$form_id = $entry['form_id'] ?? ''; | |
if ( $entry_id ) { | |
$email['headers']['X-PM-Metadata-gf-entry-id'] = 'X-PM-Metadata-gf-entry-id: ' . $entry_id; | |
} | |
if ( $form_id ) { | |
$email['headers']['X-PM-Metadata-gf-form-id'] = 'X-PM-Metadata-gf-form-id: ' . $form_id; | |
} | |
$email['headers']['X-PM-Tag'] = 'X-PM-Metadata-tag: gravity-forms'; | |
return $email; | |
} | |
add_filter( 'gform_pre_send_email', 'postmark_headers_for_gravityforms', 10, 4 ); | |
/** | |
* Postmark Notification Settings. | |
* | |
* @param [type] $ui_settings UI Settings. | |
* @param [type] $notification Notification. | |
* @param [type] $form Form. | |
*/ | |
function postmark_notification_setting( $ui_settings, $notification, $form ) { | |
$ui_settings['postmark_tag'] = ' | |
<tr> | |
<th><label for="postmark-tag">Postmark - Tag</label></th> | |
<td><input value="' . rgar( $notification, 'postmark_tag' ) . '" name="postmark_tag"></td> | |
</tr>'; | |
return $ui_settings; | |
} | |
add_filter( 'gform_notification_ui_settings', 'postmark_notification_setting', 10, 3 ); | |
/** | |
* Postmark Notification Save. | |
* | |
* @param [type] $notification Notification. | |
* @param [type] $form Form. | |
*/ | |
function postmark_notification_save( $notification, $form ) { | |
$notification['postmark_tag'] = rgpost( 'postmark_tag' ); | |
return $notification; | |
} | |
add_filter( 'gform_pre_notification_save', 'postmark_notification_save', 10, 2 ); | |
add_filter( 'gform_pre_send_email', function ( $email, $message_format, $notification ) { | |
if( ! empty( $notification['postmark_tag'] ) ) { | |
$email['headers']['X-PM-Tag'] = 'X-PM-Metadata-tag: ' . $notification['postmark_tag']; | |
} | |
return $email; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment