-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log all WP_Error calls, when WP_ENV = 'development' (#557)
Create errors.php
- Loading branch information
1 parent
d23e7c4
commit d05f80a
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* Errors | ||
* Only allowed in development environment. | ||
*/ | ||
|
||
defined('ABSPATH') || exit; | ||
|
||
if (getenv('WP_ENV') !== 'development') { | ||
return; | ||
} | ||
|
||
/** | ||
* wp_error_added | ||
* When WP_Error is called, it is up to the developer to access and handle the error, they are not logged by default. | ||
* This action/function ensures that any errors added to WP_Error will be logged immediately. | ||
*/ | ||
|
||
add_action('wp_error_added', function (string|int $code, string $message, mixed $data, WP_Error $wp_error) { | ||
if (is_array($message) || is_object($message)) { | ||
error_log("Error code: $code. Message: " . print_r($message, true)); | ||
} else { | ||
error_log("Error code: $code. Message: $message"); | ||
} | ||
}, 10, 4); |