From ad3e4cd60b5e791f1c3dac618e9188f64f126a83 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Tue, 17 Dec 2024 12:36:14 -0500 Subject: [PATCH] Prevent caching and exit with 1 when a plugin is missing --- CHANGELOG.md | 5 +++++ src/class-wp-plugin-loader.php | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1ae69f..974ca1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `WP Plugin Loader` will be documented in this file. +## 0.1.6 - 2024-12-17 + +- When a plugin is not found, exit with a status code of 1 and send a `500` + status code header. This will prevent a fatal error from being cached + ## 0.1.5 - 2024-09-25 - Ensure that the default cache key is unique to each installation. Previously diff --git a/src/class-wp-plugin-loader.php b/src/class-wp-plugin-loader.php index a5606db..47ba3a4 100644 --- a/src/class-wp-plugin-loader.php +++ b/src/class-wp-plugin-loader.php @@ -222,8 +222,14 @@ protected function handle_missing_plugin( string $plugin ): void { newrelic_notice_error( $error_message ); } - // Bye bye! - die( esc_html( $error_message ) ); + // Send a 500 status code and no-cache headers to prevent caching of the error message. + if ( ! headers_sent() ) { + status_header( 500 ); + nocache_headers(); + } + + echo esc_html( $error_message ); + exit( 1 ); } /**