From 8c0b1e3c190a6c990d7f51a3638b1f676cdb6aaf Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Thu, 16 May 2024 16:07:20 -0500 Subject: [PATCH] check for image_path exists and set http status header --- includes/featured-image-generator.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/featured-image-generator.php b/includes/featured-image-generator.php index c18ca34..c6f8257 100644 --- a/includes/featured-image-generator.php +++ b/includes/featured-image-generator.php @@ -184,6 +184,17 @@ add_action('template_redirect', 'handle_image_request'); function serve_image($image_path) { header('Content-Type: image/png'); + if (file_exists($image_path)) { + status_header( 200 ); + } else { + status_header( 404 ); + die("Image not found."); + } + + // Clear all output buffering to prevent any extra output + while (ob_get_level()) { + ob_end_clean(); + } readfile($image_path); }