我正在开发一个wordpress项目,它工作正常
当我更新 PHP版本7.2.0 时,我收到这样的警告:
警告:使用未定义的常量WP_GURUS_DEBUG - 假设 'WP_GURUS_DEBUG'(这将在PHP的未来版本中引发错误) 在 C:\ WAMP \ WWW \ wordpress1 \可湿性粉剂内容\插件\后我接触形式-7 \包括\ WordPress的-大师调试,api.php 第9行
我的wordpress版本 4.9.1
我的插件:
发布我的CF7表格 版本3.2.0
这是插件文件:
<?php
/**
* Error logging and notices
* @since 1.0.0
* @var string $message to log if in debug mode
*/
if( !function_exists('debug_msg') ){
if (true === WP_DEBUG || true === WP_GURUS_DEBUG) {
$debug_msg_last_line='';
$debug_msg_last_file='';
}
function debug_msg($message,$prefix='') {
if (true === WP_DEBUG || true === WP_GURUS_DEBUG) {
global $debug_msg_last_line,$debug_msg_last_file;
$backtrace = debug_backtrace();
$file = $backtrace[0]['file'];
$files = explode('/',$file);
$dirs = explode('/',plugin_dir_path( __FILE__ ));
$files = array_diff($files,$dirs);
$file = implode('/',$files);
$line = $backtrace[0]['line'];
if($file != $debug_msg_last_file && $line != $debug_msg_last_line){
error_log("DEBUG_MSG: [".$line."]./".$file);
$debug_msg_last_file=$file;
$debug_msg_last_line=$line;
}else{
//error_log("CF7_2_POST: ");
}
if (is_array($message) || is_object($message)) {
error_log(" + ".$prefix.print_r($message, true));
} else {
error_log(" + ".$prefix.$message);
}
}
}
} ?>
如何解决此警告?
答案 0 :(得分:7)
Aurovrata Venet写道:
哎呀,我的坏!在v3.2.1中修复帖子链接: https://wordpress.org/support/topic/warning-use-of-undefined-constant-wp_gurus_debug/#post-9777594
WP_DEBUG
已经defined(默认情况下为false
),但默认情况下,WP_GURUS_DEBUG
显然未由插件定义。尝试使用未定义的常量将在未来的PHP版本中被视为错误,但作为一个单挑,他们将其显示为警告,以便为开发人员提供更新其代码的机会。
插件维护者需要更新行
if (true === WP_DEBUG || true === WP_GURUS_DEBUG) {
检查常量是否为defined,如下所示:
if ( ( defined( 'WP_DEBUG' ) AND true === WP_DEBUG ) || ( defined( 'WP_GURUS_DEBUG' ) AND true === WP_GURUS_DEBUG ) ) {