[wp-trac] [WordPress Trac] #19073: wp_die() can be a wrapper for WP_Error objects, but also triggers if no error is present

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 28 13:41:04 UTC 2011


#19073: wp_die() can be a wrapper for WP_Error objects, but also triggers if no
error is present
--------------------------+-----------------------------
 Reporter:  F J Kaiser    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.3
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 The function {{{wp_die( $message );}}} wraps up
 {{{_default_wp_die_handler( $message );}}} and both only have the argument
 {{{$message}}} as required.

 If you now pass a {{{WP_Error( $code, $message );}}} object to the die
 handler, the function automatically extracts the title from the
 {{{$data}}} array - as long as it's an array and you've a key named
 {{{'title'}}} and no {{{$title}}} argument was set when calling the
 function.

 This means that you can do something like this:
 {{{
 function my_custom_fn( $args = array() ) {
     $error = '';
     if ( ! isset( $args['some_key'] ) )
         $error = new WP_Error( __FUNCTION__, 'You are missing some_key' );

     if ( is_wp_error( $error ) )
         wp_die( $error );

     // do other stuff
 }
 }}}

 Problem with the above mentioned code is that {{{_default_wp_die_handler(
 $message );}}} does...
 {{{
 $errors = $message->get_error_messages();
 switch ( count( $errors ) ) :
 case 0 :
         $message = '';
         break;
 }}}
 ...and simply proceeds, even if no error is present. That's a senseless
 behavior.

 If we would simply abort/return at this point (case: error-count is 0), we
 could use {{{wp_die();}}} as on-demand wrapper for errors.

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


More information about the wp-trac mailing list