Last active
February 2, 2024 20:44
-
-
Save cfaria/7eb83ca2853cb062fd7f6365c9bd6de2 to your computer and use it in GitHub Desktop.
Prevent E_NOTICE, E_WARNING, E_DEPRECATED errors WSOD in Sage 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Roots\Acorn\ServiceProvider; | |
class ThemeServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->booted( | |
function($app) { | |
set_error_handler(function ($level, $message, $file = '', $line = 0, $context = []) { | |
// Check if this error level is handled by error reporting | |
if (error_reporting() & $level) { | |
// Return false for any error levels that should | |
// be handled by the built in PHP error handler. | |
if ($level & (E_WARNING | E_NOTICE | E_DEPRECATED)) { | |
echo "<br />\n"; | |
echo "<b>ERROR</b> [$level] $message<br />\n"; | |
echo " Fatal error on line $line in file $file"; | |
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; | |
echo "Aborting...<br />\n"; | |
return false; | |
} | |
// Throw an exception to be handled by Laravel for all other errors. | |
throw new \ErrorException($message, 0, $level, $file, $line); | |
} | |
}); | |
} | |
); | |
} | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
} | |
} |
In your ajax scenario, maybe return with one of these?
if (wp_doing_ajax()) {
...
wp_send_json( $response:mixed, $status_code:integer|null, $options:integer )
wp_send_json_error( $data:mixed|null, $status_code:integer|null, $options:integer )
...
}
Works like a charm Mike... even with Ajax requests without using wp_send_json or wp_send_json_error.
Thank you again ;D
🙏 🙌
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aha yeah I see, how about only outputting to admin_footer/footer and prevent display in ajax, ie. just log to the logfile?
Something like this..
views/admin/error.blade.php