Commit 4e9ebd651b for wordpress.org

commit 4e9ebd651bc1b097aab04c0465632b18b1f9e332
Author: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Date:   Sun Oct 11 23:49:50 2026 +0000

    General: Send correct HTTP statuses for db-error/maintenance drop-ins.

    Updates the HTTP headers for sites running the `db-error.php` or `maintenance.php` drop-ins. Previously sites running these drop-ins would send a `200 OK` HTTP response by default if they were not specified by the drop-in. These have been updated to:

    * `500 Internal Server Error` for the Database Error drop-in, matching the header sent by the default call to `wp_die().
    * `503 Service Unavailable` for the maintenance mode drop-in with a retry header of 10 minutes, matching the headers sent by the default call to `wp_die()`.

    Developers can continue to customize these headers by sending the headers in the drop-ins.

    Developed in https://github.com/WordPress/wordpress-develop/pull/13471.

    Props bradleyt, dineshinau, sabernhardt, westonruter.
    Fixes #66080.



    Built from https://develop.svn.wordpress.org/trunk@64305


    git-svn-id: http://core.svn.wordpress.org/trunk@63455 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wpdb.php b/wp-includes/class-wpdb.php
index 96d2bafeed..e4784d2c91 100644
--- a/wp-includes/class-wpdb.php
+++ b/wp-includes/class-wpdb.php
@@ -1959,7 +1959,8 @@ class wpdb {
 	 * If `$allow_bail` is false, the lack of database connection will need to be handled manually.
 	 *
 	 * @since 3.0.0
-	 * @since 3.9.0 $allow_bail parameter added.
+	 * @since 3.9.0 Added `$allow_bail` parameter.
+	 * @since 7.2.0 Added status and no-cache headers 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.
@@ -2011,8 +2012,13 @@ class wpdb {
 		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/wp-includes/functions.php b/wp-includes/functions.php
index c07a670d76..3e7062c4f1 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -5663,6 +5663,7 @@ function wp_ob_end_flush_all() {
  * in WordPress 2.5.0.
  *
  * @since 2.3.2
+ * @since 7.2.0 Added status and no-cache headers before loading a custom `db-error.php` drop-in.
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
@@ -5675,6 +5676,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/wp-includes/load.php b/wp-includes/load.php
index 1558a44189..d827afa5ba 100644
--- a/wp-includes/load.php
+++ b/wp-includes/load.php
@@ -395,6 +395,7 @@ function wp_favicon_request() {
  * the wp-content directory).
  *
  * @since 3.0.0
+ * @since 7.2.0 Added status, no-cache and retry-after headers before loading a custom `maintenance.php` drop-in.
  * @access private
  */
 function wp_maintenance() {
@@ -403,12 +404,16 @@ function wp_maintenance() {
 		return;
 	}

+	require_once ABSPATH . WPINC . '/functions.php';
+
 	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();
 	}

-	require_once ABSPATH . WPINC . '/functions.php';
 	wp_load_translations_early();

 	header( 'Retry-After: 600' );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 11d42a0f83..c6e5371d2a 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-64304';
+$wp_version = '7.2-alpha-64305';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.