Created
November 7, 2016 02:55
-
-
Save xnau/8bb178d797d6f99fdcf128296201d870 to your computer and use it in GitHub Desktop.
Sends the Participants Database welcome email when a record is approved
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 | |
/* | |
Plugin Name: Participants Database Send Welcome On Approval | |
Description: Sends the welcome email when a record is approved. | |
*/ | |
/* | |
* check the new record data before the record is updated | |
*/ | |
add_filter( 'pdb-before_submit_update', 'pdb_send_record_update_notification' ); | |
/** | |
* sends an email notification when a record is approved | |
* | |
* @param array $post the submitted record data | |
* @return array the new record data | |
*/ | |
function pdb_send_record_update_notification( $post ) | |
{ | |
if ( ! is_admin() || empty( $post['email'] ) ) { | |
/* | |
* if we're not in the admin or if there is no email address to send to, do | |
* nothing and return | |
*/ | |
return $post; | |
} | |
/* | |
* these three variables will need to be edited for your application | |
*/ | |
$subject = 'We approved your registration'; | |
$message = 'Dear [first_name] [last_name], | |
Thanks for registering! You may <a href="[record_link]">access and update your record here.</a>'; | |
$from = 'Your Website <info@yourwebsite.com>'; | |
/* | |
* put it all together into the configuration array | |
*/ | |
$config = array( | |
'to' => $post['email'], | |
'from' => $from, | |
'subject' => $subject, | |
'template' => $message, | |
); | |
// send the email if the record is getting approved | |
if ( pdb_record_is_getting_approved( $post ) ) { | |
PDb_Template_Email::send( $config, $post ); | |
} | |
/* | |
* return the record data so it can be saved | |
*/ | |
return $post; | |
} | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment