因爲wordpress已經落後太多版本,並且PHP版本也是早期預設的7.2版本,目前已經建議是7.4,現在版本連插件都不安裝了,今天就來更新了一下,先備份檔案和資料庫,然後升級,PHP從7.2升級到7.4,然後WP也更新到最新版,訪問首頁報錯:
1 |
Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 |
還有
1 |
Fatal error: Uncaught Error: Call to a member function id() on array in /wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 Stack trace: #0 /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 /wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): preg_replace_callback('#()#msi', 'CrayonFormatter...', '<?xml version="...') #3 /wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): CrayonFormatter::format_mixed_code('<?xml version="...', Object(CrayonLang), Object(CrayonHighlighter)) #4 /wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): CrayonHighlighter->process() #5 /wp-content/plugins/crayon-syntax-highlighter/cr in /wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36 |
看來就是插件的問題,有強大的AI工具,建議如下修改;
crayon_langs.class.php的第340行左右由原來的:
1 2 3 4 5 |
// Override function clean_id($id) { $id = CrayonUtil::space_to_hyphen( strtolower(trim($id)) ); return preg_replace('/[^\w-+#]/msi', '', $id); } |
修改爲:
1 2 3 4 5 |
// Override function clean_id($id) { $id = CrayonUtil::space_to_hyphen(strtolower(trim($id))); return preg_replace('/[^\w\-\+#]/msi', '', $id); } |
修改後,插件就可以用了。連第二個錯誤貌似也消失了
後來有從其他人分享的經驗中也可以如下修改:
1 |
return preg_replace('/[^\w\-+#]/msi', '', $id); |
先記錄,後續再觀察狀況。
更新:有別人更新的分叉版本,改用分叉的版本了
https://github.com/urvanov-ru/crayon-syntax-highlighter