@@ -20,159 +20,159 @@ discard block |
||
20 | 20 | class ExceptionStackTraceDisplay |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - * @since 4.10.24.p |
|
26 | - */ |
|
27 | - private $class_name = ''; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + * @since 4.10.24.p |
|
26 | + */ |
|
27 | + private $class_name = ''; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string |
|
31 | - * @since 4.10.24.p |
|
32 | - */ |
|
33 | - private $error_code = ''; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + * @since 4.10.24.p |
|
32 | + */ |
|
33 | + private $error_code = ''; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param Exception $exception |
|
38 | - * @throws Exception |
|
39 | - */ |
|
40 | - public function __construct(Exception $exception) |
|
41 | - { |
|
42 | - if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
43 | - $this->displayException($exception); |
|
44 | - } else { |
|
45 | - throw $exception; |
|
46 | - } |
|
47 | - } |
|
36 | + /** |
|
37 | + * @param Exception $exception |
|
38 | + * @throws Exception |
|
39 | + */ |
|
40 | + public function __construct(Exception $exception) |
|
41 | + { |
|
42 | + if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
43 | + $this->displayException($exception); |
|
44 | + } else { |
|
45 | + throw $exception; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @access protected |
|
52 | - * @param Exception $exception |
|
53 | - * @throws ReflectionException |
|
54 | - */ |
|
55 | - protected function displayException(Exception $exception) |
|
56 | - { |
|
57 | - // get separate user and developer messages if they exist |
|
58 | - $msg = explode('||', $exception->getMessage()); |
|
59 | - $user_msg = $msg[0]; |
|
60 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
61 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
62 | - // process trace info |
|
63 | - $trace_details = $this->traceDetails($exception); |
|
64 | - $code = $exception->getCode() ?: $this->error_code; |
|
65 | - // add helpful developer messages if debugging is on |
|
66 | - // or generic non-identifying messages for non-privileged users |
|
67 | - $error_message = WP_DEBUG |
|
68 | - ? $this->developerError($exception, $msg, $code, $trace_details) |
|
69 | - : $this->genericError($msg, $code); |
|
70 | - // start gathering output |
|
71 | - $output = ' |
|
50 | + /** |
|
51 | + * @access protected |
|
52 | + * @param Exception $exception |
|
53 | + * @throws ReflectionException |
|
54 | + */ |
|
55 | + protected function displayException(Exception $exception) |
|
56 | + { |
|
57 | + // get separate user and developer messages if they exist |
|
58 | + $msg = explode('||', $exception->getMessage()); |
|
59 | + $user_msg = $msg[0]; |
|
60 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
61 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
62 | + // process trace info |
|
63 | + $trace_details = $this->traceDetails($exception); |
|
64 | + $code = $exception->getCode() ?: $this->error_code; |
|
65 | + // add helpful developer messages if debugging is on |
|
66 | + // or generic non-identifying messages for non-privileged users |
|
67 | + $error_message = WP_DEBUG |
|
68 | + ? $this->developerError($exception, $msg, $code, $trace_details) |
|
69 | + : $this->genericError($msg, $code); |
|
70 | + // start gathering output |
|
71 | + $output = ' |
|
72 | 72 | <div id="ee-error-message" class="error"> |
73 | 73 | ' . $error_message . ' |
74 | 74 | </div>'; |
75 | - $styles = $this->exceptionStyles(); |
|
76 | - $scripts = $this->printScripts(true); |
|
77 | - if (defined('DOING_AJAX')) { |
|
78 | - echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
79 | - exit(); |
|
80 | - } |
|
81 | - echo $styles, $output, $scripts; |
|
82 | - } |
|
75 | + $styles = $this->exceptionStyles(); |
|
76 | + $scripts = $this->printScripts(true); |
|
77 | + if (defined('DOING_AJAX')) { |
|
78 | + echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
79 | + exit(); |
|
80 | + } |
|
81 | + echo $styles, $output, $scripts; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - private function genericError($msg, $code) |
|
86 | - { |
|
87 | - return ' |
|
85 | + private function genericError($msg, $code) |
|
86 | + { |
|
87 | + return ' |
|
88 | 88 | <p> |
89 | 89 | <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
90 | 90 | </p>'; |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * @throws ReflectionException |
|
96 | - */ |
|
97 | - private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
98 | - { |
|
99 | - $time = time(); |
|
100 | - return ' |
|
94 | + /** |
|
95 | + * @throws ReflectionException |
|
96 | + */ |
|
97 | + private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
98 | + { |
|
99 | + $time = time(); |
|
100 | + return ' |
|
101 | 101 | <div class="ee-error-dev-msg-dv"> |
102 | 102 | <p class="ee-error-dev-msg-pg"> |
103 | 103 | ' |
104 | - . sprintf( |
|
105 | - esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
106 | - '<strong class="ee-error-dev-msg-str">', |
|
107 | - get_class($exception), |
|
108 | - '</strong> <span>', |
|
109 | - $code . '</span>' |
|
110 | - ) |
|
111 | - . '<br /> |
|
104 | + . sprintf( |
|
105 | + esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
106 | + '<strong class="ee-error-dev-msg-str">', |
|
107 | + get_class($exception), |
|
108 | + '</strong> <span>', |
|
109 | + $code . '</span>' |
|
110 | + ) |
|
111 | + . '<br /> |
|
112 | 112 | <span class="big-text">"' . trim($msg) . '"</span><br/> |
113 | 113 | <a id="display-ee-error-trace-1' |
114 | - . $time |
|
115 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
116 | - . $time |
|
117 | - . '"> |
|
114 | + . $time |
|
115 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
116 | + . $time |
|
117 | + . '"> |
|
118 | 118 | ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
119 | 119 | </a><br /> |
120 | 120 | ' |
121 | - . $exception->getFile() |
|
122 | - . sprintf( |
|
123 | - esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
124 | - ' <span class="small-text lt-grey-text">', |
|
125 | - $exception->getLine(), |
|
126 | - '</span>' |
|
127 | - ) |
|
128 | - . ' |
|
121 | + . $exception->getFile() |
|
122 | + . sprintf( |
|
123 | + esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
124 | + ' <span class="small-text lt-grey-text">', |
|
125 | + $exception->getLine(), |
|
126 | + '</span>' |
|
127 | + ) |
|
128 | + . ' |
|
129 | 129 | </p> |
130 | 130 | <div id="ee-error-trace-1' |
131 | - . $time |
|
132 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
131 | + . $time |
|
132 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
133 | 133 | ' |
134 | - . $trace_details |
|
135 | - . $this->classDetails() . ' |
|
134 | + . $trace_details |
|
135 | + . $this->classDetails() . ' |
|
136 | 136 | </div> |
137 | 137 | </div>'; |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | 140 | |
141 | - /** |
|
142 | - * @throws ReflectionException |
|
143 | - */ |
|
144 | - private function classDetails() |
|
145 | - { |
|
146 | - if (empty($this->class_name)) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - $a = new ReflectionClass($this->class_name); |
|
150 | - return ' |
|
141 | + /** |
|
142 | + * @throws ReflectionException |
|
143 | + */ |
|
144 | + private function classDetails() |
|
145 | + { |
|
146 | + if (empty($this->class_name)) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + $a = new ReflectionClass($this->class_name); |
|
150 | + return ' |
|
151 | 151 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
152 | 152 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
153 | 153 | <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
154 | 154 | <pre>' . $a . '</pre> |
155 | 155 | </div> |
156 | 156 | </div>'; |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @param Exception $exception |
|
161 | - * @return string |
|
162 | - * @throws ReflectionException |
|
163 | - * @since 4.10.24.p |
|
164 | - */ |
|
165 | - private function traceDetails(Exception $exception) |
|
166 | - { |
|
167 | - $trace = $exception->getTrace(); |
|
168 | - if (empty($trace)) { |
|
169 | - return esc_html__( |
|
170 | - 'Sorry, but no trace information was available for this exception.', |
|
171 | - 'event_espresso' |
|
172 | - ); |
|
173 | - } |
|
159 | + /** |
|
160 | + * @param Exception $exception |
|
161 | + * @return string |
|
162 | + * @throws ReflectionException |
|
163 | + * @since 4.10.24.p |
|
164 | + */ |
|
165 | + private function traceDetails(Exception $exception) |
|
166 | + { |
|
167 | + $trace = $exception->getTrace(); |
|
168 | + if (empty($trace)) { |
|
169 | + return esc_html__( |
|
170 | + 'Sorry, but no trace information was available for this exception.', |
|
171 | + 'event_espresso' |
|
172 | + ); |
|
173 | + } |
|
174 | 174 | |
175 | - $trace_details = ' |
|
175 | + $trace_details = ' |
|
176 | 176 | <div id="ee-trace-details"> |
177 | 177 | <table> |
178 | 178 | <tr> |
@@ -181,160 +181,160 @@ discard block |
||
181 | 181 | <th scope="col" class="ee-align-left" style="width:40%;">File</th> |
182 | 182 | <th scope="col" class="ee-align-left"> |
183 | 183 | ' . esc_html__('Class', 'event_espresso') |
184 | - . '->' |
|
185 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
184 | + . '->' |
|
185 | + . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
186 | 186 | </th> |
187 | 187 | </tr>'; |
188 | - $last_on_stack = count($trace) - 1; |
|
189 | - // reverse array so that stack is in proper chronological order |
|
190 | - $sorted_trace = array_reverse($trace); |
|
191 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
192 | - $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
193 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
194 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
195 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
196 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
197 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
198 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
199 | - if (empty($file) && ! empty($this->class_name)) { |
|
200 | - $a = new ReflectionClass($this->class_name); |
|
201 | - $file = $a->getFileName(); |
|
202 | - if (empty($line) && ! empty($function)) { |
|
203 | - try { |
|
204 | - // if $function is a closure, this throws an exception |
|
205 | - $b = new ReflectionMethod($this->class_name, $function); |
|
206 | - $line = $b->getStartLine(); |
|
207 | - } catch (Exception $closure_exception) { |
|
208 | - $line = 'unknown'; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - if ($nmbr === $last_on_stack) { |
|
213 | - $file = $exception->getFile() ?: $file; |
|
214 | - $line = $exception->getLine() ?: $line; |
|
215 | - $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
216 | - } |
|
217 | - $file = EEH_File::standardise_directory_separators($file); |
|
218 | - $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
219 | - $line = ! empty($line) ? $line : ' '; |
|
220 | - $file = ! empty($file) ? $file : ' '; |
|
221 | - $type = ! empty($type) ? $type : ''; |
|
222 | - $function = ! empty($function) ? $function : ''; |
|
223 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
224 | - $trace_details .= ' |
|
188 | + $last_on_stack = count($trace) - 1; |
|
189 | + // reverse array so that stack is in proper chronological order |
|
190 | + $sorted_trace = array_reverse($trace); |
|
191 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
192 | + $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
193 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
194 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
195 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
196 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
197 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
198 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
199 | + if (empty($file) && ! empty($this->class_name)) { |
|
200 | + $a = new ReflectionClass($this->class_name); |
|
201 | + $file = $a->getFileName(); |
|
202 | + if (empty($line) && ! empty($function)) { |
|
203 | + try { |
|
204 | + // if $function is a closure, this throws an exception |
|
205 | + $b = new ReflectionMethod($this->class_name, $function); |
|
206 | + $line = $b->getStartLine(); |
|
207 | + } catch (Exception $closure_exception) { |
|
208 | + $line = 'unknown'; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + if ($nmbr === $last_on_stack) { |
|
213 | + $file = $exception->getFile() ?: $file; |
|
214 | + $line = $exception->getLine() ?: $line; |
|
215 | + $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
216 | + } |
|
217 | + $file = EEH_File::standardise_directory_separators($file); |
|
218 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
219 | + $line = ! empty($line) ? $line : ' '; |
|
220 | + $file = ! empty($file) ? $file : ' '; |
|
221 | + $type = ! empty($type) ? $type : ''; |
|
222 | + $function = ! empty($function) ? $function : ''; |
|
223 | + $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
224 | + $trace_details .= ' |
|
225 | 225 | <tr> |
226 | 226 | <td class="ee-align-right">' . $nmbr . '</td> |
227 | 227 | <td class="ee-align-right">' . $line . '</td> |
228 | 228 | <td class="ee-align-left">' . $file . '</td> |
229 | 229 | <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
230 | 230 | </tr>'; |
231 | - } |
|
232 | - $trace_details .= ' |
|
231 | + } |
|
232 | + $trace_details .= ' |
|
233 | 233 | </table> |
234 | 234 | </div>'; |
235 | - return $trace_details; |
|
236 | - } |
|
235 | + return $trace_details; |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
240 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
239 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
240 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
241 | 241 | |
242 | - /** |
|
243 | - * generate string from exception trace args |
|
244 | - * |
|
245 | - * @param array $arguments |
|
246 | - * @param int $indent |
|
247 | - * @param bool $array |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
251 | - { |
|
252 | - $args = array(); |
|
253 | - $args_count = count($arguments); |
|
254 | - if ($args_count > 2) { |
|
255 | - $indent++; |
|
256 | - $args[] = '<br />'; |
|
257 | - } |
|
258 | - $x = 0; |
|
259 | - foreach ($arguments as $arg) { |
|
260 | - $x++; |
|
261 | - for ($i = 0; $i < $indent; $i++) { |
|
262 | - $args[] = ' '; |
|
263 | - } |
|
264 | - if (is_string($arg)) { |
|
265 | - if (! $array && strlen($arg) > 75) { |
|
266 | - $args[] = '<br />'; |
|
267 | - for ($i = 0; $i <= $indent; $i++) { |
|
268 | - $args[] = ' '; |
|
269 | - } |
|
270 | - $args[] = "'" . $arg . "'<br />"; |
|
271 | - } else { |
|
272 | - $args[] = " '" . $arg . "'"; |
|
273 | - } |
|
274 | - } elseif (is_array($arg)) { |
|
275 | - $arg_count = count($arg); |
|
276 | - if ($arg_count > 2) { |
|
277 | - $indent++; |
|
278 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
279 | - $indent--; |
|
280 | - } elseif ($arg_count === 0) { |
|
281 | - $args[] = ' array()'; |
|
282 | - } else { |
|
283 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
284 | - } |
|
285 | - } elseif ($arg === null) { |
|
286 | - $args[] = ' null'; |
|
287 | - } elseif (is_bool($arg)) { |
|
288 | - $args[] = $arg ? ' true' : ' false'; |
|
289 | - } elseif (is_object($arg)) { |
|
290 | - $args[] = get_class($arg); |
|
291 | - } elseif (is_resource($arg)) { |
|
292 | - $args[] = get_resource_type($arg); |
|
293 | - } else { |
|
294 | - $args[] = $arg; |
|
295 | - } |
|
296 | - if ($x === $args_count) { |
|
297 | - if ($args_count > 2) { |
|
298 | - $args[] = '<br />'; |
|
299 | - $indent--; |
|
300 | - for ($i = 1; $i < $indent; $i++) { |
|
301 | - $args[] = ' '; |
|
302 | - } |
|
303 | - } |
|
304 | - } else { |
|
305 | - $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
306 | - } |
|
307 | - } |
|
308 | - return implode('', $args); |
|
309 | - } |
|
242 | + /** |
|
243 | + * generate string from exception trace args |
|
244 | + * |
|
245 | + * @param array $arguments |
|
246 | + * @param int $indent |
|
247 | + * @param bool $array |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
251 | + { |
|
252 | + $args = array(); |
|
253 | + $args_count = count($arguments); |
|
254 | + if ($args_count > 2) { |
|
255 | + $indent++; |
|
256 | + $args[] = '<br />'; |
|
257 | + } |
|
258 | + $x = 0; |
|
259 | + foreach ($arguments as $arg) { |
|
260 | + $x++; |
|
261 | + for ($i = 0; $i < $indent; $i++) { |
|
262 | + $args[] = ' '; |
|
263 | + } |
|
264 | + if (is_string($arg)) { |
|
265 | + if (! $array && strlen($arg) > 75) { |
|
266 | + $args[] = '<br />'; |
|
267 | + for ($i = 0; $i <= $indent; $i++) { |
|
268 | + $args[] = ' '; |
|
269 | + } |
|
270 | + $args[] = "'" . $arg . "'<br />"; |
|
271 | + } else { |
|
272 | + $args[] = " '" . $arg . "'"; |
|
273 | + } |
|
274 | + } elseif (is_array($arg)) { |
|
275 | + $arg_count = count($arg); |
|
276 | + if ($arg_count > 2) { |
|
277 | + $indent++; |
|
278 | + $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
279 | + $indent--; |
|
280 | + } elseif ($arg_count === 0) { |
|
281 | + $args[] = ' array()'; |
|
282 | + } else { |
|
283 | + $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
284 | + } |
|
285 | + } elseif ($arg === null) { |
|
286 | + $args[] = ' null'; |
|
287 | + } elseif (is_bool($arg)) { |
|
288 | + $args[] = $arg ? ' true' : ' false'; |
|
289 | + } elseif (is_object($arg)) { |
|
290 | + $args[] = get_class($arg); |
|
291 | + } elseif (is_resource($arg)) { |
|
292 | + $args[] = get_resource_type($arg); |
|
293 | + } else { |
|
294 | + $args[] = $arg; |
|
295 | + } |
|
296 | + if ($x === $args_count) { |
|
297 | + if ($args_count > 2) { |
|
298 | + $args[] = '<br />'; |
|
299 | + $indent--; |
|
300 | + for ($i = 1; $i < $indent; $i++) { |
|
301 | + $args[] = ' '; |
|
302 | + } |
|
303 | + } |
|
304 | + } else { |
|
305 | + $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
306 | + } |
|
307 | + } |
|
308 | + return implode('', $args); |
|
309 | + } |
|
310 | 310 | |
311 | 311 | |
312 | - /** |
|
313 | - * create error code from filepath, function name, |
|
314 | - * and line number where exception or error was thrown |
|
315 | - * |
|
316 | - * @access protected |
|
317 | - * @param string $file |
|
318 | - * @param string $func |
|
319 | - * @param string $line |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - protected function generate_error_code($file = '', $func = '', $line = '') |
|
323 | - { |
|
324 | - $file_bits = explode('.', basename($file)); |
|
325 | - $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
326 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
327 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
328 | - return $error_code; |
|
329 | - } |
|
312 | + /** |
|
313 | + * create error code from filepath, function name, |
|
314 | + * and line number where exception or error was thrown |
|
315 | + * |
|
316 | + * @access protected |
|
317 | + * @param string $file |
|
318 | + * @param string $func |
|
319 | + * @param string $line |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + protected function generate_error_code($file = '', $func = '', $line = '') |
|
323 | + { |
|
324 | + $file_bits = explode('.', basename($file)); |
|
325 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
326 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
327 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
328 | + return $error_code; |
|
329 | + } |
|
330 | 330 | |
331 | 331 | |
332 | - /** |
|
333 | - * @return string |
|
334 | - */ |
|
335 | - private function exceptionStyles() |
|
336 | - { |
|
337 | - return ' |
|
332 | + /** |
|
333 | + * @return string |
|
334 | + */ |
|
335 | + private function exceptionStyles() |
|
336 | + { |
|
337 | + return ' |
|
338 | 338 | <style media="screen"> |
339 | 339 | #ee-error-message { |
340 | 340 | max-width:90% !important; |
@@ -392,34 +392,34 @@ discard block |
||
392 | 392 | color: #999; |
393 | 393 | } |
394 | 394 | </style>'; |
395 | - } |
|
395 | + } |
|
396 | 396 | |
397 | 397 | |
398 | - /** |
|
399 | - * _print_scripts |
|
400 | - * |
|
401 | - * @param bool $force_print |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - private function printScripts($force_print = false) |
|
405 | - { |
|
406 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
407 | - // if script is already enqueued then we can just get out |
|
408 | - if (wp_script_is('ee_error_js')) { |
|
409 | - return ''; |
|
410 | - } |
|
411 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
412 | - wp_enqueue_style('espresso_default'); |
|
413 | - wp_enqueue_style('espresso_custom_css'); |
|
414 | - wp_enqueue_script('ee_error_js'); |
|
415 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
416 | - return ''; |
|
417 | - } |
|
418 | - } |
|
419 | - $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
420 | - $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
421 | - $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
422 | - return ' |
|
398 | + /** |
|
399 | + * _print_scripts |
|
400 | + * |
|
401 | + * @param bool $force_print |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + private function printScripts($force_print = false) |
|
405 | + { |
|
406 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
407 | + // if script is already enqueued then we can just get out |
|
408 | + if (wp_script_is('ee_error_js')) { |
|
409 | + return ''; |
|
410 | + } |
|
411 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
412 | + wp_enqueue_style('espresso_default'); |
|
413 | + wp_enqueue_style('espresso_custom_css'); |
|
414 | + wp_enqueue_script('ee_error_js'); |
|
415 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
416 | + return ''; |
|
417 | + } |
|
418 | + } |
|
419 | + $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
420 | + $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
421 | + $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
422 | + return ' |
|
423 | 423 | <script> |
424 | 424 | /* <![CDATA[ */ |
425 | 425 | const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -429,5 +429,5 @@ discard block |
||
429 | 429 | <script src="' . $core . '" type="text/javascript" ></script> |
430 | 430 | <script src="' . $ee_error . '" type="text/javascript" ></script> |
431 | 431 | '; |
432 | - } |
|
432 | + } |
|
433 | 433 | } |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | // start gathering output |
71 | 71 | $output = ' |
72 | 72 | <div id="ee-error-message" class="error"> |
73 | - ' . $error_message . ' |
|
73 | + ' . $error_message.' |
|
74 | 74 | </div>'; |
75 | 75 | $styles = $this->exceptionStyles(); |
76 | 76 | $scripts = $this->printScripts(true); |
77 | 77 | if (defined('DOING_AJAX')) { |
78 | - echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
78 | + echo wp_json_encode(array('error' => $styles.$output.$scripts)); |
|
79 | 79 | exit(); |
80 | 80 | } |
81 | 81 | echo $styles, $output, $scripts; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | { |
87 | 87 | return ' |
88 | 88 | <p> |
89 | - <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
|
89 | + <span class="ee-error-user-msg-spn">' . trim($msg).'</span> <sup>'.$code.'</sup> |
|
90 | 90 | </p>'; |
91 | 91 | } |
92 | 92 | |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | '<strong class="ee-error-dev-msg-str">', |
107 | 107 | get_class($exception), |
108 | 108 | '</strong> <span>', |
109 | - $code . '</span>' |
|
109 | + $code.'</span>' |
|
110 | 110 | ) |
111 | 111 | . '<br /> |
112 | - <span class="big-text">"' . trim($msg) . '"</span><br/> |
|
112 | + <span class="big-text">"' . trim($msg).'"</span><br/> |
|
113 | 113 | <a id="display-ee-error-trace-1' |
114 | 114 | . $time |
115 | 115 | . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
116 | 116 | . $time |
117 | 117 | . '"> |
118 | - ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
|
118 | + ' . esc_html__('click to view backtrace and class/method details', 'event_espresso').' |
|
119 | 119 | </a><br /> |
120 | 120 | ' |
121 | 121 | . $exception->getFile() |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
133 | 133 | ' |
134 | 134 | . $trace_details |
135 | - . $this->classDetails() . ' |
|
135 | + . $this->classDetails().' |
|
136 | 136 | </div> |
137 | 137 | </div>'; |
138 | 138 | } |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | return ' |
151 | 151 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
152 | 152 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
153 | - <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
|
154 | - <pre>' . $a . '</pre> |
|
153 | + <h3>' . esc_html__('Class Details', 'event_espresso').'</h3> |
|
154 | + <pre>' . $a.'</pre> |
|
155 | 155 | </div> |
156 | 156 | </div>'; |
157 | 157 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | <th scope="col" class="ee-align-left"> |
183 | 183 | ' . esc_html__('Class', 'event_espresso') |
184 | 184 | . '->' |
185 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
185 | + . esc_html__('Method( arguments )', 'event_espresso').' |
|
186 | 186 | </th> |
187 | 187 | </tr>'; |
188 | 188 | $last_on_stack = count($trace) - 1; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $type = isset($trace['type']) ? $trace['type'] : ''; |
195 | 195 | $function = isset($trace['function']) ? $trace['function'] : ''; |
196 | 196 | $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
197 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
197 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args; |
|
198 | 198 | $line = isset($trace['line']) ? $trace['line'] : ''; |
199 | 199 | if (empty($file) && ! empty($this->class_name)) { |
200 | 200 | $a = new ReflectionClass($this->class_name); |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | $file = ! empty($file) ? $file : ' '; |
221 | 221 | $type = ! empty($type) ? $type : ''; |
222 | 222 | $function = ! empty($function) ? $function : ''; |
223 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
223 | + $args = ! empty($args) ? '( '.$args.' )' : '()'; |
|
224 | 224 | $trace_details .= ' |
225 | 225 | <tr> |
226 | - <td class="ee-align-right">' . $nmbr . '</td> |
|
227 | - <td class="ee-align-right">' . $line . '</td> |
|
228 | - <td class="ee-align-left">' . $file . '</td> |
|
229 | - <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
|
226 | + <td class="ee-align-right">' . $nmbr.'</td> |
|
227 | + <td class="ee-align-right">' . $line.'</td> |
|
228 | + <td class="ee-align-left">' . $file.'</td> |
|
229 | + <td class="ee-align-left">' . $this->class_name.$type.$function.$args.'</td> |
|
230 | 230 | </tr>'; |
231 | 231 | } |
232 | 232 | $trace_details .= ' |
@@ -262,25 +262,25 @@ discard block |
||
262 | 262 | $args[] = ' '; |
263 | 263 | } |
264 | 264 | if (is_string($arg)) { |
265 | - if (! $array && strlen($arg) > 75) { |
|
265 | + if ( ! $array && strlen($arg) > 75) { |
|
266 | 266 | $args[] = '<br />'; |
267 | 267 | for ($i = 0; $i <= $indent; $i++) { |
268 | 268 | $args[] = ' '; |
269 | 269 | } |
270 | - $args[] = "'" . $arg . "'<br />"; |
|
270 | + $args[] = "'".$arg."'<br />"; |
|
271 | 271 | } else { |
272 | - $args[] = " '" . $arg . "'"; |
|
272 | + $args[] = " '".$arg."'"; |
|
273 | 273 | } |
274 | 274 | } elseif (is_array($arg)) { |
275 | 275 | $arg_count = count($arg); |
276 | 276 | if ($arg_count > 2) { |
277 | 277 | $indent++; |
278 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
278 | + $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')'; |
|
279 | 279 | $indent--; |
280 | 280 | } elseif ($arg_count === 0) { |
281 | 281 | $args[] = ' array()'; |
282 | 282 | } else { |
283 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
283 | + $args[] = ' array( '.$this->_convert_args_to_string($arg).' )'; |
|
284 | 284 | } |
285 | 285 | } elseif ($arg === null) { |
286 | 286 | $args[] = ' null'; |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | { |
324 | 324 | $file_bits = explode('.', basename($file)); |
325 | 325 | $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
326 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
327 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
326 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
327 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
328 | 328 | return $error_code; |
329 | 329 | } |
330 | 330 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | */ |
404 | 404 | private function printScripts($force_print = false) |
405 | 405 | { |
406 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
406 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
407 | 407 | // if script is already enqueued then we can just get out |
408 | 408 | if (wp_script_is('ee_error_js')) { |
409 | 409 | return ''; |
@@ -416,18 +416,18 @@ discard block |
||
416 | 416 | return ''; |
417 | 417 | } |
418 | 418 | } |
419 | - $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
420 | - $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
421 | - $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
419 | + $jquery = esc_url_raw(includes_url().'js/jquery/jquery.js'); |
|
420 | + $core = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.espresso_version()); |
|
421 | + $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js?ver='.espresso_version()); |
|
422 | 422 | return ' |
423 | 423 | <script> |
424 | 424 | /* <![CDATA[ */ |
425 | -const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
425 | +const ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
426 | 426 | /* ]]> */ |
427 | 427 | </script> |
428 | -<script src="' . $jquery . '" type="text/javascript" ></script> |
|
429 | -<script src="' . $core . '" type="text/javascript" ></script> |
|
430 | -<script src="' . $ee_error . '" type="text/javascript" ></script> |
|
428 | +<script src="' . $jquery.'" type="text/javascript" ></script> |
|
429 | +<script src="' . $core.'" type="text/javascript" ></script> |
|
430 | +<script src="' . $ee_error.'" type="text/javascript" ></script> |
|
431 | 431 | '; |
432 | 432 | } |
433 | 433 | } |