| | 741 | |
| | 742 | /** |
| | 743 | * Set up the PHP error handler |
| | 744 | * |
| | 745 | * @since 3.4.0 |
| | 746 | * @access private |
| | 747 | */ |
| | 748 | function wp_set_error_handler() { |
| | 749 | global $wp_php_errors; |
| | 750 | |
| | 751 | $wp_php_errors = array(); |
| | 752 | set_error_handler( 'wp_error_handler' ); |
| | 753 | |
| | 754 | if ( is_admin() ) |
| | 755 | add_action( 'admin_footer', 'wp_show_errors', 20 ); |
| | 756 | else |
| | 757 | add_action( 'wp_footer', 'wp_show_errors', 20 ); |
| | 758 | } |
| | 759 | |
| | 760 | /** |
| | 761 | * Resolve an error constant to its human readable name |
| | 762 | * |
| | 763 | * @since 3.4.0 |
| | 764 | * @access private |
| | 765 | * |
| | 766 | * @param int |
| | 767 | * @return string |
| | 768 | */ |
| | 769 | function wp_error_constant($errno) { |
| | 770 | $codes = array( |
| | 771 | E_ERROR => 'E_ERROR', |
| | 772 | E_WARNING => 'E_WARNING', |
| | 773 | E_PARSE => 'E_PARSE', |
| | 774 | E_NOTICE => 'E_NOTICE', |
| | 775 | E_CORE_ERROR => 'E_CORE_ERROR', |
| | 776 | E_CORE_WARNING => 'E_CORE_WARNING', |
| | 777 | E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
| | 778 | E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
| | 779 | E_USER_ERROR => 'E_USER_ERROR', |
| | 780 | E_USER_WARNING => 'E_USER_WARNING', |
| | 781 | E_USER_NOTICE => 'E_USER_NOTICE', |
| | 782 | E_STRICT => 'E_STRICT', |
| | 783 | E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', |
| | 784 | E_DEPRECATED => 'E_DEPRECATED', |
| | 785 | E_USER_DEPRECATED => 'E_USER_DEPRECATED', |
| | 786 | ); |
| | 787 | |
| | 788 | return isset( $codes[$errno] ) ? $codes[$errno] : $errno; |
| | 789 | } |
| | 790 | |
| | 791 | /** |
| | 792 | * Show PHP errors |
| | 793 | * |
| | 794 | * @since 3.4.0 |
| | 795 | * @access private |
| | 796 | * |
| | 797 | */ |
| | 798 | function wp_show_errors() { |
| | 799 | global $wp_php_errors; |
| | 800 | |
| | 801 | if ( !is_array( $wp_php_errors ) ) |
| | 802 | $wp_php_errors = array(); |
| | 803 | |
| | 804 | foreach ( (array) $wp_php_errors as $err ) : ?> |
| | 805 | <div class="error"> |
| | 806 | <p><?php echo sprintf( __( '<b>%1$s</b>: %2$s in <b>%3$s</b> on line <b>%4$d</b>' ), wp_error_constant( $err['errno'] ), $err['errstr'], $err['errfile'], $err['errline'] ); ?></p> |
| | 807 | </div> |
| | 808 | <?php |
| | 809 | endforeach; |
| | 810 | } |
| | 811 | |
| | 812 | /** |
| | 813 | * PHP error handler callback |
| | 814 | * |
| | 815 | * @since 3.4.0 |
| | 816 | * @access private |
| | 817 | * |
| | 818 | * @param int Error code |
| | 819 | * @param string Error message |
| | 820 | * @param string File where error occurred |
| | 821 | * @param int $errline Line number where error occurred |
| | 822 | * @return void |
| | 823 | */ |
| | 824 | function wp_error_handler($errno, $errstr, $errfile, $errline) { |
| | 825 | global $wp_php_errors; |
| | 826 | |
| | 827 | if ( !is_array( $wp_php_errors ) ) |
| | 828 | $wp_php_errors = array(); |
| | 829 | |
| | 830 | if ( error_reporting() & $errno ) |
| | 831 | $wp_php_errors[] = compact( 'errno', 'errstr', 'errfile', 'errline' ); |
| | 832 | } |