@@ -31,13 +31,17 @@ public function handle() {
31
31
}
32
32
33
33
try {
34
- // Bail if no error found or if it could not be stored.
35
- if ( ! $ this ->detect_error () ) {
34
+ // Bail if no error found.
35
+ $ error = $ this ->detect_error ();
36
+ if ( ! $ error ) {
36
37
return ;
37
38
}
38
39
39
- // Redirect the request to catch multiple errors in one go.
40
- $ this ->redirect_protected ();
40
+ // If the error was stored and thus the extension paused,
41
+ // redirect the request to catch multiple errors in one go.
42
+ if ( $ this ->store_error ( $ error ) ) {
43
+ $ this ->redirect_protected ();
44
+ }
41
45
42
46
// Display the PHP error template.
43
47
$ this ->display_error_template ();
@@ -47,26 +51,42 @@ public function handle() {
47
51
}
48
52
49
53
/**
50
- * Detects the error causing the crash and stores it if one was found .
54
+ * Detects the error causing the crash if it should be handled .
51
55
*
52
56
* @since 5.1.0
53
57
*
54
- * @return bool True if an error was found and stored, false otherwise .
58
+ * @return array|null Error that was triggered, or null if no error received or if the error should not be handled .
55
59
*/
56
60
protected function detect_error () {
57
61
$ error = error_get_last ();
58
62
59
63
// No error, just skip the error handling code.
60
64
if ( null === $ error ) {
61
- return false ;
65
+ return null ;
62
66
}
63
67
64
68
// Bail if this error should not be handled.
65
69
if ( ! wp_should_handle_error ( $ error ) ) {
70
+ return null ;
71
+ }
72
+
73
+ return $ error ;
74
+ }
75
+
76
+ /**
77
+ * Stores the given error so that the extension causing it is paused.
78
+ *
79
+ * @since 5.1.0
80
+ *
81
+ * @param array $error Error that was triggered.
82
+ * @return bool True if the error was stored successfully, false otherwise.
83
+ */
84
+ protected function store_error ( $ error ) {
85
+ // Do not pause extensions if they only crash on a non-protected endpoint.
86
+ if ( ! is_protected_endpoint () ) {
66
87
return false ;
67
88
}
68
89
69
- // Try to store the error so that the respective extension is paused.
70
90
return wp_record_extension_error ( $ error );
71
91
}
72
92
0 commit comments