Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#15190 closed enhancement (worksforme)

_default_wp_die_handler should accept pretty HTML

Reported by: 5ubliminal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: Warnings/Notices Keywords:
Focuses: Cc:


wp_die() is a very easy to use function to output a message but it has a problem with more advanced HTML is it gets enclosed in the <p> tag.

See here:

$message = "<p>{$errors[0]}</p>";
$message = "<p>$message</p>";

A solution that keeps backward compatibility would be to allow a callback for that function or accept an Exception object that could wrap some advanced HTML. So we could use:

// Used PHP 5.3 syntax here but you get the picture :)
	echo 'something!';
	return ob_get_clean();
}, ...);

... or (but not sure if it has a length limit) ...

wp_die(new Exception('HTML CODE COMES HERE'), ...);

This way, you could check like this, right after the is_string($message):

	// Or even OB yourself for safety
	/* $message = */ call_user_func($message); // Call it
	// But it can be left to the callback
	$message = ob_get_clean();
}elseif(is_object($message) && @is_a($message, 'Exception')){
	$message = $message->getMessage();

This can be currently hacked by using an object that takes a string in the construct and exposes it in string but it's a PITA to carry it all around.


Change History (2)

comment:1 follow-up: nacin3 years ago

  • Keywords reporter-feedback close added

I don't really see a point to this.

comment:2 in reply to: ↑ 1 ocean903 years ago

  • Keywords reporter-feedback close removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Replying to nacin:

I don't really see a point to this.

_default_wp_die_handler() will echo the message in <p> tags. If you have a message with some other HTML tags:


the output will be not valid:


But there is a solution to prevent this, you can define your own wp_die handler.

Note: See TracTickets for help on using tickets.