[wp-trac] [WordPress Trac] #28319: Add hook to WP_Error for logging and report purposes

WordPress Trac noreply at wordpress.org
Sun Aug 3 18:59:16 UTC 2014


#28319: Add hook to WP_Error for logging and report purposes
-----------------------------------+-----------------------------
 Reporter:  ebinnion               |       Owner:  johnbillion
     Type:  enhancement            |      Status:  reopened
 Priority:  normal                 |   Milestone:  Future Release
Component:  General                |     Version:  trunk
 Severity:  normal                 |  Resolution:
 Keywords:  2nd-opinion has-patch  |     Focuses:
-----------------------------------+-----------------------------
Changes (by ebinnion):

 * keywords:  2nd-opinion => 2nd-opinion has-patch


Comment:

 I have updated the patch to move the action to the add method as well as
 having the constructor call the add method.

 Because the action now runs on add, I changed the action name to
 add_wp_error.

 I used the following in a plugin to test:

 {{{
 add_action( 'init', 'test_something' );

 function test_something() {
         if ( isset( $_GET['test_error'] ) ) {
             $errors = new WP_Error();

             $errors->add( 'foo', 'A foo error has occurred.' );

             $errors->add( 'bar', 'A bar error has occurred.' );

             exit;
         }

 }

 add_action( 'add_wp_error', 'print_something' );
 function print_something( $error ) {
         echo '<pre>';
         print_r( $error );
         echo '</pre>';
 }
 }}}

 And I received the following output:

 {{{
 WP_Error Object
 (
     [errors:WP_Error:private] => Array
         (
             [foo] => Array
                 (
                     [0] => A foo error has occurred.
                 )

         )

     [error_data:WP_Error:private] => Array
         (
         )

 )
 WP_Error Object
 (
     [errors:WP_Error:private] => Array
         (
             [foo] => Array
                 (
                     [0] => A foo error has occurred.
                 )

             [bar] => Array
                 (
                     [0] => A bar error has occurred.
                 )

         )

     [error_data:WP_Error:private] => Array
         (
         )

 )
 }}}

 I'm not sure if it makes more sense to just pass the last error message or
 to pass the whole WP_Error object.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28319#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list