<?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 (!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]);

  if ($wasChecked) {
    $errors = sendMessage(array(
      'from'    => $SETTINGS['adminEmail'],
      'to'      => $_REQUEST['email'],
      'subject' => "You have been approved!",
      'text'    => "Congradulations!

You have been approved for our website.
Your password is: {$_REQUEST['password']}

See you soon!
",
    ));
    if ($errors) { die($errors); }
  }

}



?>
