From a6cad7d9373108c76916166a43c7a0ba9b5befc1 Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Thu, 10 Sep 2026 13:54:38 +0530 Subject: [PATCH 1/4] Database: Send a 500 status and no-cache headers when using db-error.php or maintenance.php drop-ins --- src/wp-includes/class-wpdb.php | 10 +++++++++- src/wp-includes/functions.php | 4 ++++ src/wp-includes/load.php | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 869111efd0797..7802d91d2ff2c 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -1958,6 +1958,8 @@ public function flush() { * * @since 3.0.0 * @since 3.9.0 $allow_bail parameter added. + * @since 7.2.0 A 500 status header and no-cache headers are now sent + * before loading a custom db-error.php drop-in. * * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True with a successful connection, false on failure. @@ -2009,8 +2011,14 @@ public function db_connect( $allow_bail = true ) { if ( ! $this->dbh && $allow_bail ) { wp_load_translations_early(); - // Load custom DB error template, if present. + /** + * Load custom DB error template, if present. + * A 500 status header and no-cache headers are now sent + * before loading a custom db-error.php drop-in. + */ if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { + status_header( 500 ); + nocache_headers(); require_once WP_CONTENT_DIR . '/db-error.php'; die(); } diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 4c323812991d7..1591f588a5771 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5634,6 +5634,8 @@ function wp_ob_end_flush_all() { * in WordPress 2.5.0. * * @since 2.3.2 + * @since 7.2.0 A 500 status header and no-cache headers are now sent + * before loading a custom db-error.php drop-in. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -5646,6 +5648,8 @@ function dead_db() { // Load custom DB error template, if present. if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { + status_header( 500 ); + nocache_headers(); require_once WP_CONTENT_DIR . '/db-error.php'; die(); } diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 9d407453424c5..a26fa6c05f183 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -395,6 +395,8 @@ function wp_favicon_request() { * the wp-content directory). * * @since 3.0.0 + * @since 7.2.0 A 500 status header and no-cache headers are now sent before loading maintenance.php drop-in. + * This is to ensure that the correct headers are sent. * @access private */ function wp_maintenance() { @@ -404,6 +406,9 @@ function wp_maintenance() { } if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { + status_header( 503 ); + nocache_headers(); + header( 'Retry-After: 600' ); require_once WP_CONTENT_DIR . '/maintenance.php'; die(); } From 5b00cb85741353f026908e479f26f0cac8c0dc68 Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Fri, 11 Sep 2026 01:51:26 +0530 Subject: [PATCH 2/4] Update src/wp-includes/class-wpdb.php Co-authored-by: Weston Ruter --- src/wp-includes/class-wpdb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 7802d91d2ff2c..036b2dadc1002 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -2014,7 +2014,7 @@ public function db_connect( $allow_bail = true ) { /** * Load custom DB error template, if present. * A 500 status header and no-cache headers are now sent - * before loading a custom db-error.php drop-in. + * before loading a custom db-error.php drop-in. */ if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { status_header( 500 ); From 336be9aab03f8daa21477d4854fc92ed8a412cbf Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Fri, 11 Sep 2026 01:51:43 +0530 Subject: [PATCH 3/4] Update src/wp-includes/class-wpdb.php Co-authored-by: Weston Ruter --- src/wp-includes/class-wpdb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 036b2dadc1002..7c12f9ef34d5e 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -1959,7 +1959,7 @@ public function flush() { * @since 3.0.0 * @since 3.9.0 $allow_bail parameter added. * @since 7.2.0 A 500 status header and no-cache headers are now sent - * before loading a custom db-error.php drop-in. + * before loading a custom db-error.php drop-in. * * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True with a successful connection, false on failure. From 629a86b7debb77c132211d4c31610086af481ffb Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Thu, 10 Sep 2026 22:13:17 +0000 Subject: [PATCH 4/4] Added suggestion to remove space for fixin phpcs issues. Fixed the status header for wp maintainance to change 500 to 503 in comment line --- src/wp-includes/class-wpdb.php | 6 ++---- src/wp-includes/functions.php | 3 +-- src/wp-includes/load.php | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 7c12f9ef34d5e..36f8e57278125 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -1958,8 +1958,7 @@ public function flush() { * * @since 3.0.0 * @since 3.9.0 $allow_bail parameter added. - * @since 7.2.0 A 500 status header and no-cache headers are now sent - * before loading a custom db-error.php drop-in. + * @since 7.2.0 A 500 status header and no-cache headers are now sent before loading a custom db-error.php drop-in. * * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True with a successful connection, false on failure. @@ -2013,8 +2012,7 @@ public function db_connect( $allow_bail = true ) { /** * Load custom DB error template, if present. - * A 500 status header and no-cache headers are now sent - * before loading a custom db-error.php drop-in. + * A 500 status header and no-cache headers are now sent before loading a custom db-error.php drop-in. */ if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { status_header( 500 ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 75b82116c144c..f4a5093a277b5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5634,8 +5634,7 @@ function wp_ob_end_flush_all() { * in WordPress 2.5.0. * * @since 2.3.2 - * @since 7.2.0 A 500 status header and no-cache headers are now sent - * before loading a custom db-error.php drop-in. + * @since 7.2.0 A 500 status header and no-cache headers are now sent before loading a custom db-error.php drop-in. * * @global wpdb $wpdb WordPress database abstraction object. * diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index a26fa6c05f183..3782d1e7ac6a2 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -395,8 +395,8 @@ function wp_favicon_request() { * the wp-content directory). * * @since 3.0.0 - * @since 7.2.0 A 500 status header and no-cache headers are now sent before loading maintenance.php drop-in. - * This is to ensure that the correct headers are sent. + * @since 7.2.0 A 503 status header and no-cache headers are now sent before loading maintenance.php drop-in. + * to ensure that the correct headers are sent. * @access private */ function wp_maintenance() {