diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 869111efd0797..36f8e57278125 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -1958,6 +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. * * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True with a successful connection, false on failure. @@ -2009,8 +2010,13 @@ 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 4f5916a322620..f4a5093a277b5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5634,6 +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. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -5646,6 +5647,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..3782d1e7ac6a2 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 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() { @@ -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(); }