Discussion:
Change "Error Establishing a Database Connection" error message
Ryan B
2014-04-15 17:27:08 UTC
Permalink
I am wanting to change this error message to something a little more useful
to an end user, and also have it trigger an email alert to me if this error
occurs. Is there a hook or filter I could use to change the output given to
the user when a database connection error occurs?
Shumail Mohy-ud-din
2014-04-15 17:38:39 UTC
Permalink
Hi,

Check line 1158 of wp-db.php - "<h1>Error establishing a database
connection</h1>"
I guess you can change from there.

Kind Regards,
Shumail Mohy-ud-Din
Computer Science Student,
National University of Science & Technology,PK
- www.ShumailMohyuddin.com
Post by Ryan B
I am wanting to change this error message to something a little more useful
to an end user, and also have it trigger an email alert to me if this error
occurs. Is there a hook or filter I could use to change the output given to
the user when a database connection error occurs?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nicholas Ciske
2014-04-15 17:39:00 UTC
Permalink
No filter, but the template can be overridden... and that could send an email.

// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once( WP_CONTENT_DIR . '/db-error.php' );
die();
}

See line ~1388 here:
https://github.com/WordPress/WordPress/blob/1860b6a007c568b50344d113fe6490713479ad6a/wp-includes/wp-db.php

And dead_db() on line ~1955 here:
https://github.com/WordPress/WordPress/blob/ca7ef18e55481de51dad2f9f234ffa8461f3a209/wp-includes/functions.php#L2987

On multisite you can filter wp_die() to check for that message and alter it/send an email.

See line ~401 here:
https://github.com/WordPress/WordPress/blob/827b92a9bd8a84c0ce73b55079675e9a2b0a14e7/wp-includes/ms-load.php

wp_die
https://codex.wordpress.org/Function_Reference/wp_die

_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Ryan B
I am wanting to change this error message to something a little more useful
to an end user, and also have it trigger an email alert to me if this error
occurs. Is there a hook or filter I could use to change the output given to
the user when a database connection error occurs?
Ryan B
2014-04-15 20:22:05 UTC
Permalink
@Shumail Mohy-ud-din, modifying core like that is not recommended, because
the change would have to be redone each time a WordPress update is
installed.

@Nicholas Ciske, that works perfect. Thanks for the tip.

Loading...