1)开启WordPress调试模式
在wp-config.php中添加以下代码:
define( "WP_DEBUG", true );
define( "WP_DEBUG_LOG", true );
打开后可以在wp-content\debug.log下查看程序报错。
2)也可以自己写bug日志,wp-includes\general-template.php下添加公共函数:
function addDebugLog($log)
{
date_default_timezone_set( 'Asia/Shanghai' );
$log = mb_convert_encoding($log, 'gbk', mb_detect_encoding($log));
$path = str_replace('\\', '/', dirname(__FILE__)) . '/debug/';
is_dir($path) || mkdir($path, 0777, true);
$fp = fopen($path . 'debug-log-' . date('Y-m-d') . '.txt', 'a');
flock($fp, LOCK_EX);
fwrite($fp, '[' . date('Y-m-d H:i:s') . ']' . $log . "\r\n");
flock($fp, LOCK_UN);
fclose($fp);
}
使用时,直接调用addDebugLog函数即可。