Posted on by

Sending a User Welcome Email When a Record is Approved

A few months ago, I wrote a tutorial on how to automatically send an email when a record is updated. I’ve gotten several requests for something very similar: how to send an email to a person who has signed up, but ONLY after their submission has been approved. This is a good way to avoid spam submissions showing up on your site if you have an open registration form, so that anyone trying to sell you “real” Gucci bags isn’t getting added as a legitimate signup.

The first thing you’ll need to do is set up an approval checkbox as an administrative field (that is, it’s in an admin field group) and set up all your frontend displays to exclude showing unapproved records.

The original tutorial steps you through the creation of a simple plugin to add that functionality to Participants Database. You should read that article if you want to learn in detail how that is done. Anyway, the tutorial ends up with a plugin script that looks like this:

To get our functionality, what we need to do to that script is add a function that checks that the previously saved record was not approved and that the record is currently getting updated with an approval. If those conditions are met, we know that we need to send out the “welcome” email. We do that by loading the saved record, check if it’s unapproved, then check the update data to see if it is getting approved. A good way to do this is to create a function that does the checking…like this:

function pdb_record_is_getting_approved( $new_record )
{
  $old_record = Participants_Db::get_participant( $new_record['id'] );
  if ( $old_record['approved'] !== 'yes' && $new_record['approved'] === 'yes' ) {
    return true;
  }
  return false;
}

We just use that function to determine if the email should be sent or not. We put that in the section of the plugin that sends the email so it will skip sending it if the record isn’t getting approved at that point:

if ( pdb_record_is_getting_approved( $post ) ) {
    PDb_Template_Email::send( $config, $post );
  }

Pretty simple, huh? You’ll notice I used a long descriptive name for the function: that’s so the code ends up being more readable. Maybe that’s not needed for such a simple script, but it’s a good coding practice that will save you time later when you’re trying to fix bugs or change how things work.

Before you activate this plugin and start using it, uncheck the “Send Signup Response Email” in the plugin settings so that the regular signup greeting is not sent.

Here is the completed plugin:

6 thoughts on “Sending a User Welcome Email When a Record is Approved

  1. How to make all fields read only on the profile page of user after the admin approved the record?

    1. This can be done using a custom template, you’ll need to have some ability to do some php coding, but you can check the record value for the approval before displaying, then show the either their record or display the [pdb_single] shortcode, which would give them all their values in a non-editable form.

  2. Added SMTP Email plugin to help eliminate undelivered and spam email warnings. All emails are sending correctly except for the emails from this plugin (were sending OK before SMTP EMail Plugin). Checking my error logs, I found this: xnau_Template_Email::_mail sending failed for: example.email@email.com while doing:

    1. Found the problem / solution. When changing to SMTP Email Plugin, once I changed the “from” email address to match the authenticated email address in the SMTP plugin, emails resumed sending.

  3. I have a site where members get added by admin, members will be able to update their profile.
    The existing 2000 members will be added via CSV file.

    Needed a way to bulk send a message with Private ID to each one of them.

    I think this will solve my problem
    :) thank you!

    1. For this, you need the Email Expansion Kit add-on. It will allow you to send the “signup” email to selected items on the list. Set up the “signup” email as your “welcome and this is how you get to your record” email.

      You’ll have to do it in batches, but it’s relatively simple using the “select all”.

Leave a Reply

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

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.

6 thoughts on “Sending a User Welcome Email When a Record is Approved

  1. How to make all fields read only on the profile page of user after the admin approved the record?

    1. This can be done using a custom template, you’ll need to have some ability to do some php coding, but you can check the record value for the approval before displaying, then show the either their record or display the [pdb_single] shortcode, which would give them all their values in a non-editable form.

  2. Added SMTP Email plugin to help eliminate undelivered and spam email warnings. All emails are sending correctly except for the emails from this plugin (were sending OK before SMTP EMail Plugin). Checking my error logs, I found this: xnau_Template_Email::_mail sending failed for: example.email@email.com while doing:

    1. Found the problem / solution. When changing to SMTP Email Plugin, once I changed the “from” email address to match the authenticated email address in the SMTP plugin, emails resumed sending.

  3. I have a site where members get added by admin, members will be able to update their profile.
    The existing 2000 members will be added via CSV file.

    Needed a way to bulk send a message with Private ID to each one of them.

    I think this will solve my problem
    :) thank you!

    1. For this, you need the Email Expansion Kit add-on. It will allow you to send the “signup” email to selected items on the list. Set up the “signup” email as your “welcome and this is how you get to your record” email.

      You’ll have to do it in batches, but it’s relatively simple using the “select all”.

Leave a Reply

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

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.