WordPress开发技巧:如何开启调试模式

前端之家收集整理的这篇文章主要介绍了WordPress开发技巧:如何开启调试模式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我们在使用wordpress开发网站的时候,很多时候会出现一些莫名其妙的问题,但是页面中并没有显示出来错误信息,这时候的我们总是一头雾水,不知道自己该朝哪个方向努力。这篇WordPress教程里,我们就向大家介绍一下开启wordpress调试模式的方法

打开网站根目录,找到wp-config.php文件,将原来的 WP_Debug 设置修改如下:

301_155@-5c891d12dfb8c753924540" class="@R_301_155@-Syntax @R_301_155@-theme-classic @R_301_155@-font-monaco @R_301_155@-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
301_155@-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">301_155@-title">wp-config.php
301_155@-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
301_155@-button @R_301_155@-nums-button" title="Toggle Line Numbers">
301_155@-button-icon">
301_155@-button @R_301_155@-plain-button" title="Toggle Plain Code">
301_155@-button-icon">
301_155@-button @R_301_155@-wrap-button" title="Toggle Line Wrap">
301_155@-button-icon">
301_155@-button @R_301_155@-expand-button" title="Expand Code">
301_155@-button-icon">
301_155@-button @R_301_155@-copy-button" title="Copy">
301_155@-button-icon">
301_155@-button @R_301_155@-popup-button" title="Open Code In New Window">
301_155@-button-icon">
301_155@-language">PHP
301_155@-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
301_155@-plain-wrap">
301_155@-main" style="">301_155@-table">301_155@-row">
301_155@-nums " data-settings="show">
301_155@-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
301_155@-num" data-line="@R_301_155@-5c891d12dfb8c753924540-1">1
301_155@-num @R_301_155@-striped-num" data-line="@R_301_155@-5c891d12dfb8c753924540-2">2
301_155@-code">
301_155@-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
301_155@-line" id="@R_301_155@-5c891d12dfb8c753924540-1">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG'301_155@-sy">,301_155@-h"> 301_155@-t">true301_155@-sy">)301_155@-sy">;
301_155@-line @R_301_155@-striped-line" id="@R_301_155@-5c891d12dfb8c753924540-2">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG_DISPLAY'301_155@-sy">,301_155@-h"> 301_155@-t">true301_155@-sy">)301_155@-sy">;

这样我们就可以看到错误的日志log了。但是有些错误是发生在某些后台进程里,比如cron job,没法显示错误log,这是我们就需要把错误log保存到debug文件中。修改上面的代码如下:

301_155@-5c891d12dfb94265384499" class="@R_301_155@-Syntax @R_301_155@-theme-classic @R_301_155@-font-monaco @R_301_155@-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
301_155@-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">301_155@-title">wp-config.php
301_155@-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
301_155@-button @R_301_155@-nums-button" title="Toggle Line Numbers">
301_155@-button-icon">
301_155@-button @R_301_155@-plain-button" title="Toggle Plain Code">
301_155@-button-icon">
301_155@-button @R_301_155@-wrap-button" title="Toggle Line Wrap">
301_155@-button-icon">
301_155@-button @R_301_155@-expand-button" title="Expand Code">
301_155@-button-icon">
301_155@-button @R_301_155@-copy-button" title="Copy">
301_155@-button-icon">
301_155@-button @R_301_155@-popup-button" title="Open Code In New Window">
301_155@-button-icon">
301_155@-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
301_155@-plain-wrap">
301_155@-main" style="">301_155@-table">301_155@-row">
301_155@-nums " data-settings="show">
301_155@-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
301_155@-num" data-line="@R_301_155@-5c891d12dfb94265384499-1">1
301_155@-num @R_301_155@-striped-num" data-line="@R_301_155@-5c891d12dfb94265384499-2">2
301_155@-num" data-line="@R_301_155@-5c891d12dfb94265384499-3">3
301_155@-code">
301_155@-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
301_155@-line" id="@R_301_155@-5c891d12dfb94265384499-1">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG'301_155@-sy">,301_155@-h"> 301_155@-t">true301_155@-sy">)301_155@-sy">;
301_155@-line @R_301_155@-striped-line" id="@R_301_155@-5c891d12dfb94265384499-2">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG_DISPLAY'301_155@-sy">,301_155@-h"> 301_155@-t">false301_155@-sy">)301_155@-sy">;
301_155@-line" id="@R_301_155@-5c891d12dfb94265384499-3">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG_LOG'301_155@-sy">,301_155@-h"> 301_155@-t">true301_155@-sy">)301_155@-sy">;

修改完成以后,我们可以在 wp-content文件夹下的 debug.log 文件中看到相应的错误信息。

切记网站调成成功以后,需要把调试模式关闭,否者一旦有错误,访问者也将看到网站的系统错误。还有就是wp-content文件夹下的debug.log会变得很大,把服务器的空间都用完。关闭的方式如下:

301_155@-5c891d12dfb96804750896" class="@R_301_155@-Syntax @R_301_155@-theme-classic @R_301_155@-font-monaco @R_301_155@-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
301_155@-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">301_155@-title">wp-config.php
301_155@-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
301_155@-button @R_301_155@-nums-button" title="Toggle Line Numbers">
301_155@-button-icon">
301_155@-button @R_301_155@-plain-button" title="Toggle Plain Code">
301_155@-button-icon">
301_155@-button @R_301_155@-wrap-button" title="Toggle Line Wrap">
301_155@-button-icon">
301_155@-button @R_301_155@-expand-button" title="Expand Code">
301_155@-button-icon">
301_155@-button @R_301_155@-copy-button" title="Copy">
301_155@-button-icon">
301_155@-button @R_301_155@-popup-button" title="Open Code In New Window">
301_155@-button-icon">
301_155@-language">PHP
301_155@-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
301_155@-plain-wrap">
301_155@-main" style="">301_155@-table">301_155@-row">
301_155@-nums " data-settings="show">
301_155@-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
301_155@-num" data-line="@R_301_155@-5c891d12dfb96804750896-1">1
301_155@-code">
301_155@-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
301_155@-line" id="@R_301_155@-5c891d12dfb96804750896-1">301_155@-e">define301_155@-sy">(301_155@-s">'WP_DEBUG'301_155@-sy">,301_155@-h"> 301_155@-t">false301_155@-sy">)301_155@-sy">;

猜你在找的wordpress相关文章