| 1 |
<?php |
| 2 |
|
| 3 |
class EasyOptInsErrorHandler { |
| 4 |
public $errors = array(); |
| 5 |
public $output = array(); |
| 6 |
|
| 7 |
public function capture_start() { |
| 8 |
ob_start(); |
| 9 |
|
| 10 |
set_error_handler( array( $this, 'handle_error' ), E_USER_ERROR ); |
| 11 |
|
| 12 |
add_filter( 'wp_die_handler', array( $this, 'handle_die' ) ); |
| 13 |
add_filter( 'wp_die_ajax_handler', array( $this, 'handle_die' ) ); |
| 14 |
} |
| 15 |
|
| 16 |
public function capture_end() { |
| 17 |
ob_end_clean(); |
| 18 |
|
| 19 |
restore_error_handler(); |
| 20 |
|
| 21 |
remove_filter( 'wp_die_handler', array( $this, 'handle_die' ) ); |
| 22 |
remove_filter( 'wp_die_ajax_handler', array( $this, 'handle_die' ) ); |
| 23 |
} |
| 24 |
|
| 25 |
public function handle_error( $err_no, $err_str ) { |
| 26 |
$this->output[] = ob_get_clean(); |
| 27 |
ob_start(); |
| 28 |
|
| 29 |
$this->errors[] = $err_str; |
| 30 |
} |
| 31 |
|
| 32 |
public function handle_die() { |
| 33 |
$output = ob_get_clean(); |
| 34 |
ob_start(); |
| 35 |
|
| 36 |
$this->output[] = $output; |
| 37 |
|
| 38 |
return array( $this, 'handle_die_callback' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function handle_die_callback( $message ) { |
| 42 |
$this->errors[] = $message; |
| 43 |
|
| 44 |
return true; |
| 45 |
} |
| 46 |
} |
| 47 |
|