<?php
/*
Plugin Name: Email On Approved
Description: Email the user their password once they are approved
Version: 1.00
Requires at least: 2.04
*/


// UPDATE THESE VALUES

// DON'T UPDATE ANYTHING BELOW THIS LINE

addAction('record_postsave',  'emailOnApproved_sendPassword', null, 4);


//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
  global $CURRENT_USER, $SETTINGS;
  $fieldname = 'approved';

  // error checking
    if ($tableName != 'accounts') { return; } 
  if (!array_key_exists($fieldname, $CURRENT_USER)) {
    die(__FUNCTION__ .": You must create an accounts fields called '$fieldname'!");
  }

  // send email
  $wasChecked   = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
  $wasUnchecked = intval($oldRecord[$fieldname]  && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__
	Welcome!  <br><br>
  
Your subscription has been  processed successfully and you now have access to the Members Only area of our web site. <br> <br>
Your user name is: {$_REQUEST['username']} <br> 
and your temporary password is: {$_REQUEST['password']}<br><br> 
Once you have successfully logged in, you can change your password and update your profile information. <br><br> 
  
  
<a href="http://www.your_website_URL.com{$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']}">Click here to login</a> <br><br> 
  
Best, <br>  <br>
    
The Subscription Committee  
__TEXT__;


$headers  = 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .="FROM:". $SETTINGS['adminEmail'];  
  
   if ($wasChecked) { 
    $errors = mail($_REQUEST['email'],"Your membership has been successfully processed!",$message,$headers);  
    if ($errors!=1) { die("Mail Error: $php_errormsg"); } 
  } 
 
} 
 
?>
