阿里云主机

万维景盛

万维景盛官网
怎样调试wordpress网站显示具体报错信息?

调试PHP代码是任何项目的一部分,但WordPress提供了特定的调试系统,旨在简化过程,并跨核心、插件和主题标准化代码。万维景盛工程师为用户分享WordPress开发中的各种调试工具,以及如何提高编码效率、提高代码的总体质量和可操作性。如果你觉得用wordpress建站太复杂,可以选择模板网站建站——飞思建站,简单成熟的企业网站管理系统,丰富的管理模块,即装即用,售后无忧,价格可承受。

对于非程序员或普通用户,这些选项可用于显示有关错误的详细信息。

示例wp-config.php用于调试#示例wp-config.php用于调试

插入到wp-config.php文件中的以下代码将把所有错误、通知和警告记录到wp-content目录中名为debug.log的文件中。它还将隐藏错误,以便它们不会中断页面生成。

//启用WP_调试模式

define('WP_DEBUG',true);

//启用对/wp content/Debug.log文件的调试日志记录

define('WP_DEBUG_LOG',true);

//禁用错误和警告的显示

define('WP_DEBUG_DISPLAY',false);

@ini_set('display_errors',0);

//使用核心JS和CSS文件的开发版本(只有在修改这些核心文件时才需要)

define('SCRIPT_DEBUG',true);

注意:您必须在/*之前插入此项。仅此而已,停止编辑!快乐博客。*/在wp-config.php文件中。

WP#u调试#WP#u调试

WP_DEBUG是一个PHP常量(一个永久性全局变量),可用于在整个WordPress中触发“调试”模式。默认情况下,它假定为false,并且通常在WordPress开发副本的wp-config.php文件中设置为true。

//这将启用调试。

define('WP_DEBUG',true);

//这将禁用调试。

define('WP_DEBUG',false);

