Skip to content

Commit f8b9634

Browse files
committed
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 #13471. Props bradleyt, dineshinau, sabernhardt, westonruter. Fixes #66080. git-svn-id: https://develop.svn.wordpress.org/trunk@64305 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e0dd355 commit f8b9634

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎src/wp-includes/class-wpdb.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,8 @@ public function flush() {
19591959
* If `$allow_bail` is false, the lack of database connection will need to be handled manually.
19601960
*
19611961
* @since 3.0.0
1962-
* @since 3.9.0 $allow_bail parameter added.
1962+
* @since 3.9.0 Added `$allow_bail` parameter.
1963+
* @since 7.2.0 Added status and no-cache headers before loading a custom `db-error.php` drop-in.
19631964
*
19641965
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
19651966
* @return bool True with a successful connection, false on failure.
@@ -2011,8 +2012,13 @@ public function db_connect( $allow_bail = true ) {
20112012
if ( ! $this->dbh && $allow_bail ) {
20122013
wp_load_translations_early();
20132014

2014-
// Load custom DB error template, if present.
2015+
/*
2016+
* Load custom DB error template, if present.
2017+
* A 500 status header and no-cache headers are now sent before loading a custom db-error.php drop-in.
2018+
*/
20152019
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
2020+
status_header( 500 );
2021+
nocache_headers();
20162022
require_once WP_CONTENT_DIR . '/db-error.php';
20172023
die();
20182024
}

‎src/wp-includes/functions.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5663,6 +5663,7 @@ function wp_ob_end_flush_all() {
56635663
* in WordPress 2.5.0.
56645664
*
56655665
* @since 2.3.2
5666+
* @since 7.2.0 Added status and no-cache headers before loading a custom `db-error.php` drop-in.
56665667
*
56675668
* @global wpdb $wpdb WordPress database abstraction object.
56685669
*
@@ -5675,6 +5676,8 @@ function dead_db() {
56755676

56765677
// Load custom DB error template, if present.
56775678
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
5679+
status_header( 500 );
5680+
nocache_headers();
56785681
require_once WP_CONTENT_DIR . '/db-error.php';
56795682
die();
56805683
}

‎src/wp-includes/load.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function wp_favicon_request() {
395395
* the wp-content directory).
396396
*
397397
* @since 3.0.0
398+
* @since 7.2.0 Added status, no-cache and retry-after headers before loading a custom `maintenance.php` drop-in.
398399
* @access private
399400
*/
400401
function wp_maintenance() {
@@ -403,12 +404,16 @@ function wp_maintenance() {
403404
return;
404405
}
405406

407+
require_once ABSPATH . WPINC . '/functions.php';
408+
406409
if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
410+
status_header( 503 );
411+
nocache_headers();
412+
header( 'Retry-After: 600' );
407413
require_once WP_CONTENT_DIR . '/maintenance.php';
408414
die();
409415
}
410416

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

414419
header( 'Retry-After: 600' );

0 commit comments

Comments
 (0)