Make WordPress Core


Ignore:
Timestamp:
09/20/2020 05:43:00 PM (4 years ago)
Author:
johnbillion
Message:

General: Introduce the wp_error_added and wp_error_checked actions.

These actions allow debugging tools to track WP_Error instances as they're created and subsequently passed between functions which check for error objects.

Props Shelob9, Mte90, TimothyBlynJacobs, johnbillion

Fixes #40568

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-error.php

    r48586 r49022  
    5757        }
    5858
    59         $this->errors[ $code ][] = $message;
    60 
    61         if ( ! empty( $data ) ) {
    62             $this->error_data[ $code ] = $data;
    63         }
     59        $this->add( $code, $message, $data );
    6460    }
    6561
     
    177173
    178174    /**
    179      * Add an error or append additional message to an existing error.
     175     * Adds an error or appends an additional message to an existing error.
    180176     *
    181177     * @since 2.1.0
     
    187183    public function add( $code, $message, $data = '' ) {
    188184        $this->errors[ $code ][] = $message;
     185
    189186        if ( ! empty( $data ) ) {
    190             $this->error_data[ $code ] = $data;
    191         }
     187            $this->add_data( $data, $code );
     188        }
     189
     190        /**
     191         * Fires when an error is added to a WP_Error object.
     192         *
     193         * @since 5.6.0
     194         *
     195         * @param string|int $code     Error code.
     196         * @param string     $message  Error message.
     197         * @param mixed      $data     Error data. Might be empty.
     198         * @param WP_Error   $wp_error The WP_Error object.
     199         */
     200        do_action( 'wp_error_added', $code, $message, $data, $this );
    192201    }
    193202
Note: See TracChangeset for help on using the changeset viewer.