[wp-trac] [WordPress Trac] #15190: _default_wp_die_handler should accept pretty HTML

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 22 07:00:51 UTC 2010


#15190: _default_wp_die_handler should accept pretty HTML
------------------------------+---------------------------------------------
 Reporter:  5ubliminal        |       Owner:                 
     Type:  enhancement       |      Status:  new            
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Warnings/Notices  |     Version:  3.0.1          
 Severity:  normal            |    Keywords:                 
------------------------------+---------------------------------------------
 '''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 :)
 wp_die(function(){
         ob_start();
         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)''':


 {{{
 elseif(is_callable($message)){
         // Or even OB yourself for safety
         ob_start();
         /* $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.

 Thanks.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15190>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list