Can WordPress email the admin about PHP errors, while hiding them from the site?

Is it possible to have WordPress email the site administrator whenever a PHP error message is displayed? Ideally the message would also be filtered out of the HTML output, so as to avoid information disclosure.

I ask because, while @ini_set('display_errors', 0); is at the top of my wp-config.php and working nicely, I want to receive notifications about errors.

I will happily write a custom plugin to do this, if someone who knows more about WP can point me in the direction of where I might hook in to get the job done.

Final bit: Am I crazy for wanting something this out-of-the-ordinary?

Solutions Collecting From Web of "Can WordPress email the admin about PHP errors, while hiding them from the site?"

Displaying PHP errors isn’t really a WordPress thing, it is more of a PHP thing directly. No, I don’t think you are crazy for wanting this, I had a similar need for a separate application and I wrote this blog post which should be helpful.

Essentially, define your own error handler.

Typically, as v0idless mentioned, this is done on the server side, There any many tools to manage error logs and emails out there. The error log reporting on the server end is much more detailed than you could write in a plugin.

Though I have never tested it I believe error_log php function supports email.

Reporting constant errors can kill your site/server depending on the error threshold you have set, I recommend you just email the error.log file once every few hours/days.

For instance on the server end:

  • All fatal or hard errors are in a
    separate log file which is emailed
    immediately.( Also instant
    message/cell phone support).

  • All other errors in are in another
    log file emailed every 24 hours (
    which I never read:) )

  • They log files are also backed up
    every day.

I actually use rubygems to do this stuff since it’s so damn easy.