一段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);
?>
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);
?>
»»»本文链接地址:http://ISayMe.com/2011/11/wordpress-theme-debug-code/
»»»欢迎订阅本站:您可以选择通过RSS阅读器订阅
声明:如無特別申明,文章均為博主原創并遵循 BY-NC-SA-3.0. 转载请注明自说Me话 ™
»»»欢迎订阅本站:您可以选择通过RSS阅读器订阅
声明:如無特別申明,文章均為博主原創并遵循 BY-NC-SA-3.0. 转载请注明自说Me话 ™
6:35 下午
错误集中比较好 而且还是在页脚 分散的话就太影响视觉了
10:16 上午
都没有找错误的习惯
1:12 下午
这个会提示哪里出现错误?是php里面的错误,还是包含js错误的所有错误?
4:41 下午
@秦天SEO
提示的是PHP中的错误.js中的错误肯定不会提示啊 不在一起的.
PHP的错误是在服务器上运行时出现的.js中的错误是在浏览器中运行的时候出现的.不搭边
11:59 上午
本地测试有XDebug辅助了。。。
11:09 上午
表示看不太懂
9:17 上午
真的非常不知道怎么用呀