Skip to content

Instantly share code, notes, and snippets.

@mattwiebe
Created December 21, 2010 01:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattwiebe/749336 to your computer and use it in GitHub Desktop.
Save mattwiebe/749336 to your computer and use it in GitHub Desktop.
A simple class to override WP's email functionality to debug/inspect what will be sent. Put in your mu-plugins directory.
<?php
/*
Plugin Name: Mail Killer/Logger
Description: A simple class to override WP's email functionality to debug/inspect what will be sent. Put in your mu-plugins directory.
Version: 1.0
Author: Matt Wiebe
Author URI: http://somadesign.ca/
License: A "Slug" license name e.g. GPL2
*/
class SD_Mail_Killer {
private $phpmailer;
private $kill_email = true; // true: email will not be sent
private $log = true; // true: the PHPMailer Object will be written to your error_log for debugging purposes.
function __construct() {
add_action('phpmailer_init', array($this, 'replace'), 10, 1);
}
function Send() {
if ( ! $this->kill_email )
$this->phpmailer->Send();
if ( $this->log )
error_log(print_r($this->phpmailer, true));
do_action('sd_mail_killer', $this->phpmailer);
}
function replace($phpmailer) {
$this->phpmailer = $phpmailer;
$phpmailer = $this;
}
}
new SD_Mail_Killer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment