在新版的WordPress中,系统已经多次提示升级PHP,考虑到新版本更高效更安全,所以决定升级。
可是,升级完成后,网站出现大量报错,报错信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 |
如果上面的代码不直观的话,可以看下图,满屏的报错。
可以很直观的看出错误是来自一款叫 Crayon Syntax Highlighter 的代码高亮插件,在7.1等版本中并没有这个报错,显而易见的是,肯定是新版本语法或表达的变化造成的报错。
解决的办法也很简单,找到报错的文件与行数,进行修改即可,报错的文件是 crayon_langs.class.php的340行。
一般我们可以通过更新插件能适配到最新版的wordpress和PHP,但遗憾的是:
这款插件已经于4年前停止更新了,所以我们需要自己解决,解决的方法很简单:
修改这行代码为下方即可解决该报错信息。
1 |
return preg_replace('/\[^\w-+#]/msi', '', $id); |
即加上转义符好就能解决。