WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#4207 closed enhancement (duplicate)

Pluggable DB Down Page

Reported by: linickx Owned by: darkfate
Milestone: Priority: low
Severity: normal Version:
Component: General Keywords: needs-patch
Focuses: Cc:

Description (last modified by rob1n)

I believe most pro-bloggers would appreciate this.

Can we have a simple way to "plug" the database down page, i.e once we've got wordpress setup the default wordpress error message doesn't look as professional as one which was integrated into a users theme.

Something simple inside "~/wp-includes/wp-db.php; function bail()" should be enough, I was thinking of ....

function bail($message) { // Just wraps errors in a nice header and footer
        if ( !$this->show_errors )
                return false;
		if (file_exists('wp-content/db-down.php')) {
			 include('wp-content/db-down.php');
		} else {	 
        header( 'Content-Type: text/html; charset=utf-8');
        echo <<<HEAD
        <!DOCTYPE htm.... blah blah
		}
		die();
}
}

Thanks :)

Attachments (2)

wp-db.php.patch (555 bytes) - added by darkfate 12 years ago.
patch to look for db-down.php in wp-includes, go to default if not found
wp-db.php.2.patch (565 bytes) - added by darkfate 12 years ago.
updated to go to wp-content

Download all attachments as: .zip

Change History (18)

#1 @rob1n
12 years ago

  • Description modified (diff)

#2 @rob1n
12 years ago

  • Description modified (diff)

#3 @Otto42
12 years ago

Good idea. The problem is that the wp-db.php file loads way before pluggable or plugins or even the theme files. It's one of the very first files to load.

Hacking your code code is an obvious way to do it, of course. Unpleasant, but there you go.

Another not-so-obvious way is to copy the wp-db.php file to wp-content/db.php and hack it there instead. When Wordpress sees a db.php file in wp-content, it uses it instead of wp-db.php. The idea there seems to be to allow people to replace the DB code with other code entirely, perhaps to support other databases than mySQL.

But that's just ways to do it right now, of course.

#4 @linickx
12 years ago

Thanks, Basically I wanted a way to "theme" the DB down page after I've got WP running.

I had an issue with an "iffy" mysql db and my site was replaced with the normal "have you set up your db correctly ?", whereas what I needed was a "sorry but my site is down" page.

Thanks for the tip about using a db.php in wp-content, that'll save me having to hack wp after every upgrade :-D

#5 @Otto42
12 years ago

Yeah, I thought of a themed page, but the problem is that without the database, the code has no way to know what your theme is. So it would have to live outside the normal theme directories and such, and this adds some confusion to the whole theme idea.

#6 @technosailor
12 years ago

How about, when a theme is activated, we write some code to look for dbdown.php in the theme directory. If it exists, then a constant is written into wp-config.php with the url to the dbdown.php. By default, we serve up the standard db down page, however, if the constant is defined we serve that page up instead? Just thinking out loud...

#7 @linickx
12 years ago

sorry, perhaps I shouldn't have used the word "theme", you're right, it does add confusion. ;-) and perhaps over complexity .(if that makes sense?)

Personally, all I would like to see is an accepted solution to "if wordpress is down, do this" where by "this" is some externally executed code, ie. display a page, spam the admin, exec("mysqld restart"), whatever the admin can dream up :-D

#8 @intoxination
12 years ago

I believe the best solution would be to define a constant in wp-config to point to a user created database down page. If that constant isn't defined then the standard WP page shows. There is no way for WP to know which theme to look in since it can't connect to the database to see which theme is activated. The only option I see is going the constant route, then adding a page to codex explaining it.

Anyway - I give this idea a big +1

#9 @masquerade
12 years ago

I think the original solution that was originally suggested in the actual ticket, that seems to have been ignored, is the best idea. Its kinda frustrating that it was just entirely ignored by the responses to the ticket.

No (attempts at) writing to strange files automatically. No magic constants. Do like we do with many other files. Fin.

@darkfate
12 years ago

patch to look for db-down.php in wp-includes, go to default if not found

#10 follow-up: @darkfate
12 years ago

You can use $message in db-down.php too, but I'm assuming the whole point is to add your own text.

#11 @darkfate
12 years ago

  • Owner changed from anonymous to darkfate
  • Status changed from new to assigned

#12 @darkfate
12 years ago

  • Keywords has-patch added

#13 in reply to: ↑ 10 ; follow-up: @westi
12 years ago

  • Keywords needs-patch added; has-patch removed

The current patch doesn't quite cut it.

The configurable file should need to be placed in wp-content not wp-includes like all the other files.

Should we not make wp_die itself pluggable instead to make all die messages themeable?

@darkfate
12 years ago

updated to go to wp-content

#14 in reply to: ↑ 13 @darkfate
12 years ago

Replying to westi:

The current patch doesn't quite cut it.

The configurable file should need to be placed in wp-content not wp-includes like all the other files.

Should we not make wp_die itself pluggable instead to make all die messages themeable?

Well I think it's a good idea to have a default function. No need to make more excess code that only pro-bloggers are going to use. wp_die() can be used if people want the default theming and they just have to plop this file in if they want to modify it.

#15 @darkfate
11 years ago

  • Keywords has-patch added; needs-patch removed

I'm marking this has-patch. If anyone agrees with westi, I encourage them to make another patch.

#16 @darkdragon
11 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone 2.4 deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Closing as duplicate of #5500.

If wp_die is going to be themeable then it should be in a new ticket.

Note: See TracTickets for help on using tickets.