On accident today I discovered a really cool plugin for WordPress called the Error Reporting plugin. This plugin is a great tool to log any errors related to WordPress, WordPress plugins, etc. One of the options that the plugin provides is the ability to have each error emailed to you which could be overwhelming depending on what errors you are logging with the plugin. I like to log as much as possible so the problem for me was the fact that the error emails automatically go to the WordPress site administrator email address. My preference would be for this field to be an option that can be configured so I could create a new Gmail address and send all of the errors there. This way you can archive every single error message that has been generated for a long time because of Gmail’s 7GB+ storage capacity. So below I describe how to modify the email address the error logs are sent to along with a couple other items I modified while I was poking around.
WordPress Error Reporting Plugin: more info
To modify the email address that the error logs are sent to you will need to modify line 1870 of the errorreporting.php file located in the “wp-root/wp-content/plugins/error-reporting” directory. The below PHP code examples shows the default and the updated where the To email address has been changed to email@example.com.
Modify Error Reporting Error Log Email To Address:
Default To Email Address:
- $admin_email = get_bloginfo('admin_email');
- $to = $admin_email;
Updated To Email Address:
- $to = "firstname.lastname@example.org";
Notice how in the default that the admin_email variable is set in the line above where the To field is set. That line can be removed since admin_email is not used anywhere else in the code. After you update the above and save the file all the error logs will be emailed to the address you specify. Another thing I decided to modify while looking at the code was the email Subject since by default it is just “Blog error”. I wanted to go ahead and provide a little more detail in the subject line so I added a variable for the specific time and then added that to the Subject of each emaul using the below code.
Default Email Subject PHP Code:
- $subject = "Blog error";
Added Variable & New Email Subject PHP Code:
- $subjecttime = date ('d-M-Y H:i:s', time());
- $subject = "Blog error at " . $subjecttime;
The above will simply add the date and time to the subject of each error log email sent. There are a couple other options you can modify here as well such as the From email address or adding any default text to the body of each email. Hopefully this will be easier for others one day if modifying the email address is added to the Error Reporting admin. I was really surprised to see that this plugin to date has only been downloaded about 1,000 times. The developer put in a lot of work on this plugin and as far as I can tell so far it does a great job of reporting errors and provides lots of cool features related to error reporting.