SMS Activate tiger-sms ChatGPT 账号/ChatGPT 代注册 OpenAI API 代充值

Crayon Syntax Highlighter 在新版本 PHP 下出现错误(Fatal Error)的解决办法

dajiaka OpenAI API key

Crayon Syntax Highlighter 是老王一直在用的一个 WordPress 代码高亮插件,虽然几年不更新了,但是功能一直正常使用。前几天老王将自己服务器的 PHP 升级到了 7.3 版本,结果站点出现了 Fatal Error,开启调试模式后,发现是 Crayon Syntax Highlighter 的问题,这里分享下解决方法。

一、相关文章

关于 Crayon Syntax Highlighter 的介绍以及 WordPress 如何开启调试模式,可以参考:

  1. WordPress 此站点正遇到技术问题,如何开启 WordPress 调试模式
  2. Crayon Syntax Highlighter 转义问题:&& 显示不正确

二、问题描述

莫打开调试模式前,使用到 Crayon Syntax Highlighter 的文章会提示“此站点正在遇到技术问题”,没有用代码的文章则会正常显示。打开 WordPress 调试模式后,可以看到有这么一个 Fatal Error

Fatal error: Uncaught Error: Call to a member function id() on array in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 
Stack trace: #0 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(538): 
CrayonFormatter::format_code('', Array, Object(CrayonHighlighter)) 
#1 [internal function]: 
CrayonFormatter::delim_to_internal(Array) 
#2 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): 
preg_replace_callback('#()#msi', 'CrayonFormatter...', '{\r\n "founder...') 
#3 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): 
CrayonFormatter::format_mixed_code('{\r\n "founder...', Object(CrayonLang), Object(CrayonHighlighter)) 
#4 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): 
CrayonHighlighter->process() 
#5 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighte in 
/www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36

以及一些 Warning

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 
in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

站点无法正常显示。

三、解决方法

1、停用插件

最简单的就是停用 Crayon Syntax Highlighter,一般主题其实也能正常显示代码的,例如老王用的 DUX 就能正常显示由 Crayon Syntax Highlighter 生成的代码,所以老王直接停用了。

2、修改插件源代码

以下解决办法和截图参考:https://crunchify.com/fix-for-crayon-syntax-highlighter-wordpress-plugin-and-php-7-3-fatal-error/

1.修改文件 crayon_langs.class.php

340 行,return preg_replace('/[^\w-+#]/msi', '', $id); 改成 return preg_replace('/[^\w\-+#]/msi', '', $id);

Crayon Syntax Highlighter 在新版本 PHP 下出现错误(Fatal Error)的解决办法

2.修改文件 crayon_formatter.class.php

旧代码:

$toolbar_height = $font_size * 1.5 . 'px !important;';
$info_height = $font_size * 1.4 . 'px !important;';

新代码:

$crunchify_height = 1.5;
$toolbar_height = $_font_size * $crunchify_height . 'px !important;';
$info_height = $_font_size * $crunchify_height . 'px !important;';

Crayon Syntax Highlighter 在新版本 PHP 下出现错误(Fatal Error)的解决办法

3.修改文件 crayon_settings.class.php

Crayon Syntax Highlighter 在新版本 PHP 下出现错误(Fatal Error)的解决办法

赞(1)
关注我们
未经允许不得转载:老王博客 » Crayon Syntax Highlighter 在新版本 PHP 下出现错误(Fatal Error)的解决办法