'[email]', '/(? '[sđt]', "/'[^'\\n]{1,2000}'/" => "'…'", '/"[^"\\n]{1,2000}"/' => '"…"', ); foreach ( $rules as $re => $to ) { $x = preg_replace( $re, $to, $msg ); $msg = is_string( $x ) ? $x : $msg; } // chỉ giữ đường dẫn trang (bỏ query string có thể chứa token, email...), làm sạch rồi mới lưu $uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; $uri = (string) strtok( $uri, '?#' ); $uri = preg_replace( '/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/', '[email]', substr( $uri, 0, 200 ) ); $uri = preg_replace( '#/[A-Za-z0-9_-]{24,}#', '/[…]', (string) $uri ); // đoạn đường dẫn dài kiểu token/khoá $row = json_encode( array( 't' => time(), 'h' => $h, 'type' => (int) $e['type'], 'file' => $file, 'line' => (int) $e['line'], 'msg' => substr( $msg, 0, 800 ), 'uri' => $uri, 'php' => PHP_VERSION ), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE ); $log = $dir . '/errors.jsonl'; if ( file_exists( $log ) && @filesize( $log ) > 262144 ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions -- chạy lúc tắt request, không được ném lỗi @rename( $log, $log . '.1' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions -- chạy lúc tắt request, không được ném lỗi } @file_put_contents( $log, $row . "\n", FILE_APPEND | LOCK_EX ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions -- chạy lúc tắt request, không được ném lỗi } catch ( \Throwable $x ) { return; } }