开发WordPress主题和插件,如果调试。

来源:https://www.shanhubei.com/archives/11789.html

开发WordPress主题和插件,如果调试。

一、使用自带,设置一下:

 wp-config.php 文件中添加一行代码以打开调试模式
define('WP_DEBUG', true);
//启用调试日志记录到 /wp-content/debug.log 文件
define('WP_DEBUG_LOG', true) ;

//禁止显示错误和警告
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

二、自定义日志输出函数

function write_log( $data ) {
    if ( true === WP_DEBUG ) {
        if ( is_array( $data ) || is_object( $data ) ) {
            error_log( print_r( $data, true ) );
        } else {
            error_log( $data );
        }
    }
}

//在需要的地方
write_log( 'DEBUG TEXT' );
write_log( $variable );
 

 

详细你可以看一下官方的说明:https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/

posted @ 2024-01-25 17:48  珊瑚贝博客  阅读(119)  评论(0)    收藏  举报