wordpress php7 兼容_WordPress升级PHP7后wp-code-highlight插件兼容性解决方法

原创内容,转载请注明出处:https://www.myzhenai.com.cn/post/3479.html

关键词:WordPress内容空白 升级PHP7后Wordpress内容空白 wp-code-highlight不能兼容PHP7 preg_replace_callback函数替换preg_replace函数

我刚才把自己服务器的PHP版本从5.4升级到了PHP7,但是在升级后却发现一个问题,所有首页和文章页的文章内容全部是空白的,我知道文章内容还在,但发生这样的问题让我很纳闷。

刚开始我以为是博客主题不兼容PHP7,但经过排查发现不是,我打开了Wordpress的调试功能,终于看到出错的报告文件来自于wp-code-highlight插件。

因为wp-code-highlight里使用了preg_replace函数,而这个函数已经被PHP抛弃了,因为安全问题,PHP7已经不支持这个函数了,现在用了preg_replace_callback函数替换代替。

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in //wp-content/plugins/wp-code-highlight/wp-code-highlight.php on line 68

Warning: preg_replace_callback(): Requires argument 2, ''< p r e class="wp-code-highlight prettyprint linenums:1">'.wch_stripslashes('$2').' p r e>'', to be a valid callback in /wp-content/plugins/wp-code-highlight/wp-code-highlight.php on line 68

e8d97a128ade44af5b129ddd6cd871aa.png

892ee408878c97a271ace76468e0a0dc.png

解决方法:

1、找到你博客安装路径,将wp-code-highlight.php这个文件下载到本地,用UE等编辑器打开,修改以下内容。查找preg_replace

2、用下边这一行内容替换掉源文件中的内容

function wp_code_highlight_filter($content) {

if(get_option('wp_code_highlight_line_numbers')=='enable'){

$line_numbers=' linenums:1';

}

else{

$line_numbers='';

}

return preg_replace("/

(.*?)/ise",

"'

'.wch_stripslashes('$2').'
'", $content);

}

function wp_code_highlight_filter($content) {

if(get_option('wp_code_highlight_line_numbers')=='enable'){

$line_numbers=' linenums:1';

}

else{

$line_numbers='';

}

return preg_replace_callback('/

(.*?)/is',

function ($m) {

return "

".$m[2].'
';

}, $content);

}

3cd0b151701a56c11ecb7ba4d359b7c5.png

参考内容:https://wordpress.org/support/topic/this-plugin-does-not-support-php7/#post-8043051

sicnature ---------------------------------------------------------------------

Your current IP address is: 125.119.64.209

Your IP address location: 浙江省杭州市电信

Your IP address country and region: 中国

d9840db1de5c066b3143a36b83ba0940.png

Your current browser is:

c55e3eff36f0c380a04e3e5ffee3bbca.png

Your current system is:

mac.png

Original content, please indicate the source:

同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog

sicnature ---------------------------------------------------------------------

Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/3479.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值