MC4WP_API_Exception::__toString ()

Return: (string)

Source file: api/class-exception.php

View source


Used by

Uses


Source

    public function __toString() {
        $string = $this->message . '.';

        if( ! empty( $this->detail ) ) {
            $string .= ' ' . $this->detail;
        }


        if( ! empty( $this->errors ) && isset( $this->errors[0]->field ) ) {

            // strip off obsolete msg
            $string = str_replace( 'For field-specific details, see the \'errors\' array.', '', $string );

            // generate list of field errors
            $field_errors = array();
            foreach( $this->errors as $error ) {
                if( ! empty( $error->field ) ) {
                    $field_errors[] = sprintf( '- %s : %s', $error->field, $error->message );
                } else {
                    $field_errors[] = sprintf( '- %s', $error->message );
                }
            }

            $string .= " \n" . join( "\n", $field_errors );
        }

        return $string;
    }
}

User Contributed Notes

You must log in before being able to contribute a note.