Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to use Register Shutdown Function to track Fatal Errors, my question is, where's the best place to call this so it hits both WordPress, Plugin, and Theme Fatal Errors?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

WordPress core register a shutdown function on its own (source) the function shutdown_action_hook registered to be ran on shutdown, call

do_action( 'shutdown' );

and little more (source).

So, if you want to register a shutdown function in WordPress way just add your function on 'shutdown' hook:

add_action( 'shutdown', 'my_shutdown_callback' );

function my_shutdown_callback() {
  error_log('Goodbye');
}

Where to put this code is not very important, a plugin, a mu plugin, functions.php, it doesn't matter, it will run always on shutdown...

Of course register it as soon as possible allows you to catch early errors, so using a mu plugin you can catch errors that happen on plugins init.

share|improve this answer
    
I mean, are there really any other alternatives to putting it at the top of my themes functions.php file so that it registers as early as possible? +1 –  Howdy_McGee Aug 1 at 21:32
    
@Howdy_McGee when developing a theme, no, there is no (useful) alternative. Possible alternatives are are on top of plugins or MU plugins files, but if you are developing a theme... –  G. M. Aug 1 at 21:44
    
The reason that I'm looking to do this is because I do manage multiple themes, and would like to run automatic updates on all of them but the problem with that is if one of the plugins isn't compatible and throws a fit. The only other option I was thinking is to manually add it to wp-config.php or a similar file but I'm not sure what files get overwritten on update. –  Howdy_McGee Aug 1 at 21:47
1  
@Howdy_McGee use a plugin, or a mu plugin. In the latter case you can just put the code I posted (of course using the real callback) and save the file in the mu-plugins folder and you are done. If you use a regular plugin than you have to use plugin headers and activate it in backend. –  G. M. Aug 1 at 21:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.