| @@ -13,11 +13,15 @@ | ||
| 13 | 13 | protected static $backupDir = '/wpide/backups/'; |
| 14 | 14 | |
| 15 | 15 | public static function boot() |
| 16 | 16 | { |
| 17 | - register_shutdown_function([__CLASS__, 'shutdownHandler']); | |
| 18 | - set_exception_handler([__CLASS__, 'exceptionHandler']); | |
| 19 | - set_error_handler([__CLASS__, 'errorHandler']); | |
| 17 | + | |
| 18 | + if (version_compare(PHP_VERSION, '7.4.0', '>=')) { | |
| 19 | + | |
| 20 | + register_shutdown_function([__CLASS__, 'shutdownHandler']); | |
| 21 | + set_exception_handler([__CLASS__, 'exceptionHandler']); | |
| 22 | + set_error_handler([__CLASS__, 'errorHandler']); | |
| 23 | + } | |
| 20 | 24 | } |
| 21 | 25 | |
| 22 | 26 | public static function isPluginScreen(): bool |
| 23 | 27 | { |
| @@ -47,9 +51,8 @@ | ||
| 47 | 51 | } |
| 48 | 52 | |
| 49 | 53 | public static function exceptionHandler(Throwable $exception) |
| 50 | 54 | { |
| 51 | - | |
| 52 | 55 | self::errorHandler(-1, $exception->getMessage(), $exception->getFile(), $exception->getLine()); |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | 58 | public static function errorHandler($error_type, $error_message, $error_file, $error_line) |
| @@ -58,8 +61,14 @@ | ||
| 58 | 61 | if (!$error_type) { |
| 59 | 62 | return; |
| 60 | 63 | } |
| 61 | 64 | |
| 65 | + // Respect the active error_reporting mask so @-suppressed warnings | |
| 66 | + // and globally filtered notices do not get re-logged by this handler. | |
| 67 | + if (-1 !== $error_type && 0 === (error_reporting() & $error_type)) { | |
| 68 | + return false; | |
| 69 | + } | |
| 70 | + | |
| 62 | 71 | $fatal = false; |
| 63 | 72 | |
| 64 | 73 | switch ($error_type) { |
| 65 | 74 | |
| @@ -138,9 +147,9 @@ | ||
| 138 | 147 | $lockfile = self::backupDir().'.lock'; |
| 139 | 148 | $backup_file = self::findBackupFile($error_file); |
| 140 | 149 | |
| 141 | 150 | // If backup exists |
| 142 | - if (file_exists($backup_file)) { | |
| 151 | + if (!empty($backup_file) && file_exists($backup_file)) { | |
| 143 | 152 | |
| 144 | 153 | if (ob_get_length()) ob_end_clean(); |
| 145 | 154 | |
| 146 | 155 | // If on admin side, show file recovery wizard |
| @@ -209,10 +218,16 @@ | ||
| 209 | 218 | |
| 210 | 219 | public static function findBackupFile($error_file): ?string |
| 211 | 220 | { |
| 212 | 221 | |
| 222 | + $backupFolders = scandir(self::backupDir()); | |
| 223 | + | |
| 224 | + if(empty($backupFolders)) { | |
| 225 | + return null; | |
| 226 | + } | |
| 227 | + | |
| 213 | 228 | // Get backup folders |
| 214 | - $backupFolders = array_filter(scandir(self::backupDir()), function ($folder) { | |
| 229 | + $backupFolders = array_filter($backupFolders, function ($folder) { | |
| 215 | 230 | |
| 216 | 231 | if ($folder === '.' || $folder === '..') { |
| 217 | 232 | return false; |
| 218 | 233 | } |
| @@ -868,5 +883,5 @@ | ||
| 868 | 883 | } |
| 869 | 884 | } |
| 870 | 885 | |
| 871 | 886 | WPIDE_Error_Handler::boot(); |
| 872 | -} | |
| 887 | +} | |