Last active
November 30, 2021 15:37
-
-
Save spivurno/3710975 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Notify User When Submitted Post is Published
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 | |
/** | |
* Notify User When Submitted Post is Published | |
* http://gravitywiz.com/notify-user-when-submitted-post-is-published/ | |
*/ | |
add_action( 'publish_post', 'gw_notify_on_publish' ); | |
function gw_notify_on_publish( $post_id ) { | |
$custom_field_name = 'your_custom_field_name'; | |
$from_name = 'Your Name'; | |
$from_email = 'your@email.com'; | |
$subject = 'Your Subject Here'; | |
$message = 'Your message here.'; | |
/* No need to edit beyond this point */ | |
// if this meta key is not set, this post was not created by a Gravity Form | |
if ( ! get_post_meta( $post_id, '_gform-form-id', true ) ) { | |
return; | |
} | |
// make sure we haven't already sent a notification for this post | |
if ( get_post_meta( $post_id, '_gform-notified', true ) ) { | |
return; | |
} | |
$email = get_post_meta( $post_id, $custom_field_name, true ); | |
$headers = array(); | |
$headers[] = "From: '{$from_name}' <{$from_email}>"; | |
$headers[]= "Content-type: text/html; charset=" . get_option( 'blog_charset' ); | |
wp_mail( $email, $subject, $message, $headers ); | |
update_post_meta( $post_id, '_gform-notified', 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-notify-user-on-publish.php