| | 656 | /** |
| | 657 | * Set up the php error handler |
| | 658 | */ |
| | 659 | function wp_set_error_handler() { |
| | 660 | global $wp_php_errors; |
| | 661 | $wp_php_errors = array(); |
| | 662 | set_error_handler( 'wp_error_handler' ); |
| | 663 | if ( is_admin() ) |
| | 664 | add_action( 'admin_footer', 'wp_show_errors' ); |
| | 665 | else |
| | 666 | add_action( 'wp_footer', 'wp_show_errors' ); |
| | 667 | } |
| | 668 | |
| | 669 | /** |
| | 670 | * Resolve an error constant to its human readable name |
| | 671 | * @param int |
| | 672 | * @return string |
| | 673 | */ |
| | 674 | function wp_error_constant($errno) { |
| | 675 | $codes = array( |
| | 676 | E_ERROR => 'E_ERROR', |
| | 677 | E_WARNING => 'E_WARNING', |
| | 678 | E_PARSE => 'E_PARSE', |
| | 679 | E_NOTICE => 'E_NOTICE', |
| | 680 | E_CORE_ERROR => 'E_CORE_ERROR', |
| | 681 | E_CORE_WARNING => 'E_CORE_WARNING', |
| | 682 | E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
| | 683 | E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
| | 684 | E_USER_ERROR => 'E_USER_ERROR', |
| | 685 | E_USER_WARNING => 'E_USER_WARNING', |
| | 686 | E_USER_NOTICE => 'E_USER_NOTICE', |
| | 687 | E_STRICT => 'E_STRICT', |
| | 688 | E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', |
| | 689 | E_DEPRECATED => 'E_DEPRECATED', |
| | 690 | E_USER_DEPRECATED => 'E_USER_DEPRECATED', |
| | 691 | ); |
| | 692 | return isset( $codes[$errno] ) ? $codes[$errno] : $errno; |
| | 693 | } |
| | 694 | |
| | 695 | /** |
| | 696 | * Show PHP errors |
| | 697 | */ |
| | 698 | function wp_show_errors() { |
| | 699 | global $wp_php_errors; |
| | 700 | if ( !is_array( $wp_php_errors ) ) |
| | 701 | $wp_php_errors = array(); |
| | 702 | foreach ( (array) $wp_php_errors as $err) : ?> |
| | 703 | <div class="error"> |
| | 704 | <div> |
| | 705 | <span class="php-errno"><?php echo wp_error_constant($err['errno']); ?></span> |
| | 706 | <?php echo __('in'); ?> |
| | 707 | <span class="php-errfile"><?php echo $err['errfile']; ?></span> |
| | 708 | <?php echo __('on line'); ?>: |
| | 709 | <span class="php-errstr"><?php echo $err['errstr']; ?></span> |
| | 710 | </div> |
| | 711 | </div> |
| | 712 | <?php |
| | 713 | endforeach; |
| | 714 | } |
| | 715 | |
| | 716 | /** |
| | 717 | * PHP error handler callback |
| | 718 | * @param int Error code |
| | 719 | * @param string Error message |
| | 720 | * @param string File where error occurred |
| | 721 | * @param int $errline Line number where error occurred |
| | 722 | * @return void |
| | 723 | */ |
| | 724 | function wp_error_handler($errno, $errstr, $errfile, $errline) { |
| | 725 | global $wp_php_errors; |
| | 726 | if ( !is_array( $wp_php_errors ) ) |
| | 727 | $wp_php_errors = array(); |
| | 728 | if ( error_reporting() & $errno ) { |
| | 729 | $wp_php_errors[] = array( |
| | 730 | 'errno' => $errno, |
| | 731 | 'errstr' => $errstr, |
| | 732 | 'errfile' => $errfile, |
| | 733 | 'errline' => $errline |
| | 734 | ); |
| | 735 | } |
| | 736 | } |
| | 737 | |