Skip to content

Instantly share code, notes, and snippets.

@jeremyfelt
Created September 4, 2013 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyfelt/6441206 to your computer and use it in GitHub Desktop.
Save jeremyfelt/6441206 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Log wp_mail()
Version: 0.1
Plugin URI: http://wsu.edu
Description: Log emails sent through WordPress to a text file.
Author: jeremyfelt, wsu.edu
*/
add_filter( 'wp_mail', 'wsu_log_wp_mail', 1 );
/**
* Stores emails sent through WordPress to a log file in the content directory.
*
* @param array $args arguments passed to wp_mail()
*
* @return array arguments, unmodified
*/
function wsu_log_wp_mail( $args ) {
// Only do this in a specific local environment.
if ( defined( 'WSU_LOCAL_CONFIG' ) && true === WSU_LOCAL_CONFIG ) {
$log_message = "---MESSAGE---\n" . var_export( array( date('r'), $args ), true );
$fp = fopen( WP_CONTENT_DIR . '/log/wp-mail.log', 'a+' );
fwrite( $fp, $log_message );
fclose( $fp );
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment