Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gravity Wiz // Notify User When Submitted Post is Published
* Notify User When Submitted Post is Published
add_action('publish_post', 'notify_on_publish');
function notify_on_publish($post_id) {
global $post;
$custom_field_name = 'your_custom_field_name';
$from_name = 'Your Name';
$from_email = '';
$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))
// make sure we havne't already sent a notification for this post
if(get_post_meta($post_id, '_gform-notified', true))
$email = get_post_meta($post_id, $custom_field_name, true);
$headers = "From: '$from_name' <$from_email> rn";
$headers .= "Content-type: text/html; charset=" . get_option('blog_charset') . "rn";
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
You can’t perform that action at this time.