注意:示例中的true和false值没有被撇号(')包围,因为它们是布尔值(true/false)。如果将常量设置为“false”,它们将被解释为true,因为引号使其成为字符串而不是布尔值。

不建议在现场使用WP_DEBUG或其他调试工具;它们用于本地测试和临时安装。

PHP错误、警告和通知#PHP错误、警告和通知

启用WP_DEBUG将显示所有PHP错误、通知和警告。这可能会修改PHP的默认行为,该行为仅显示致命错误和/或在出现错误时显示白色死亡屏幕。


Debugging PHP code is part of any project, but WordPress comes with specific debug systems designed to simplify the process as well as standardize code across the core, plugins and themes. This page describes the various debugging tools in WordPress and how to be more productive in your coding as well as increasing the overall quality and interoperativity of your code.


For non-programmers or general users, these options can be used to show detailed information about errors.


Example wp-config.php for Debugging #Example wp-config.php for Debugging

The following code, inserted in your wp-config.php file, will log all errors, notices, and warnings to a file called debug.log in the wp-content directory. It will also hide the errors so they do not interrupt page generation.


// Enable WP_DEBUG mode

define( 'WP_DEBUG', true );


// Enable Debug logging to the /wp-content/debug.log file

define( 'WP_DEBUG_LOG', true );


// Disable display of errors and warnings

define( 'WP_DEBUG_DISPLAY', false );

@ini_set( 'display_errors', 0 );


// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)

define( 'SCRIPT_DEBUG', true );

NOTE: You must insert this BEFORE /* That's all, stop editing! Happy blogging. */ in the wp-config.php file.


WP_DEBUG #WP_DEBUG

WP_DEBUG is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress.


// This enables debugging.

define( 'WP_DEBUG', true );

// This disables debugging.

define( 'WP_DEBUG', false );

Note: The true and false values in the example are not surrounded by apostrophes (‘) because they are boolean (true/false) values. If you set constants to 'false', they will be interpreted as true because the quotes make it a string rather than a boolean.


It is not recommended to use WP_DEBUG or the other debug tools on live sites; they are meant for local testing and staging installs.


PHP Errors, Warnings, and Notices #PHP Errors, Warnings, and Notices

Enabling WP_DEBUG will cause all PHP errors, notices and warnings to be displayed. This is likely to modify the default behavior of PHP which only displays fatal errors and/or shows a white screen of death when errors are reached.

显示所有PHP通知和警告通常会导致错误消息,这些消息似乎没有被破坏,但在PHP中没有遵循正确的数据验证约定。一旦识别出相关的代码,这些警告就很容易修复,并且生成的代码几乎总是更能抵抗bug,更易于维护。

弃用的函数和参数#弃用的函数和参数

启用WP_DEBUG还将引起关于站点上使用的WordPress中不推荐使用的函数和参数的通知。这些函数或函数参数尚未从核心代码中删除,但将在不久的将来删除。弃用通知通常指示应该使用的新函数。

WP_调试日志#WP_调试日志

WP_DEBUG_LOG是WP_DEBUG的伴奏,它会导致所有错误也保存到DEBUG.LOG日志文件中。如果您希望稍后查看所有通知或需要查看屏幕外生成的通知(例如,在AJAX请求或WP cron运行期间),此功能非常有用。

请注意,这允许您使用PHP内置的error_log()函数写入日志文件,例如在调试Ajax事件时,该函数非常有用。

当设置为true时,日志将保存到站点文件系统内内容目录(通常为wp content/debug.log)中的debug.log。或者,您可以将其设置为有效的文件路径,以便将文件保存到其他位置。

define('WP_DEBUG_LOG',true);

-或-

define('WP_DEBUG_LOG','/tmp/WP errors.LOG');

注意:要使WP_DEBUG_LOG执行任何操作,必须启用WP_DEBUG(true)。请记住,您可以单独关闭WP_调试_显示。

WP_调试_显示#WP_调试_显示

WP_DEBUG_DISPLAY是WP_DEBUG的另一个助手,它控制调试消息是否显示在页面的HTML中。默认值为“true”,在生成错误和警告时显示错误和警告。将此设置为false将隐藏所有错误。这应该与WP_DEBUG_LOG一起使用,以便以后可以查看错误。

define('WP_DEBUG_DISPLAY',false);

注意:要使WP_DEBUG_显示执行任何操作,必须启用WP_DEBUG(真)。请记住,您可以独立控制WP_调试_日志。

脚本调试#脚本调试

SCRIPT_DEBUG是一个相关常量,它将强制WordPress使用核心CSS和JavaScript文件的“dev”版本,而不是通常加载的小型版本。当您测试对任何内置.js或.css文件的修改时,这非常有用。默认值为false。

define('SCRIPT_DEBUG',true);

保存查询#保存查询

SAVEQUERIESdefine将数据库查询保存到一个数组中,可以显示该数组以帮助分析这些查询。define为true的常量会导致保存每个查询、执行该查询所用的时间以及调用该查询的函数。

define('savequerys',true);

数组存储在全局$wpdb->querys中。

注意:这将对站点的性能产生影响,因此请确保在不调试时关闭此选项。


Showing all PHP notices and warnings often results in error messages for things that don’t seem broken, but do not follow proper data validation conventions inside PHP. These warnings are easy to fix once the relevant code has been identified, and the resulting code is almost always more bug-resistant and easier to maintain.


Deprecated Functions and Arguments #Deprecated Functions and Arguments

Enabling WP_DEBUG will also cause notices about deprecated functions and arguments within WordPress that are being used on your site. These are functions or function arguments that have not been removed from the core code yet but are slated for deletion in the near future. Deprecation notices often indicate the new function that should be used instead.


WP_DEBUG_LOG #WP_DEBUG_LOG

WP_DEBUG_LOG is a companion to WP_DEBUG that causes all errors to also be saved to a debug.log log file This is useful if you want to review all notices later or need to view notices generated off-screen (e.g. during an AJAX request or wp-cron run).


Note that this allows you to write to log file using PHP’s built in error_log() function, which can be useful for instance when debugging Ajax events.


When set to true, the log is saved to debug.log in the content directory (usually wp-content/debug.log) within your site’s filesystem. Alternatively, you can set it to a valid file path to have the file saved elsewhere.


define( 'WP_DEBUG_LOG', true );

-or-

define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

Note: for WP_DEBUG_LOG to do anything, WP_DEBUG must be enabled (true). Remember you can turn off WP_DEBUG_DISPLAY independently.


WP_DEBUG_DISPLAY #WP_DEBUG_DISPLAY

WP_DEBUG_DISPLAY is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with WP_DEBUG_LOG so that errors can be reviewed later.


define( 'WP_DEBUG_DISPLAY', false );

Note: for WP_DEBUG_DISPLAY to do anything, WP_DEBUG must be enabled (true). Remember you can control WP_DEBUG_LOG independently.


SCRIPT_DEBUG #SCRIPT_DEBUG

SCRIPT_DEBUG is a related constant that will force WordPress to use the “dev” versions of core CSS and JavaScript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. Default is false.


define( 'SCRIPT_DEBUG', true );


SAVEQUERIES #SAVEQUERIES

The SAVEQUERIES definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.


define( 'SAVEQUERIES', true );

The array is stored in the global $wpdb->queries.


NOTE: This will have a performance impact on your site, so make sure to turn this off when you aren’t debugging.


< 购物车 > 会员 客服 充值 工单
Top

客服热线

010-80253326

18610695105

客服QQ

请拨总机 010-80253326

咨询售后问题建议 提交工单