* @access public
* @return void
*/
- public function sendEmailNotification( $notification_type, $account )
+ public function sendEmailNotification( $notification_id, $account )
{
// Support Class
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
// get the Account
$account = $BillingSupport->getAccountById( $account );
- echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
+ if ( !$account ) {
+ // If there's no account then return false.
+ return false;
+ }
+ $to_email = $account['email'];
+ if ( !$to_email ) {
+ // If there's no email then return false.
+ return false;
+ }
// get the Notification type
- $notification_type = $this->getNotificationTypeById( $notification_type );
+ var_dump( $notification_id );
+ $notification_type = $this->getNotificationTypeById( $notification_id );
echo '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
+ if ( !$notification_type ) {
+ // If there's no notification type then return false.
+ return false;
+ }
+ $subject = $notification_type['subject'];
+ if ( !$subject ) {
+ // If there's no subject then return false.
+ return false;
+ }
+ $from_header = $notification_type['from_header'];
+ $replyto = $notification_type['replyto'];
+
+ // Setup the Smarty Engine
+ $smarty = new smartyTemplateSupport();
+ $viewPath = GLM_MEMBERS_BILLING_PLUGIN_PATH . '/views';
+ $smarty->template->setTemplateDir( $viewPath );
+
+ // Add standard parameters
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+ $viewFile = 'admin/notifications/notification.html';
+
+ $smarty->templateAssign( 'title', $notification_type['subject'] );
+ $smarty->templateAssign( 'html_content', wpautop( $notification_type['message'] ) );
+
+ // Generate output from model data and view
+ $htmlMessage = $smarty->template->fetch( $viewFile );
+
+ // change the default wordpress from name when sending mail
+ add_filter(
+ 'wp_mail_from_name',
+ function ( $name ) {
+ $siteName = get_bloginfo( 'name' );
+ return $siteName;
+ }
+ );
+ // Send confirmation email, set the content type to allow html by using this filter
+ add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+ $message = $htmlMessage;
+ $header[] = 'From:' . $from_header;
+ $header[] = 'Reply-To:' . $replyto;
+
+ wp_mail( $to_email, $subject, $message, $header );
+
+ // remove the filter to avoid conflicts
+ remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
}
/**
);
}
+ /**
+ * Set content type of the email.
+ *
+ * Used as filter for the wp_mail_content_type
+ */
+ function set_content_type()
+ {
+ return "text/html";
+ }
}
echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
$Notifications = new GlmNotifications( $this->wpdb, $this->config );
- $notification_id = 5;
- $account = 1;
- $Notifications->sendEmailNotification( $notification_id, $account );
+ $notification_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
+ if ( $notification_id ) {
+ echo '<pre>$notification_id: ' . print_r( $notification_id, true ) . '</pre>';
+ $account = 1; // TODO: remove this. It's for testing only
+ $noticeReturned = $Notifications->sendEmailNotification( $notification_id, $account );
+ var_dump( $noticeReturned );
+ }
wp_die('Testing here');
break;
case 'add':