一段wordpress的Theme DEBUG程序

作者:yinheli http://philna.com
出处:philna2主题
位置:app/debug.php
作用:开启自定义DEBUG后,在页脚上集中显示错误提示,而不是在分散在出错位置上直接显示
使用方法:在functions.php文件中设置自定义DEBUG选项,define('THEME_DEBUG',true); 或者false.

PHP语言: 高亮代码由发芽网提供
<?php
if(defined('THEME_DEBUG') && constant('THEME_DEBUG')){
//如果定义了自定义DEBUG,则设置错误处理函数
    set_error_handler('ErrorHandler', E_ALL);
    $GLOBALS['PHPErrorMessage'] = array();
    //设置错误信息数组
}
/**
* @param int $errno contains the level of the error raised, as an integer.
* @param string $errstr contains the error message, as a string.
* @param string $errfile which contains the filename that the error was raised in, as a string.
* @param int $errline contains the line number the error was raised at, as an integer.
* @param array $errcontext which is an array that points to the active symbol table at the point the error occurred...
* @return unknown_type
*/
function ErrorHandler($errno, $errstr, $errfile, $errline, $errcontext){
    static $id = 1;
    if(!is_user_logged_in()){
        return;
    //如果不是管理员登录,则直接返回
    }
    //判断错误级别
    switch($errno){
        case E_WARNING : case E_USER_WARNING :
            $type = 'Warning';
            break;
        case E_NOTICE : case E_USER_NOTICE :
            $type = 'Notice';
            break;
        default :
            $type = 'Error';
            break;
    }
    //填充错误信息数组
    $GLOBALS['PHPErrorMessage'][] = 'ID: '.$id.' '.$type.': '.$errfile.' line: '.$errline.' '.$errstr;
    $id++;
    return;
}
//echo E_NOTICE;
function DisplayPHPErrorMessage(){
    //if(is_bot()) return;
    if(isset($GLOBALS['PHPErrorMessage']) && $GLOBALS['PHPErrorMessage']){
        echo '<div style="margin: 0 auto; width: 898px"><h3>PHP errors on this blog</h3><ul>';
        foreach($GLOBALS['PHPErrorMessage'] as $message){
            echo '<li>', $message, '</li>';
        }
        echo '</ul></div>';
    }
}
add_action('wp_footer', 'DisplayPHPErrorMessage', 0);
?>

相关文章

  • PhilNa2首页文章收缩再修复 ( 18 )
    前面讲到过关于使用philna2收缩而进行的一些修改.具体请看PhilNa2首页文章收缩及问题修复...
  • W1s 首页Ajax翻页新效果 ( 14 )
    最近真的累了,鼓捣了这么多感到有点身心俱疲...,现在我越来越发现PhilNa2的省心了...神马...
  • 代码访问随机日志 ( 6 )
    不记得是怎么找到这篇文章的,但是很庆幸,又找到了好东西.哈哈原来在IM路人 的博客中看到...
  • 短代码 mp3player ( 1 )
    代码来源感谢 良心发现的WP短代码集成音乐播放器 以及荒野无灯weblog 的 不用audio-play...
  • 嵌套评论的问题及向Japhia,邓肯致歉 ( 25 )
    写这篇文章之前,首先要对Japhia 以及邓肯 两位朋友表示抱歉,因为我的一时小聪明,而连累到...