| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?> |
| 2 |
<?php |
| 3 |
|
| 4 |
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler |
| 5 |
set_error_handler(function($errno, $msg, $fn, $ln) use ($file) { |
| 6 |
|
| 7 |
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting |
| 8 |
if (!(error_reporting() & $errno)) { |
| 9 |
return false; |
| 10 |
} |
| 11 |
|
| 12 |
$levels = [ |
| 13 |
E_ALL => "E_ALL", |
| 14 |
E_ERROR => "E_ERROR", |
| 15 |
E_WARNING => "E_WARNING", |
| 16 |
E_PARSE => "E_PARSE", |
| 17 |
E_NOTICE => "E_NOTICE", |
| 18 |
E_CORE_ERROR => "E_CORE_ERROR", |
| 19 |
E_CORE_WARNING => "E_CORE_WARNING", |
| 20 |
E_COMPILE_ERROR => "E_COMPILE_ERROR", |
| 21 |
E_COMPILE_WARNING => "E_COMPILE_WARNING", |
| 22 |
E_USER_ERROR => "E_USER_ERROR", |
| 23 |
E_USER_WARNING => "E_USER_WARNING", |
| 24 |
E_USER_NOTICE => "E_USER_NOTICE", |
| 25 |
E_STRICT => "E_STRICT", |
| 26 |
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", |
| 27 |
E_DEPRECATED => "E_DEPRECATED", |
| 28 |
E_USER_DEPRECATED => "E_USER_DEPRECATED" |
| 29 |
]; |
| 30 |
|
| 31 |
$levelName = $levels[$errno] ?? "UNKNOWN ERROR LEVEL"; |
| 32 |
|
| 33 |
// Improved debugging information |
| 34 |
if (strpos($fn, dirname($file) . '/') !== false) { |
| 35 |
$debugInfo = [ |
| 36 |
'Error Level' => $levelName, |
| 37 |
'Message' => $msg, |
| 38 |
'File' => $fn, |
| 39 |
'Line' => $ln, |
| 40 |
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
| 41 |
'Backtrace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) |
| 42 |
]; |
| 43 |
|
| 44 |
throw new ErrorException(sprintf( |
| 45 |
/* translators: %1$s is the error level, %2$s is the error message, %3$s is the file name, %4$s is the line number, %5$s is the debug info */ |
| 46 |
'%s - %s in %s at line %s. Debug Info: %s', |
| 47 |
esc_html($levelName), |
| 48 |
esc_html($msg), |
| 49 |
esc_html($fn), |
| 50 |
absint($ln), |
| 51 |
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 52 |
esc_html(print_r($debugInfo, true)) |
| 53 |
), 500); |
| 54 |
} |
| 55 |
|
| 56 |
return false; |
| 57 |
}); |
| 58 |
|