A-A+

wordpress 更新后各种错误解决方式集合

2021年08月05日 13:38 汪洋大海 暂无评论 共2542字 (阅读1,190 views次)

首先建议关闭自动更新
编辑WordPress程序目录下的wp-config.php文件,向其中添加如下代码:

define( ‘AUTOMATIC_UPDATER_DISABLED’, true );

一,报错Notice:Undefined index:submit in

原代码:

if( $_POST['submit'] ){ }

新代码:

if(isset($_POST['submit']) && $_POST['submit']) { }

别的相同类似报错都可以按这个方式来解决问题。

二,已不建议给has_cap传入一个参数!用户级别已被废弃,请改用能力。

在插件或主题文件中搜索关键词:add_options_page查找用户级别代码位置。

原代码:

add_options_page('Delete-Revision', 'Delete-Revision',8, basename(__FILE__), 'my_options_delete_revision');

新代码:

add_options_page('Delete-Revision', 'Delete-Revision','manage_options', basename(__FILE__), 'my_options_delete_revision');

主要是把红色的8修改为红色的manage_options。

三,Notice: 自3.1.0版本起,已不建议给WP_Query传入一个参数!“caller_get_posts”不再被建议使用。请改用“ignore_sticky_posts”
这个直接搜索查找替换文件里的:caller_get_posts 为 ignore_sticky_posts 即可。

四,Notice: 为WP_Widget调用的构造方法已自版本4.3.0起废弃!请改用 __construct()。
这个直接搜索查找替换文件里的:parent::WP_Widget 或 $this->WP_Widget 为 parent::__construct

五,create_function函数报错

php 7.3版本不推荐使用create_function函数,在php 7.3中使用create_function()函数会有兼容性报错Deprecated: Function create_function() is deprecated,解决方法是替换掉该函数。

以wordpress的代码为例,原代码如下

add_action('widgets_init', create_function('', 'return register_widget("contact");')); 

修改为

add_action('widgets_init', function(){register_widget('contact' );});

原代码:

$callbacks[$delimiter] = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");

修改为:

$callbacks[$delimiter] = function($matches) use ($delimiter) {
    return $delimiter . strtolower($matches[1]);
};

问题描述:
运行一个旧的php项目时报错:

  • PHP message: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
  • Warning: preg_replace_callback(): Requires argument 2, ‘iconv(‘UCS-2’, ‘UTF-8’,
  • Function create_function() is deprecated>

原因分析:

  • php 5.6之后的版本不再支持pre_replace()函数
  • 自PHP 7.2起,函数create_function因为代码注入漏洞已被弃用。从PHP 5.3开始,执行此操作的首选方法是使用匿名函数。要捕获外部变量的值,请使用use声明。

解决方案:

preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", json_encode($data));

修改为:

preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));}, json_encode($data));

或直接封装为一个函数,可实现更好地复用:

	function decodeUnicode($str){
		return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));}, $str);
	}

 

在xxxxx中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。

class EfanWebsitestat extends WP_Widget{

这个也不行,怎么改?

直接更改下面的函数

function EfanWebsitestat(){ 换成 function __construct(){即可

 

Notice: Undefined offset: 0 问题解决方案:

标题原写法是:
直接在用数组 arra[0]时出现 Notice: Undefined offset: 0,经过查询是数组未定义就是用。

if ($patientIDarray[0] == 'MLST'){
}
后查询说做个判断试试

$MLST = "";
if (isset($patientIDarray[0])) {
$MLST=$patientIDarray[0];
}
if ($MLST == "MLST"){
}
修改后解决问题,不报错了。

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×

给我留言