@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,256 +27,256 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * error_handler |
|
80 | - * |
|
81 | - * @param $code |
|
82 | - * @param $message |
|
83 | - * @param $file |
|
84 | - * @param $line |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public static function error_handler($code, $message, $file, $line) |
|
88 | - { |
|
89 | - $type = EE_Error::error_type($code); |
|
90 | - $site = site_url(); |
|
91 | - switch ($site) { |
|
92 | - case 'http://ee4.eventespresso.com/' : |
|
93 | - case 'http://ee4decaf.eventespresso.com/' : |
|
94 | - case 'http://ee4hf.eventespresso.com/' : |
|
95 | - case 'http://ee4a.eventespresso.com/' : |
|
96 | - case 'http://ee4ad.eventespresso.com/' : |
|
97 | - case 'http://ee4b.eventespresso.com/' : |
|
98 | - case 'http://ee4bd.eventespresso.com/' : |
|
99 | - case 'http://ee4d.eventespresso.com/' : |
|
100 | - case 'http://ee4dd.eventespresso.com/' : |
|
101 | - $to = '[email protected]'; |
|
102 | - break; |
|
103 | - default : |
|
104 | - $to = get_option('admin_email'); |
|
105 | - } |
|
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | - if (function_exists('wp_mail')) { |
|
109 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | - wp_mail($to, $subject, $msg); |
|
111 | - } |
|
112 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | - echo '<br /></p></div>'; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * error_type |
|
121 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | - * |
|
123 | - * @param $code |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function error_type($code) |
|
127 | - { |
|
128 | - switch ($code) { |
|
129 | - case E_ERROR: // 1 // |
|
130 | - return 'E_ERROR'; |
|
131 | - case E_WARNING: // 2 // |
|
132 | - return 'E_WARNING'; |
|
133 | - case E_PARSE: // 4 // |
|
134 | - return 'E_PARSE'; |
|
135 | - case E_NOTICE: // 8 // |
|
136 | - return 'E_NOTICE'; |
|
137 | - case E_CORE_ERROR: // 16 // |
|
138 | - return 'E_CORE_ERROR'; |
|
139 | - case E_CORE_WARNING: // 32 // |
|
140 | - return 'E_CORE_WARNING'; |
|
141 | - case E_COMPILE_ERROR: // 64 // |
|
142 | - return 'E_COMPILE_ERROR'; |
|
143 | - case E_COMPILE_WARNING: // 128 // |
|
144 | - return 'E_COMPILE_WARNING'; |
|
145 | - case E_USER_ERROR: // 256 // |
|
146 | - return 'E_USER_ERROR'; |
|
147 | - case E_USER_WARNING: // 512 // |
|
148 | - return 'E_USER_WARNING'; |
|
149 | - case E_USER_NOTICE: // 1024 // |
|
150 | - return 'E_USER_NOTICE'; |
|
151 | - case E_STRICT: // 2048 // |
|
152 | - return 'E_STRICT'; |
|
153 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | - return 'E_RECOVERABLE_ERROR'; |
|
155 | - case E_DEPRECATED: // 8192 // |
|
156 | - return 'E_DEPRECATED'; |
|
157 | - case E_USER_DEPRECATED: // 16384 // |
|
158 | - return 'E_USER_DEPRECATED'; |
|
159 | - case E_ALL: // 16384 // |
|
160 | - return 'E_ALL'; |
|
161 | - } |
|
162 | - return ''; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * fatal_error_handler |
|
169 | - * |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function fatal_error_handler() |
|
173 | - { |
|
174 | - $last_error = error_get_last(); |
|
175 | - if ($last_error['type'] === E_ERROR) { |
|
176 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * _format_error |
|
184 | - * |
|
185 | - * @param $code |
|
186 | - * @param $message |
|
187 | - * @param $file |
|
188 | - * @param $line |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - private static function _format_error($code, $message, $file, $line) |
|
192 | - { |
|
193 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | - $html .= '</tbody></table>'; |
|
199 | - return $html; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * set_content_type |
|
206 | - * |
|
207 | - * @param $content_type |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function set_content_type($content_type) |
|
211 | - { |
|
212 | - return 'text/html'; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @throws EE_Error |
|
220 | - * @throws ReflectionException |
|
221 | - */ |
|
222 | - public function get_error() |
|
223 | - { |
|
224 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | - throw $this; |
|
226 | - } |
|
227 | - // get separate user and developer messages if they exist |
|
228 | - $msg = explode('||', $this->getMessage()); |
|
229 | - $user_msg = $msg[0]; |
|
230 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | - // add details to _all_exceptions array |
|
233 | - $x_time = time(); |
|
234 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | - self::$_error_count++; |
|
242 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | - $this->display_errors(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @param bool $check_stored |
|
250 | - * @param string $type_to_check |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | - { |
|
255 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | - ? true |
|
258 | - : false; |
|
259 | - if ($check_stored && ! $has_error) { |
|
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | - foreach ($notices as $type => $notice) { |
|
262 | - if ($type === $type_to_check && $notice) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - return $has_error; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @echo string |
|
274 | - * @throws \ReflectionException |
|
275 | - */ |
|
276 | - public function display_errors() |
|
277 | - { |
|
278 | - $trace_details = ''; |
|
279 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * error_handler |
|
80 | + * |
|
81 | + * @param $code |
|
82 | + * @param $message |
|
83 | + * @param $file |
|
84 | + * @param $line |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public static function error_handler($code, $message, $file, $line) |
|
88 | + { |
|
89 | + $type = EE_Error::error_type($code); |
|
90 | + $site = site_url(); |
|
91 | + switch ($site) { |
|
92 | + case 'http://ee4.eventespresso.com/' : |
|
93 | + case 'http://ee4decaf.eventespresso.com/' : |
|
94 | + case 'http://ee4hf.eventespresso.com/' : |
|
95 | + case 'http://ee4a.eventespresso.com/' : |
|
96 | + case 'http://ee4ad.eventespresso.com/' : |
|
97 | + case 'http://ee4b.eventespresso.com/' : |
|
98 | + case 'http://ee4bd.eventespresso.com/' : |
|
99 | + case 'http://ee4d.eventespresso.com/' : |
|
100 | + case 'http://ee4dd.eventespresso.com/' : |
|
101 | + $to = '[email protected]'; |
|
102 | + break; |
|
103 | + default : |
|
104 | + $to = get_option('admin_email'); |
|
105 | + } |
|
106 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | + if (function_exists('wp_mail')) { |
|
109 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | + wp_mail($to, $subject, $msg); |
|
111 | + } |
|
112 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | + echo '<br /></p></div>'; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * error_type |
|
121 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | + * |
|
123 | + * @param $code |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function error_type($code) |
|
127 | + { |
|
128 | + switch ($code) { |
|
129 | + case E_ERROR: // 1 // |
|
130 | + return 'E_ERROR'; |
|
131 | + case E_WARNING: // 2 // |
|
132 | + return 'E_WARNING'; |
|
133 | + case E_PARSE: // 4 // |
|
134 | + return 'E_PARSE'; |
|
135 | + case E_NOTICE: // 8 // |
|
136 | + return 'E_NOTICE'; |
|
137 | + case E_CORE_ERROR: // 16 // |
|
138 | + return 'E_CORE_ERROR'; |
|
139 | + case E_CORE_WARNING: // 32 // |
|
140 | + return 'E_CORE_WARNING'; |
|
141 | + case E_COMPILE_ERROR: // 64 // |
|
142 | + return 'E_COMPILE_ERROR'; |
|
143 | + case E_COMPILE_WARNING: // 128 // |
|
144 | + return 'E_COMPILE_WARNING'; |
|
145 | + case E_USER_ERROR: // 256 // |
|
146 | + return 'E_USER_ERROR'; |
|
147 | + case E_USER_WARNING: // 512 // |
|
148 | + return 'E_USER_WARNING'; |
|
149 | + case E_USER_NOTICE: // 1024 // |
|
150 | + return 'E_USER_NOTICE'; |
|
151 | + case E_STRICT: // 2048 // |
|
152 | + return 'E_STRICT'; |
|
153 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | + return 'E_RECOVERABLE_ERROR'; |
|
155 | + case E_DEPRECATED: // 8192 // |
|
156 | + return 'E_DEPRECATED'; |
|
157 | + case E_USER_DEPRECATED: // 16384 // |
|
158 | + return 'E_USER_DEPRECATED'; |
|
159 | + case E_ALL: // 16384 // |
|
160 | + return 'E_ALL'; |
|
161 | + } |
|
162 | + return ''; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * fatal_error_handler |
|
169 | + * |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function fatal_error_handler() |
|
173 | + { |
|
174 | + $last_error = error_get_last(); |
|
175 | + if ($last_error['type'] === E_ERROR) { |
|
176 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * _format_error |
|
184 | + * |
|
185 | + * @param $code |
|
186 | + * @param $message |
|
187 | + * @param $file |
|
188 | + * @param $line |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + private static function _format_error($code, $message, $file, $line) |
|
192 | + { |
|
193 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | + $html .= '</tbody></table>'; |
|
199 | + return $html; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * set_content_type |
|
206 | + * |
|
207 | + * @param $content_type |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function set_content_type($content_type) |
|
211 | + { |
|
212 | + return 'text/html'; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @throws EE_Error |
|
220 | + * @throws ReflectionException |
|
221 | + */ |
|
222 | + public function get_error() |
|
223 | + { |
|
224 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | + throw $this; |
|
226 | + } |
|
227 | + // get separate user and developer messages if they exist |
|
228 | + $msg = explode('||', $this->getMessage()); |
|
229 | + $user_msg = $msg[0]; |
|
230 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | + // add details to _all_exceptions array |
|
233 | + $x_time = time(); |
|
234 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_error_count++; |
|
242 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | + $this->display_errors(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @param bool $check_stored |
|
250 | + * @param string $type_to_check |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | + { |
|
255 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | + ? true |
|
258 | + : false; |
|
259 | + if ($check_stored && ! $has_error) { |
|
260 | + $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | + foreach ($notices as $type => $notice) { |
|
262 | + if ($type === $type_to_check && $notice) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + return $has_error; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @echo string |
|
274 | + * @throws \ReflectionException |
|
275 | + */ |
|
276 | + public function display_errors() |
|
277 | + { |
|
278 | + $trace_details = ''; |
|
279 | + $output = ' |
|
280 | 280 | <style type="text/css"> |
281 | 281 | #ee-error-message { |
282 | 282 | max-width:90% !important; |
@@ -332,21 +332,21 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
336 | - $output .= ' |
|
335 | + if (! WP_DEBUG) { |
|
336 | + $output .= ' |
|
337 | 337 | <p>'; |
338 | - } |
|
339 | - // cycle thru errors |
|
340 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | - $error_code = ''; |
|
342 | - // process trace info |
|
343 | - if (empty($ex['trace'])) { |
|
344 | - $trace_details .= __( |
|
345 | - 'Sorry, but no trace information was available for this exception.', |
|
346 | - 'event_espresso' |
|
347 | - ); |
|
348 | - } else { |
|
349 | - $trace_details .= ' |
|
338 | + } |
|
339 | + // cycle thru errors |
|
340 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | + $error_code = ''; |
|
342 | + // process trace info |
|
343 | + if (empty($ex['trace'])) { |
|
344 | + $trace_details .= __( |
|
345 | + 'Sorry, but no trace information was available for this exception.', |
|
346 | + 'event_espresso' |
|
347 | + ); |
|
348 | + } else { |
|
349 | + $trace_details .= ' |
|
350 | 350 | <div id="ee-trace-details"> |
351 | 351 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
352 | 352 | <tr> |
@@ -356,43 +356,43 @@ discard block |
||
356 | 356 | <th scope="col" align="left">Class</th> |
357 | 357 | <th scope="col" align="left">Method( arguments )</th> |
358 | 358 | </tr>'; |
359 | - $last_on_stack = count($ex['trace']) - 1; |
|
360 | - // reverse array so that stack is in proper chronological order |
|
361 | - $sorted_trace = array_reverse($ex['trace']); |
|
362 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | - if (empty($file) && ! empty($class)) { |
|
371 | - $a = new ReflectionClass($class); |
|
372 | - $file = $a->getFileName(); |
|
373 | - if (empty($line) && ! empty($function)) { |
|
374 | - try { |
|
375 | - //if $function is a closure, this throws an exception |
|
376 | - $b = new ReflectionMethod($class, $function); |
|
377 | - $line = $b->getStartLine(); |
|
378 | - } catch (Exception $closure_exception) { |
|
379 | - $line = 'unknown'; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - if ($nmbr === $last_on_stack) { |
|
384 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | - } |
|
388 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | - $trace_details .= ' |
|
359 | + $last_on_stack = count($ex['trace']) - 1; |
|
360 | + // reverse array so that stack is in proper chronological order |
|
361 | + $sorted_trace = array_reverse($ex['trace']); |
|
362 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | + if (empty($file) && ! empty($class)) { |
|
371 | + $a = new ReflectionClass($class); |
|
372 | + $file = $a->getFileName(); |
|
373 | + if (empty($line) && ! empty($function)) { |
|
374 | + try { |
|
375 | + //if $function is a closure, this throws an exception |
|
376 | + $b = new ReflectionMethod($class, $function); |
|
377 | + $line = $b->getStartLine(); |
|
378 | + } catch (Exception $closure_exception) { |
|
379 | + $line = 'unknown'; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + if ($nmbr === $last_on_stack) { |
|
384 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | + } |
|
388 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | + $trace_details .= ' |
|
396 | 396 | <tr> |
397 | 397 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
398 | 398 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -400,523 +400,523 @@ discard block |
||
400 | 400 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
401 | 401 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
402 | 402 | </tr>'; |
403 | - } |
|
404 | - $trace_details .= ' |
|
403 | + } |
|
404 | + $trace_details .= ' |
|
405 | 405 | </table> |
406 | 406 | </div>'; |
407 | - } |
|
408 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | - // add generic non-identifying messages for non-privileged users |
|
410 | - if (! WP_DEBUG) { |
|
411 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | - . trim($ex['msg']) |
|
413 | - . '</span> <sup>' |
|
414 | - . $ex['code'] |
|
415 | - . '</sup><br />'; |
|
416 | - } else { |
|
417 | - // or helpful developer messages if debugging is on |
|
418 | - $output .= ' |
|
407 | + } |
|
408 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | + // add generic non-identifying messages for non-privileged users |
|
410 | + if (! WP_DEBUG) { |
|
411 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | + . trim($ex['msg']) |
|
413 | + . '</span> <sup>' |
|
414 | + . $ex['code'] |
|
415 | + . '</sup><br />'; |
|
416 | + } else { |
|
417 | + // or helpful developer messages if debugging is on |
|
418 | + $output .= ' |
|
419 | 419 | <div class="ee-error-dev-msg-dv"> |
420 | 420 | <p class="ee-error-dev-msg-pg"> |
421 | 421 | <strong class="ee-error-dev-msg-str">An ' |
422 | - . $ex['name'] |
|
423 | - . ' exception was thrown!</strong> <span>code: ' |
|
424 | - . $ex['code'] |
|
425 | - . '</span><br /> |
|
422 | + . $ex['name'] |
|
423 | + . ' exception was thrown!</strong> <span>code: ' |
|
424 | + . $ex['code'] |
|
425 | + . '</span><br /> |
|
426 | 426 | <span class="big-text">"' |
427 | - . trim($ex['msg']) |
|
428 | - . '"</span><br/> |
|
427 | + . trim($ex['msg']) |
|
428 | + . '"</span><br/> |
|
429 | 429 | <a id="display-ee-error-trace-' |
430 | - . self::$_error_count |
|
431 | - . $time |
|
432 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | - . self::$_error_count |
|
434 | - . $time |
|
435 | - . '"> |
|
430 | + . self::$_error_count |
|
431 | + . $time |
|
432 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | + . self::$_error_count |
|
434 | + . $time |
|
435 | + . '"> |
|
436 | 436 | ' |
437 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | - . ' |
|
437 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | + . ' |
|
439 | 439 | </a><br /> |
440 | 440 | <span class="small-text lt-grey-text">' |
441 | - . $ex['file'] |
|
442 | - . ' ( line no: ' |
|
443 | - . $ex['line'] |
|
444 | - . ' )</span> |
|
441 | + . $ex['file'] |
|
442 | + . ' ( line no: ' |
|
443 | + . $ex['line'] |
|
444 | + . ' )</span> |
|
445 | 445 | </p> |
446 | 446 | <div id="ee-error-trace-' |
447 | - . self::$_error_count |
|
448 | - . $time |
|
449 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
447 | + . self::$_error_count |
|
448 | + . $time |
|
449 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
450 | 450 | ' |
451 | - . $trace_details; |
|
452 | - if (! empty($class)) { |
|
453 | - $output .= ' |
|
451 | + . $trace_details; |
|
452 | + if (! empty($class)) { |
|
453 | + $output .= ' |
|
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | - $a = new ReflectionClass($class); |
|
458 | - $output .= ' |
|
457 | + $a = new ReflectionClass($class); |
|
458 | + $output .= ' |
|
459 | 459 | <pre>' . $a . '</pre> |
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | - } |
|
463 | - $output .= ' |
|
462 | + } |
|
463 | + $output .= ' |
|
464 | 464 | </div> |
465 | 465 | </div> |
466 | 466 | <br />'; |
467 | - } |
|
468 | - $this->write_to_error_log($time, $ex); |
|
469 | - } |
|
470 | - // remove last linebreak |
|
471 | - $output = substr($output, 0, -6); |
|
472 | - if (! WP_DEBUG) { |
|
473 | - $output .= ' |
|
467 | + } |
|
468 | + $this->write_to_error_log($time, $ex); |
|
469 | + } |
|
470 | + // remove last linebreak |
|
471 | + $output = substr($output, 0, -6); |
|
472 | + if (! WP_DEBUG) { |
|
473 | + $output .= ' |
|
474 | 474 | </p>'; |
475 | - } |
|
476 | - $output .= ' |
|
475 | + } |
|
476 | + $output .= ' |
|
477 | 477 | </div>'; |
478 | - $output .= self::_print_scripts(true); |
|
479 | - if (defined('DOING_AJAX')) { |
|
480 | - echo wp_json_encode(array('error' => $output)); |
|
481 | - exit(); |
|
482 | - } |
|
483 | - echo $output; |
|
484 | - die(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * generate string from exception trace args |
|
491 | - * |
|
492 | - * @param array $arguments |
|
493 | - * @param bool $array |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | - { |
|
498 | - $arg_string = ''; |
|
499 | - if (! empty($arguments)) { |
|
500 | - $args = array(); |
|
501 | - foreach ($arguments as $arg) { |
|
502 | - if (! empty($arg)) { |
|
503 | - if (is_string($arg)) { |
|
504 | - $args[] = " '" . $arg . "'"; |
|
505 | - } elseif (is_array($arg)) { |
|
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | - } elseif ($arg === null) { |
|
508 | - $args[] = ' NULL'; |
|
509 | - } elseif (is_bool($arg)) { |
|
510 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | - } elseif (is_object($arg)) { |
|
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
513 | - } elseif (is_resource($arg)) { |
|
514 | - $args[] = get_resource_type($arg); |
|
515 | - } else { |
|
516 | - $args[] = $arg; |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - $arg_string = implode(', ', $args); |
|
521 | - } |
|
522 | - if ($array) { |
|
523 | - $arg_string .= ' )'; |
|
524 | - } |
|
525 | - return $arg_string; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * add error message |
|
532 | - * |
|
533 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | - * separate messages for user || dev |
|
535 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | - { |
|
542 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | - self::$_error_count++; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | - * adds an error |
|
551 | - * |
|
552 | - * @param string $msg |
|
553 | - * @param string $file |
|
554 | - * @param string $func |
|
555 | - * @param string $line |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | - { |
|
560 | - if (WP_DEBUG) { |
|
561 | - throw new EE_Error($msg); |
|
562 | - } |
|
563 | - EE_Error::add_error($msg, $file, $func, $line); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * add success message |
|
570 | - * |
|
571 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | - * separate messages for user || dev |
|
573 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | - { |
|
580 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * add attention message |
|
587 | - * |
|
588 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | - * separate messages for user || dev |
|
590 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | - { |
|
597 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param string $type whether the message is for a success or error notification |
|
604 | - * @param string $msg the message to display to users or developers |
|
605 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | - * @return void |
|
610 | - */ |
|
611 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | - { |
|
613 | - if (empty($msg)) { |
|
614 | - EE_Error::doing_it_wrong( |
|
615 | - 'EE_Error::add_' . $type . '()', |
|
616 | - sprintf( |
|
617 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | - 'event_espresso'), |
|
619 | - $type, |
|
620 | - $file, |
|
621 | - $line |
|
622 | - ), |
|
623 | - EVENT_ESPRESSO_VERSION |
|
624 | - ); |
|
625 | - } |
|
626 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | - EE_Error::doing_it_wrong( |
|
628 | - 'EE_Error::add_error()', |
|
629 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | - 'event_espresso'), |
|
631 | - EVENT_ESPRESSO_VERSION |
|
632 | - ); |
|
633 | - } |
|
634 | - // get separate user and developer messages if they exist |
|
635 | - $msg = explode('||', $msg); |
|
636 | - $user_msg = $msg[0]; |
|
637 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | - /** |
|
639 | - * Do an action so other code can be triggered when a notice is created |
|
640 | - * |
|
641 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | - * @param string $file file where error was generated |
|
645 | - * @param string $func function where error was generated |
|
646 | - * @param string $line line where error was generated |
|
647 | - */ |
|
648 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | - // add notice if message exists |
|
651 | - if (! empty($msg)) { |
|
652 | - // get error code |
|
653 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | - if (WP_DEBUG && $type === 'errors') { |
|
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | - } |
|
657 | - // add notice. Index by code if it's not blank |
|
658 | - if ($notice_code) { |
|
659 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | - } else { |
|
661 | - self::$_espresso_notices[$type][] = $msg; |
|
662 | - } |
|
663 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * in some case it may be necessary to overwrite the existing success messages |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public static function overwrite_success() |
|
674 | - { |
|
675 | - self::$_espresso_notices['success'] = false; |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * in some case it may be necessary to overwrite the existing attention messages |
|
682 | - * |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - public static function overwrite_attention() |
|
686 | - { |
|
687 | - self::$_espresso_notices['attention'] = false; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * in some case it may be necessary to overwrite the existing error messages |
|
694 | - * |
|
695 | - * @return void |
|
696 | - */ |
|
697 | - public static function overwrite_errors() |
|
698 | - { |
|
699 | - self::$_espresso_notices['errors'] = false; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @return void |
|
706 | - */ |
|
707 | - public static function reset_notices() |
|
708 | - { |
|
709 | - self::$_espresso_notices['success'] = false; |
|
710 | - self::$_espresso_notices['attention'] = false; |
|
711 | - self::$_espresso_notices['errors'] = false; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @return int |
|
718 | - */ |
|
719 | - public static function has_notices() |
|
720 | - { |
|
721 | - $has_notices = 0; |
|
722 | - // check for success messages |
|
723 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | - ? 3 |
|
725 | - : $has_notices; |
|
726 | - // check for attention messages |
|
727 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | - ? 2 |
|
729 | - : $has_notices; |
|
730 | - // check for error messages |
|
731 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | - ? 1 |
|
733 | - : $has_notices; |
|
734 | - return $has_notices; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | - * |
|
741 | - * @since 4.9.0 |
|
742 | - * @return array |
|
743 | - */ |
|
744 | - public static function get_vanilla_notices() |
|
745 | - { |
|
746 | - return array( |
|
747 | - 'success' => isset(self::$_espresso_notices['success']) |
|
748 | - ? self::$_espresso_notices['success'] |
|
749 | - : array(), |
|
750 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | - ? self::$_espresso_notices['attention'] |
|
752 | - : array(), |
|
753 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | - ? self::$_espresso_notices['errors'] |
|
755 | - : array(), |
|
756 | - ); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * compile all error or success messages into one string |
|
763 | - * |
|
764 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | - * - ONLY do this just before redirecting |
|
768 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | - * @return array |
|
770 | - */ |
|
771 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | - { |
|
773 | - // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | - $success_messages = ''; |
|
775 | - $attention_messages = ''; |
|
776 | - $error_messages = ''; |
|
777 | - $print_scripts = false; |
|
778 | - // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | - // either save notices to the db |
|
780 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | - self::$_espresso_notices = array_merge( |
|
784 | - $existing_notices, |
|
785 | - self::$_espresso_notices |
|
786 | - ); |
|
787 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | - return array(); |
|
789 | - } |
|
790 | - // grab any notices that have been previously saved |
|
791 | - if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | - foreach ($notices as $type => $notice) { |
|
793 | - if (is_array($notice) && ! empty($notice)) { |
|
794 | - // make sure that existing notice type is an array |
|
795 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | - && ! empty(self::$_espresso_notices[$type]) |
|
797 | - ? self::$_espresso_notices[$type] |
|
798 | - : array(); |
|
799 | - // merge stored notices with any newly created ones |
|
800 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | - $print_scripts = true; |
|
802 | - } |
|
803 | - } |
|
804 | - // now clear any stored notices |
|
805 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | - } |
|
807 | - // check for success messages |
|
808 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | - // combine messages |
|
810 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | - $print_scripts = true; |
|
812 | - } |
|
813 | - // check for attention messages |
|
814 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | - // combine messages |
|
816 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | - $print_scripts = true; |
|
818 | - } |
|
819 | - // check for error messages |
|
820 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | - // combine messages |
|
825 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | - $print_scripts = true; |
|
827 | - } |
|
828 | - if ($format_output) { |
|
829 | - |
|
830 | - $notices = '<div id="espresso-notices">'; |
|
831 | - $close = is_admin() ? '' |
|
832 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | - if ($success_messages !== '') { |
|
834 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
835 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | - //showMessage( $success_messages ); |
|
837 | - $notices .= '<div id="' |
|
838 | - . $css_id |
|
839 | - . '" class="espresso-notices ' |
|
840 | - . $css_class |
|
841 | - . '" style="display:none;"><p>' |
|
842 | - . $success_messages |
|
843 | - . '</p>' |
|
844 | - . $close |
|
845 | - . '</div>'; |
|
846 | - } |
|
847 | - if ($attention_messages !== '') { |
|
848 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
849 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | - //showMessage( $error_messages, TRUE ); |
|
851 | - $notices .= '<div id="' |
|
852 | - . $css_id |
|
853 | - . '" class="espresso-notices ' |
|
854 | - . $css_class |
|
855 | - . '" style="display:none;"><p>' |
|
856 | - . $attention_messages |
|
857 | - . '</p>' |
|
858 | - . $close |
|
859 | - . '</div>'; |
|
860 | - } |
|
861 | - if ($error_messages !== '') { |
|
862 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
863 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | - //showMessage( $error_messages, TRUE ); |
|
865 | - $notices .= '<div id="' |
|
866 | - . $css_id |
|
867 | - . '" class="espresso-notices ' |
|
868 | - . $css_class |
|
869 | - . '" style="display:none;"><p>' |
|
870 | - . $error_messages |
|
871 | - . '</p>' |
|
872 | - . $close |
|
873 | - . '</div>'; |
|
874 | - } |
|
875 | - $notices .= '</div>'; |
|
876 | - } else { |
|
877 | - |
|
878 | - $notices = array( |
|
879 | - 'success' => $success_messages, |
|
880 | - 'attention' => $attention_messages, |
|
881 | - 'errors' => $error_messages, |
|
882 | - ); |
|
883 | - if ($remove_empty) { |
|
884 | - // remove empty notices |
|
885 | - foreach ($notices as $type => $notice) { |
|
886 | - if (empty($notice)) { |
|
887 | - unset($notices[$type]); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - if ($print_scripts) { |
|
893 | - self::_print_scripts(); |
|
894 | - } |
|
895 | - return $notices; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * _print_scripts |
|
902 | - * |
|
903 | - * @param bool $force_print |
|
904 | - * @return string |
|
905 | - */ |
|
906 | - private static function _print_scripts($force_print = false) |
|
907 | - { |
|
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | - return ''; |
|
911 | - } |
|
912 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | - wp_enqueue_style('espresso_default'); |
|
914 | - wp_enqueue_style('espresso_custom_css'); |
|
915 | - wp_enqueue_script('ee_error_js'); |
|
916 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | - } |
|
918 | - } else { |
|
919 | - return ' |
|
478 | + $output .= self::_print_scripts(true); |
|
479 | + if (defined('DOING_AJAX')) { |
|
480 | + echo wp_json_encode(array('error' => $output)); |
|
481 | + exit(); |
|
482 | + } |
|
483 | + echo $output; |
|
484 | + die(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * generate string from exception trace args |
|
491 | + * |
|
492 | + * @param array $arguments |
|
493 | + * @param bool $array |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | + { |
|
498 | + $arg_string = ''; |
|
499 | + if (! empty($arguments)) { |
|
500 | + $args = array(); |
|
501 | + foreach ($arguments as $arg) { |
|
502 | + if (! empty($arg)) { |
|
503 | + if (is_string($arg)) { |
|
504 | + $args[] = " '" . $arg . "'"; |
|
505 | + } elseif (is_array($arg)) { |
|
506 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | + } elseif ($arg === null) { |
|
508 | + $args[] = ' NULL'; |
|
509 | + } elseif (is_bool($arg)) { |
|
510 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | + } elseif (is_object($arg)) { |
|
512 | + $args[] = ' OBJECT ' . get_class($arg); |
|
513 | + } elseif (is_resource($arg)) { |
|
514 | + $args[] = get_resource_type($arg); |
|
515 | + } else { |
|
516 | + $args[] = $arg; |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + $arg_string = implode(', ', $args); |
|
521 | + } |
|
522 | + if ($array) { |
|
523 | + $arg_string .= ' )'; |
|
524 | + } |
|
525 | + return $arg_string; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * add error message |
|
532 | + * |
|
533 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | + * separate messages for user || dev |
|
535 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | + { |
|
542 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | + self::$_error_count++; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | + * adds an error |
|
551 | + * |
|
552 | + * @param string $msg |
|
553 | + * @param string $file |
|
554 | + * @param string $func |
|
555 | + * @param string $line |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | + { |
|
560 | + if (WP_DEBUG) { |
|
561 | + throw new EE_Error($msg); |
|
562 | + } |
|
563 | + EE_Error::add_error($msg, $file, $func, $line); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * add success message |
|
570 | + * |
|
571 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | + * separate messages for user || dev |
|
573 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | + { |
|
580 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * add attention message |
|
587 | + * |
|
588 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | + * separate messages for user || dev |
|
590 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | + { |
|
597 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param string $type whether the message is for a success or error notification |
|
604 | + * @param string $msg the message to display to users or developers |
|
605 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | + * @return void |
|
610 | + */ |
|
611 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | + { |
|
613 | + if (empty($msg)) { |
|
614 | + EE_Error::doing_it_wrong( |
|
615 | + 'EE_Error::add_' . $type . '()', |
|
616 | + sprintf( |
|
617 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | + 'event_espresso'), |
|
619 | + $type, |
|
620 | + $file, |
|
621 | + $line |
|
622 | + ), |
|
623 | + EVENT_ESPRESSO_VERSION |
|
624 | + ); |
|
625 | + } |
|
626 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | + EE_Error::doing_it_wrong( |
|
628 | + 'EE_Error::add_error()', |
|
629 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | + 'event_espresso'), |
|
631 | + EVENT_ESPRESSO_VERSION |
|
632 | + ); |
|
633 | + } |
|
634 | + // get separate user and developer messages if they exist |
|
635 | + $msg = explode('||', $msg); |
|
636 | + $user_msg = $msg[0]; |
|
637 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | + /** |
|
639 | + * Do an action so other code can be triggered when a notice is created |
|
640 | + * |
|
641 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | + * @param string $file file where error was generated |
|
645 | + * @param string $func function where error was generated |
|
646 | + * @param string $line line where error was generated |
|
647 | + */ |
|
648 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | + // add notice if message exists |
|
651 | + if (! empty($msg)) { |
|
652 | + // get error code |
|
653 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | + if (WP_DEBUG && $type === 'errors') { |
|
655 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | + } |
|
657 | + // add notice. Index by code if it's not blank |
|
658 | + if ($notice_code) { |
|
659 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | + } else { |
|
661 | + self::$_espresso_notices[$type][] = $msg; |
|
662 | + } |
|
663 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * in some case it may be necessary to overwrite the existing success messages |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public static function overwrite_success() |
|
674 | + { |
|
675 | + self::$_espresso_notices['success'] = false; |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * in some case it may be necessary to overwrite the existing attention messages |
|
682 | + * |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + public static function overwrite_attention() |
|
686 | + { |
|
687 | + self::$_espresso_notices['attention'] = false; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * in some case it may be necessary to overwrite the existing error messages |
|
694 | + * |
|
695 | + * @return void |
|
696 | + */ |
|
697 | + public static function overwrite_errors() |
|
698 | + { |
|
699 | + self::$_espresso_notices['errors'] = false; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @return void |
|
706 | + */ |
|
707 | + public static function reset_notices() |
|
708 | + { |
|
709 | + self::$_espresso_notices['success'] = false; |
|
710 | + self::$_espresso_notices['attention'] = false; |
|
711 | + self::$_espresso_notices['errors'] = false; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @return int |
|
718 | + */ |
|
719 | + public static function has_notices() |
|
720 | + { |
|
721 | + $has_notices = 0; |
|
722 | + // check for success messages |
|
723 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | + ? 3 |
|
725 | + : $has_notices; |
|
726 | + // check for attention messages |
|
727 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | + ? 2 |
|
729 | + : $has_notices; |
|
730 | + // check for error messages |
|
731 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | + ? 1 |
|
733 | + : $has_notices; |
|
734 | + return $has_notices; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | + * |
|
741 | + * @since 4.9.0 |
|
742 | + * @return array |
|
743 | + */ |
|
744 | + public static function get_vanilla_notices() |
|
745 | + { |
|
746 | + return array( |
|
747 | + 'success' => isset(self::$_espresso_notices['success']) |
|
748 | + ? self::$_espresso_notices['success'] |
|
749 | + : array(), |
|
750 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | + ? self::$_espresso_notices['attention'] |
|
752 | + : array(), |
|
753 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | + ? self::$_espresso_notices['errors'] |
|
755 | + : array(), |
|
756 | + ); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * compile all error or success messages into one string |
|
763 | + * |
|
764 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | + * - ONLY do this just before redirecting |
|
768 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | + * @return array |
|
770 | + */ |
|
771 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | + { |
|
773 | + // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | + $success_messages = ''; |
|
775 | + $attention_messages = ''; |
|
776 | + $error_messages = ''; |
|
777 | + $print_scripts = false; |
|
778 | + // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | + // either save notices to the db |
|
780 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | + self::$_espresso_notices = array_merge( |
|
784 | + $existing_notices, |
|
785 | + self::$_espresso_notices |
|
786 | + ); |
|
787 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | + return array(); |
|
789 | + } |
|
790 | + // grab any notices that have been previously saved |
|
791 | + if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | + foreach ($notices as $type => $notice) { |
|
793 | + if (is_array($notice) && ! empty($notice)) { |
|
794 | + // make sure that existing notice type is an array |
|
795 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | + && ! empty(self::$_espresso_notices[$type]) |
|
797 | + ? self::$_espresso_notices[$type] |
|
798 | + : array(); |
|
799 | + // merge stored notices with any newly created ones |
|
800 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | + $print_scripts = true; |
|
802 | + } |
|
803 | + } |
|
804 | + // now clear any stored notices |
|
805 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | + } |
|
807 | + // check for success messages |
|
808 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | + // combine messages |
|
810 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | + $print_scripts = true; |
|
812 | + } |
|
813 | + // check for attention messages |
|
814 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | + // combine messages |
|
816 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | + $print_scripts = true; |
|
818 | + } |
|
819 | + // check for error messages |
|
820 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | + // combine messages |
|
825 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | + $print_scripts = true; |
|
827 | + } |
|
828 | + if ($format_output) { |
|
829 | + |
|
830 | + $notices = '<div id="espresso-notices">'; |
|
831 | + $close = is_admin() ? '' |
|
832 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | + if ($success_messages !== '') { |
|
834 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
835 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | + //showMessage( $success_messages ); |
|
837 | + $notices .= '<div id="' |
|
838 | + . $css_id |
|
839 | + . '" class="espresso-notices ' |
|
840 | + . $css_class |
|
841 | + . '" style="display:none;"><p>' |
|
842 | + . $success_messages |
|
843 | + . '</p>' |
|
844 | + . $close |
|
845 | + . '</div>'; |
|
846 | + } |
|
847 | + if ($attention_messages !== '') { |
|
848 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
849 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | + //showMessage( $error_messages, TRUE ); |
|
851 | + $notices .= '<div id="' |
|
852 | + . $css_id |
|
853 | + . '" class="espresso-notices ' |
|
854 | + . $css_class |
|
855 | + . '" style="display:none;"><p>' |
|
856 | + . $attention_messages |
|
857 | + . '</p>' |
|
858 | + . $close |
|
859 | + . '</div>'; |
|
860 | + } |
|
861 | + if ($error_messages !== '') { |
|
862 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
863 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | + //showMessage( $error_messages, TRUE ); |
|
865 | + $notices .= '<div id="' |
|
866 | + . $css_id |
|
867 | + . '" class="espresso-notices ' |
|
868 | + . $css_class |
|
869 | + . '" style="display:none;"><p>' |
|
870 | + . $error_messages |
|
871 | + . '</p>' |
|
872 | + . $close |
|
873 | + . '</div>'; |
|
874 | + } |
|
875 | + $notices .= '</div>'; |
|
876 | + } else { |
|
877 | + |
|
878 | + $notices = array( |
|
879 | + 'success' => $success_messages, |
|
880 | + 'attention' => $attention_messages, |
|
881 | + 'errors' => $error_messages, |
|
882 | + ); |
|
883 | + if ($remove_empty) { |
|
884 | + // remove empty notices |
|
885 | + foreach ($notices as $type => $notice) { |
|
886 | + if (empty($notice)) { |
|
887 | + unset($notices[$type]); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + if ($print_scripts) { |
|
893 | + self::_print_scripts(); |
|
894 | + } |
|
895 | + return $notices; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * _print_scripts |
|
902 | + * |
|
903 | + * @param bool $force_print |
|
904 | + * @return string |
|
905 | + */ |
|
906 | + private static function _print_scripts($force_print = false) |
|
907 | + { |
|
908 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | + return ''; |
|
911 | + } |
|
912 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | + wp_enqueue_style('espresso_default'); |
|
914 | + wp_enqueue_style('espresso_custom_css'); |
|
915 | + wp_enqueue_script('ee_error_js'); |
|
916 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | + } |
|
918 | + } else { |
|
919 | + return ' |
|
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | 922 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -926,223 +926,223 @@ discard block |
||
926 | 926 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
927 | 927 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
928 | 928 | '; |
929 | - } |
|
930 | - return ''; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @return void |
|
937 | - */ |
|
938 | - public static function enqueue_error_scripts() |
|
939 | - { |
|
940 | - self::_print_scripts(); |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * create error code from filepath, function name, |
|
947 | - * and line number where exception or error was thrown |
|
948 | - * |
|
949 | - * @param string $file |
|
950 | - * @param string $func |
|
951 | - * @param string $line |
|
952 | - * @return string |
|
953 | - */ |
|
954 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | - { |
|
956 | - $file = explode('.', basename($file)); |
|
957 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | - return $error_code; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * write exception details to log file |
|
967 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | - * |
|
969 | - * @param int $time |
|
970 | - * @param array $ex |
|
971 | - * @param bool $clear |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | - { |
|
976 | - if (empty($ex)) { |
|
977 | - return; |
|
978 | - } |
|
979 | - if (! $time) { |
|
980 | - $time = time(); |
|
981 | - } |
|
982 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | - . PHP_EOL; |
|
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | - . PHP_EOL; |
|
993 | - try { |
|
994 | - error_log($exception_log); |
|
995 | - } catch (EE_Error $e) { |
|
996 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | - 'event_espresso'), $e->getMessage())); |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | - * A good test for knowing whether to use this method is: |
|
1009 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | - * 2. If this is loaded before something else, it won't break anything, |
|
1012 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | - * |
|
1014 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | - * @param string $function The function that was called |
|
1016 | - * @param string $message A message explaining what has been done incorrectly |
|
1017 | - * @param string $version The version of Event Espresso where the error was added |
|
1018 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | - * but not have any notices appear until a later version. This allows developers |
|
1021 | - * extra time to update their code before notices appear. |
|
1022 | - * @param int $error_type |
|
1023 | - */ |
|
1024 | - public static function doing_it_wrong( |
|
1025 | - $function, |
|
1026 | - $message, |
|
1027 | - $version, |
|
1028 | - $applies_when = '', |
|
1029 | - $error_type = null |
|
1030 | - ) { |
|
1031 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | - * |
|
1041 | - * @return array { |
|
1042 | - * @type array $success all the success messages |
|
1043 | - * @type array $errors all the error messages |
|
1044 | - * @type array $attention all the attention messages |
|
1045 | - * } |
|
1046 | - */ |
|
1047 | - public static function get_raw_notices() |
|
1048 | - { |
|
1049 | - return self::$_espresso_notices; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @deprecated 4.9.27 |
|
1056 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | - * @return void |
|
1060 | - * @throws InvalidDataTypeException |
|
1061 | - */ |
|
1062 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | - { |
|
1064 | - new PersistentAdminNotice( |
|
1065 | - $pan_name, |
|
1066 | - $pan_message, |
|
1067 | - $force_update |
|
1068 | - ); |
|
1069 | - EE_Error::doing_it_wrong( |
|
1070 | - __METHOD__, |
|
1071 | - sprintf( |
|
1072 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | - ), |
|
1075 | - '4.9.27' |
|
1076 | - ); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * @deprecated 4.9.27 |
|
1083 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | - * @param bool $purge |
|
1085 | - * @param bool $return |
|
1086 | - * @throws DomainException |
|
1087 | - * @throws InvalidInterfaceException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws ServiceNotFoundException |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - */ |
|
1092 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | - { |
|
1094 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | - ); |
|
1098 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | - EE_Error::doing_it_wrong( |
|
1100 | - __METHOD__, |
|
1101 | - sprintf( |
|
1102 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | - ), |
|
1105 | - '4.9.27' |
|
1106 | - ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * @deprecated 4.9.27 |
|
1113 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | - */ |
|
1117 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | - { |
|
1119 | - EE_Error::doing_it_wrong( |
|
1120 | - __METHOD__, |
|
1121 | - sprintf( |
|
1122 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | - ), |
|
1125 | - '4.9.27' |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * @deprecated 4.9.27 |
|
1133 | - * @param string $return_url |
|
1134 | - */ |
|
1135 | - public static function get_persistent_admin_notices($return_url = '') |
|
1136 | - { |
|
1137 | - EE_Error::doing_it_wrong( |
|
1138 | - __METHOD__, |
|
1139 | - sprintf( |
|
1140 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | - ), |
|
1143 | - '4.9.27' |
|
1144 | - ); |
|
1145 | - } |
|
929 | + } |
|
930 | + return ''; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @return void |
|
937 | + */ |
|
938 | + public static function enqueue_error_scripts() |
|
939 | + { |
|
940 | + self::_print_scripts(); |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * create error code from filepath, function name, |
|
947 | + * and line number where exception or error was thrown |
|
948 | + * |
|
949 | + * @param string $file |
|
950 | + * @param string $func |
|
951 | + * @param string $line |
|
952 | + * @return string |
|
953 | + */ |
|
954 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | + { |
|
956 | + $file = explode('.', basename($file)); |
|
957 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | + return $error_code; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * write exception details to log file |
|
967 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | + * |
|
969 | + * @param int $time |
|
970 | + * @param array $ex |
|
971 | + * @param bool $clear |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | + { |
|
976 | + if (empty($ex)) { |
|
977 | + return; |
|
978 | + } |
|
979 | + if (! $time) { |
|
980 | + $time = time(); |
|
981 | + } |
|
982 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | + . PHP_EOL; |
|
984 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | + . PHP_EOL; |
|
993 | + try { |
|
994 | + error_log($exception_log); |
|
995 | + } catch (EE_Error $e) { |
|
996 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | + 'event_espresso'), $e->getMessage())); |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | + * A good test for knowing whether to use this method is: |
|
1009 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | + * 2. If this is loaded before something else, it won't break anything, |
|
1012 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | + * |
|
1014 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | + * @param string $function The function that was called |
|
1016 | + * @param string $message A message explaining what has been done incorrectly |
|
1017 | + * @param string $version The version of Event Espresso where the error was added |
|
1018 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | + * but not have any notices appear until a later version. This allows developers |
|
1021 | + * extra time to update their code before notices appear. |
|
1022 | + * @param int $error_type |
|
1023 | + */ |
|
1024 | + public static function doing_it_wrong( |
|
1025 | + $function, |
|
1026 | + $message, |
|
1027 | + $version, |
|
1028 | + $applies_when = '', |
|
1029 | + $error_type = null |
|
1030 | + ) { |
|
1031 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | + * |
|
1041 | + * @return array { |
|
1042 | + * @type array $success all the success messages |
|
1043 | + * @type array $errors all the error messages |
|
1044 | + * @type array $attention all the attention messages |
|
1045 | + * } |
|
1046 | + */ |
|
1047 | + public static function get_raw_notices() |
|
1048 | + { |
|
1049 | + return self::$_espresso_notices; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @deprecated 4.9.27 |
|
1056 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | + * @return void |
|
1060 | + * @throws InvalidDataTypeException |
|
1061 | + */ |
|
1062 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | + { |
|
1064 | + new PersistentAdminNotice( |
|
1065 | + $pan_name, |
|
1066 | + $pan_message, |
|
1067 | + $force_update |
|
1068 | + ); |
|
1069 | + EE_Error::doing_it_wrong( |
|
1070 | + __METHOD__, |
|
1071 | + sprintf( |
|
1072 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | + ), |
|
1075 | + '4.9.27' |
|
1076 | + ); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * @deprecated 4.9.27 |
|
1083 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | + * @param bool $purge |
|
1085 | + * @param bool $return |
|
1086 | + * @throws DomainException |
|
1087 | + * @throws InvalidInterfaceException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws ServiceNotFoundException |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + */ |
|
1092 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | + { |
|
1094 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | + ); |
|
1098 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | + EE_Error::doing_it_wrong( |
|
1100 | + __METHOD__, |
|
1101 | + sprintf( |
|
1102 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | + ), |
|
1105 | + '4.9.27' |
|
1106 | + ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * @deprecated 4.9.27 |
|
1113 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | + */ |
|
1117 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | + { |
|
1119 | + EE_Error::doing_it_wrong( |
|
1120 | + __METHOD__, |
|
1121 | + sprintf( |
|
1122 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | + ), |
|
1125 | + '4.9.27' |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * @deprecated 4.9.27 |
|
1133 | + * @param string $return_url |
|
1134 | + */ |
|
1135 | + public static function get_persistent_admin_notices($return_url = '') |
|
1136 | + { |
|
1137 | + EE_Error::doing_it_wrong( |
|
1138 | + __METHOD__, |
|
1139 | + sprintf( |
|
1140 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | + ), |
|
1143 | + '4.9.27' |
|
1144 | + ); |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | |
1148 | 1148 | |
@@ -1157,27 +1157,27 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | function espresso_error_enqueue_scripts() |
1159 | 1159 | { |
1160 | - // js for error handling |
|
1161 | - wp_register_script( |
|
1162 | - 'espresso_core', |
|
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | - array('jquery'), |
|
1165 | - EVENT_ESPRESSO_VERSION, |
|
1166 | - false |
|
1167 | - ); |
|
1168 | - wp_register_script( |
|
1169 | - 'ee_error_js', |
|
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | - array('espresso_core'), |
|
1172 | - EVENT_ESPRESSO_VERSION, |
|
1173 | - false |
|
1174 | - ); |
|
1160 | + // js for error handling |
|
1161 | + wp_register_script( |
|
1162 | + 'espresso_core', |
|
1163 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | + array('jquery'), |
|
1165 | + EVENT_ESPRESSO_VERSION, |
|
1166 | + false |
|
1167 | + ); |
|
1168 | + wp_register_script( |
|
1169 | + 'ee_error_js', |
|
1170 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | + array('espresso_core'), |
|
1172 | + EVENT_ESPRESSO_VERSION, |
|
1173 | + false |
|
1174 | + ); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | if (is_admin()) { |
1178 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1178 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1179 | 1179 | } else { |
1180 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1180 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | default : |
104 | 104 | $to = get_option('admin_email'); |
105 | 105 | } |
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
107 | 107 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
108 | 108 | if (function_exists('wp_mail')) { |
109 | 109 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
110 | 110 | wp_mail($to, $subject, $msg); |
111 | 111 | } |
112 | 112 | echo '<div id="message" class="espresso-notices error"><p>'; |
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
114 | 114 | echo '<br /></p></div>'; |
115 | 115 | } |
116 | 116 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | ? true |
258 | 258 | : false; |
259 | 259 | if ($check_stored && ! $has_error) { |
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
260 | + $notices = (array) get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | 261 | foreach ($notices as $type => $notice) { |
262 | 262 | if ($type === $type_to_check && $notice) { |
263 | 263 | return true; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
335 | + if ( ! WP_DEBUG) { |
|
336 | 336 | $output .= ' |
337 | 337 | <p>'; |
338 | 338 | } |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | $class_dsply = ! empty($class) ? $class : ' '; |
392 | 392 | $type_dsply = ! empty($type) ? $type : ' '; |
393 | 393 | $function_dsply = ! empty($function) ? $function : ' '; |
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
394 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
395 | 395 | $trace_details .= ' |
396 | 396 | <tr> |
397 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
398 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
399 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
400 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
401 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
397 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
398 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
399 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
400 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
401 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
402 | 402 | </tr>'; |
403 | 403 | } |
404 | 404 | $trace_details .= ' |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | } |
408 | 408 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
409 | 409 | // add generic non-identifying messages for non-privileged users |
410 | - if (! WP_DEBUG) { |
|
410 | + if ( ! WP_DEBUG) { |
|
411 | 411 | $output .= '<span class="ee-error-user-msg-spn">' |
412 | 412 | . trim($ex['msg']) |
413 | 413 | . '</span> <sup>' |
@@ -449,14 +449,14 @@ discard block |
||
449 | 449 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
450 | 450 | ' |
451 | 451 | . $trace_details; |
452 | - if (! empty($class)) { |
|
452 | + if ( ! empty($class)) { |
|
453 | 453 | $output .= ' |
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | 457 | $a = new ReflectionClass($class); |
458 | 458 | $output .= ' |
459 | - <pre>' . $a . '</pre> |
|
459 | + <pre>' . $a.'</pre> |
|
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | 462 | } |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | } |
470 | 470 | // remove last linebreak |
471 | 471 | $output = substr($output, 0, -6); |
472 | - if (! WP_DEBUG) { |
|
472 | + if ( ! WP_DEBUG) { |
|
473 | 473 | $output .= ' |
474 | 474 | </p>'; |
475 | 475 | } |
@@ -496,20 +496,20 @@ discard block |
||
496 | 496 | private function _convert_args_to_string($arguments = array(), $array = false) |
497 | 497 | { |
498 | 498 | $arg_string = ''; |
499 | - if (! empty($arguments)) { |
|
499 | + if ( ! empty($arguments)) { |
|
500 | 500 | $args = array(); |
501 | 501 | foreach ($arguments as $arg) { |
502 | - if (! empty($arg)) { |
|
502 | + if ( ! empty($arg)) { |
|
503 | 503 | if (is_string($arg)) { |
504 | - $args[] = " '" . $arg . "'"; |
|
504 | + $args[] = " '".$arg."'"; |
|
505 | 505 | } elseif (is_array($arg)) { |
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
506 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
507 | 507 | } elseif ($arg === null) { |
508 | 508 | $args[] = ' NULL'; |
509 | 509 | } elseif (is_bool($arg)) { |
510 | 510 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
511 | 511 | } elseif (is_object($arg)) { |
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
512 | + $args[] = ' OBJECT '.get_class($arg); |
|
513 | 513 | } elseif (is_resource($arg)) { |
514 | 514 | $args[] = get_resource_type($arg); |
515 | 515 | } else { |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | { |
613 | 613 | if (empty($msg)) { |
614 | 614 | EE_Error::doing_it_wrong( |
615 | - 'EE_Error::add_' . $type . '()', |
|
615 | + 'EE_Error::add_'.$type.'()', |
|
616 | 616 | sprintf( |
617 | 617 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
618 | 618 | 'event_espresso'), |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
649 | 649 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
650 | 650 | // add notice if message exists |
651 | - if (! empty($msg)) { |
|
651 | + if ( ! empty($msg)) { |
|
652 | 652 | // get error code |
653 | 653 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
654 | 654 | if (WP_DEBUG && $type === 'errors') { |
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
655 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
656 | 656 | } |
657 | 657 | // add notice. Index by code if it's not blank |
658 | 658 | if ($notice_code) { |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
779 | 779 | // either save notices to the db |
780 | 780 | if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | 782 | $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
783 | 783 | self::$_espresso_notices = array_merge( |
784 | 784 | $existing_notices, |
@@ -808,13 +808,13 @@ discard block |
||
808 | 808 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
809 | 809 | // combine messages |
810 | 810 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
811 | - $print_scripts = true; |
|
811 | + $print_scripts = true; |
|
812 | 812 | } |
813 | 813 | // check for attention messages |
814 | 814 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
815 | 815 | // combine messages |
816 | 816 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
817 | - $print_scripts = true; |
|
817 | + $print_scripts = true; |
|
818 | 818 | } |
819 | 819 | // check for error messages |
820 | 820 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | : __('An error has occurred:<br />', 'event_espresso'); |
824 | 824 | // combine messages |
825 | 825 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
826 | - $print_scripts = true; |
|
826 | + $print_scripts = true; |
|
827 | 827 | } |
828 | 828 | if ($format_output) { |
829 | 829 | |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | */ |
906 | 906 | private static function _print_scripts($force_print = false) |
907 | 907 | { |
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
908 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | 909 | if (wp_script_is('ee_error_js', 'enqueued')) { |
910 | 910 | return ''; |
911 | 911 | } |
@@ -919,12 +919,12 @@ discard block |
||
919 | 919 | return ' |
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
922 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
923 | 923 | /* ]]> */ |
924 | 924 | </script> |
925 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
926 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
927 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
925 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
926 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
927 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
928 | 928 | '; |
929 | 929 | } |
930 | 930 | return ''; |
@@ -955,8 +955,8 @@ discard block |
||
955 | 955 | { |
956 | 956 | $file = explode('.', basename($file)); |
957 | 957 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
960 | 960 | return $error_code; |
961 | 961 | } |
962 | 962 | |
@@ -976,18 +976,18 @@ discard block |
||
976 | 976 | if (empty($ex)) { |
977 | 977 | return; |
978 | 978 | } |
979 | - if (! $time) { |
|
979 | + if ( ! $time) { |
|
980 | 980 | $time = time(); |
981 | 981 | } |
982 | 982 | $exception_log = '----------------------------------------------------------------------------------------' |
983 | 983 | . PHP_EOL; |
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
984 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
985 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
986 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
987 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
988 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
990 | + $exception_log .= $ex['string'].PHP_EOL; |
|
991 | 991 | $exception_log .= '----------------------------------------------------------------------------------------' |
992 | 992 | . PHP_EOL; |
993 | 993 | try { |
@@ -1160,14 +1160,14 @@ discard block |
||
1160 | 1160 | // js for error handling |
1161 | 1161 | wp_register_script( |
1162 | 1162 | 'espresso_core', |
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1163 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
1164 | 1164 | array('jquery'), |
1165 | 1165 | EVENT_ESPRESSO_VERSION, |
1166 | 1166 | false |
1167 | 1167 | ); |
1168 | 1168 | wp_register_script( |
1169 | 1169 | 'ee_error_js', |
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1170 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
1171 | 1171 | array('espresso_core'), |
1172 | 1172 | EVENT_ESPRESSO_VERSION, |
1173 | 1173 | false |