PluginProbe
FluentPlayer – Video Player With Forms & Lead Capture / 1.4.0
FluentPlayer – Video Player With Forms & Lead Capture v1.4.0
1.4.0 1.3.1 1.3.0 1.2.0 1.1.0 trunk 1.0.7 1.0.8 1.0.9
fluent-player / boot / error_handler.php

error_handler.php in FluentPlayer – Video Player With Forms & Lead Capture 1.4.0, at boot/error_handler.php

82 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 /**
5 * Custom error handler for development environments only.
6 * This will only be active when WP_DEBUG is enabled.
7 */
8 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
9 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Only active in development mode
10 set_error_handler(function($errno, $msg, $fn, $ln) use ($file) {
11 // Check if this error type should be reported based on current error_reporting level
12 // This respects the error_reporting settings in php.ini or set by WordPress
13 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting -- Used for error handling logic
14 if (!(error_reporting() & $errno)) {
15 return false;
16 }
17
18 $levels = [
19 E_ALL => "E_ALL",
20 E_ERROR => "E_ERROR",
21 E_WARNING => "E_WARNING",
22 E_PARSE => "E_PARSE",
23 E_NOTICE => "E_NOTICE",
24 E_CORE_ERROR => "E_CORE_ERROR",
25 E_CORE_WARNING => "E_CORE_WARNING",
26 E_COMPILE_ERROR => "E_COMPILE_ERROR",
27 E_COMPILE_WARNING => "E_COMPILE_WARNING",
28 E_USER_ERROR => "E_USER_ERROR",
29 E_USER_WARNING => "E_USER_WARNING",
30 E_USER_NOTICE => "E_USER_NOTICE",
31 E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
32 E_DEPRECATED => "E_DEPRECATED",
33 E_USER_DEPRECATED => "E_USER_DEPRECATED"
34 ];
35
36 if (PHP_VERSION_ID < 70400) {
37 $levels[E_STRICT] = "E_STRICT";
38 }
39
40 $levelName = $levels[$errno] ?? "UNKNOWN ERROR LEVEL";
41
42 // Only process errors from our plugin
43 if (strpos($fn, dirname($file) . '/') !== false) {
44 // Additional check for WP_DEBUG_LOG to determine how to handle the error
45 if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
46 // Log detailed error information
47 $debugInfo = [
48 'Error Level' => $levelName,
49 'Message' => $msg,
50 'File' => $fn,
51 'Line' => $ln,
52 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Only used in development mode
53 'Backtrace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
54 ];
55
56 // Log to debug.log
57 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Only active in development mode
58 error_log(sprintf(
59 '[Fluent Player] %s - %s in %s at line %s',
60 $levelName,
61 $msg,
62 $fn,
63 $ln
64 ));
65 }
66
67 // Only display errors if WP_DEBUG_DISPLAY is true
68 if (defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY) {
69 throw new ErrorException(sprintf(
70 '%s - %s in %s at line %s',
71 esc_html($levelName),
72 esc_html($msg),
73 esc_html($fn),
74 esc_html((string)$ln)
75 ), 500);
76 }
77 }
78
79 return false;
80 });
81 }
82