<?php

/*
Plugin Name: Announce wp-mail sendings
Description: Prints a notice for admin users when Wordpress is sending an email
Author: Sam
Version: 0.1
*/

add_action('phpmailer_init', 'add_admin_notice_phpmail');

function announce_email( $mailer ) {
	if (current_user_can('manage_options')) { // admin only
		echo "<div class='updated'><p>Sending email '". htmlspecialchars($mailer->Subject) ."' to " . htmlspecialchars(implode( ' ', $mailer->to[0] )) . '</p></div>';
	}
}

function add_admin_notice_phpmail($mailer) {
	$whom = implode( ' ', $mailer->to[0] );
	add_action(
		'print_admin_notice',
		"Sending email '{$mailer->Subject}' to $whom."
	);
}

function print_admin_notice($msg) {
	echo '<div class="updated"><p>'.htmlspecialchars($msg).'</div>';
}


?>