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