<?phpfunctioncustom_init(){add_action('shutdown','custom_fatal_error_interceptor');// Do something that might cause a fatal errormaybe_fail_whale();remove_action('shutdown','custom_fatal_error_interceptor');}add_action('init','custom_init');functioncustom_fatal_error_interceptor(){// Get the last PHP error details$error=error_get_last();if($error!==null){if(substr($error['message'],0,22)==='Maximum execution time'){// Friendly e-mail to WordPress site administrator about long processes}elseif(substr($error['message'],0,19)==='Allowed memory size'){// Friendly e-mail about memory restriction}elseif($error['type']===E_ERROR){// Check for other types of fatal errorsif(substr($error['message'],0,36)=="Cannot access protected property WC_"){// Friendly e-mail about WooCommerce 3.0 incompatibility}else{// Check for known Plugin conflicts...// Check for missing Plugin resources...// Check for common issues where the reason for the fatal error can be established from the error message provided to us by error_get_last()}}}}?>
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.