'E_ERROR', E_PARSE => 'E_PARSE', E_USER_ERROR => 'E_USER_ERROR', E_COMPILE_ERROR => 'E_COMPILE_ERROR', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', ]; // Provide friendly-names for the error codes $allErrorTypes = [ E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED", E_ALL => "E_ALL", ]; $isFatalError = isset($fatalErrorTypes[$error['type']]); $comesFromWpStaging = strpos($error['file'], WPSTG_PLUGIN_SLUG) !== false; /* * Logs fatal errors that happens anywhere, * and notices, warnings that comes from a WP STAGING file. * * (It will only log notices and errors from WP STAGING * if it was the last notice/warning triggered before PHP shutdown) */ if ($isFatalError || $comesFromWpStaging) { // Opening a file handler gives us more control than error_log('foo', 3, 'custom-file.log'); $fileHandler = @fopen(WPSTG_DEBUG_LOG_FILE, 'a'); $message = sprintf( "[WP STAGING Shutdown Function][%s][%s] %s - File: %s Line: %s | Is it Fatal Error? %s | Is it Thrown by WP STAGING? %s\n", $allErrorTypes[$error['type']], current_time('mysql'), $error['message'], $error['file'], $error['line'], $isFatalError ? 'Yes' : 'No', $comesFromWpStaging ? 'Yes' : 'No' ); if (is_resource($fileHandler)) { fwrite($fileHandler, $message, 5 * MB_IN_BYTES); } } } register_shutdown_function('\WPStaging\functions\shutdown_function');