Notify Author When Post is Published

This snippet is almost identical to the Notify User When Submitted Post is Published snippet. The key difference is this will send a notification to post author rather than an email stored in a custom field. This approach is only applicable when a) logged in users are creating posts via a Gravity Form or b) the Gravity Forms User Registration Add-on is being to used to register a user and a post is being created by that user from the same form.

In case you were wondering… the Gravity Forms User Registration Add-on provides an option to set the registered user as the post author. Convenient, eh?

Don’t forget to set your basic email settings. This includes the name and email from which the email should be sent as well as the subject and message of the notification email.

$from_name  = 'Your Name';
$from_email = 'your@email.com';
$subject    = 'Your Subject Here';
$message    = 'Your message here.';

Comments

  1. Ronel
    Ronel February 17, 2015 at 3:40 am

    Hi there,

    I tried using this plugin, but it’s not sending the email.

    Is there anything I need to change for it to work with Woocommerce Products created via Gravity Forms using the Custom Post Types addon?

    Your help is greatly appreciated.

    Reply
    1. David Smith
      David Smith Staff February 17, 2015 at 9:09 am

      I wouldn’t think so. A post is a post as far as Gravity Forms is concerned. I’m wondering if the “_gform-form-id” meta key is being added. Could you check? Add this to your theme’s functions.php via FTP (do not add this via the theme editor).

      echo ‘‘;

      Replace “$post_id” with the ID of your post. You’ll need to view the source to see the output as it is wrapped in an HTML comment.

    1. David Smith
      David Smith Staff November 20, 2014 at 5:21 pm

      Hi Erika, you can “approve” posts by publishing them via WordPress’ Posts menu. You’ll want to find the post in question, click on it to edit, and then hit the publish button once you’re satisfied. :)

    1. Phil
      Phil August 11, 2014 at 4:37 am

      THanks David. That works.

      One other problem.. the Sender field when received by the recipient reads:

      name rnContent-type: text/html; charset…. etc etc

      How can I get this to just read name ?

      Thanks

    2. David Smith
      David Smith Staff August 11, 2014 at 10:43 am

      This sounds like more of an issue you’re having with WordPress’ wp_mail() than this snippet. Are you seeing this with other emails you receive from WordPress or Gravity Forms?

  2. steveO
    steveO June 18, 2014 at 6:32 pm

    What file do I put this in? I put it into my theme’s functions.php and it fails to run. Nice work! (I just need a little prompt for where it goes….)

    Reply
    1. David Smith
      David Smith Staff June 20, 2014 at 6:31 pm

      Hi steveO, just want to confirm that you followed the instructions here.

      With that said, you might be interested in the GP Post Status Notifications perk available (by request, it’s a beta) with Gravity Perks. Here is a quick video that demonstrates how it works. I think you’ll really appreciate how much easier and more powerful the perk-version is compared to this snippet.

  3. chrismccoy
    chrismccoy May 10, 2012 at 4:50 pm

    is there a better way? if you fire it on publish_post that means it will be fired on every post submit, non gravityforms wise.

    Reply
    1. The Wiz
      The Wiz Staff May 10, 2012 at 5:47 pm

      Gravity Forms adds a post meta value to the field stored as “_gform-form-id”. This snippet checks for the existence of this meta key. If it isn’t found, it knows this post was not created by a Gravity Form and does not send the email.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Notify Author When Post is Published

This field is for validation purposes and should be left unchanged.