WP-Editor.MD升级后 500问题解决
使用 markdown 格式来发布 blog,遇到语法渲染的问题,升级 WP-Editor.MD。
1. 现象
升级 WP-Editor.MD 后发布文章入口出现 500 错误,停用 WP-Editor.MD 后可以正常访问。
2. 调测
修改根目录下 wp-config.php 中
/** * 开发者专用:WordPress调试模式。 * * 将这个值改为true,WordPress将显示所有用于开发的提示。 * 强烈建议插件开发者在开发环境中启用WP_DEBUG。 * * 要获取其他能用于调试的信息,请访问Codex。 * * @link https://codex.wordpress.org/Debugging_in_WordPress */ define('WP_DEBUG', true); // false -> ture
重新访问文章发布页面:
Fatal error: Cannot redeclare Markdown() (previously declared in wordpress/wp-content/plugins/jetpack-markdown/markdown/lib/extra.php:51) in wordpress/wp-content/plugins/wp-editormd/Jetpack/lib/markdown/extra.phpon line 67
3. 解决
WP-Editor.MD 插件底层使用WordPress Jetpack 的Markdown模块来解析和保存内容,因此可能是相关的插件存在冲突
通过报错可以看到是函数 Markdown()
重复定义造成的,
在 插件 jetpack
中定义了一个函数 Markdown()
, 由于 wp-editormd
底层也是用了 Jetpack 底层的 Markdown 模块,造成包含库的时间有冲突。
wordpress/wp-content/plugins/jetpack/_inc/lib/markdown/extra.php
### Standard Function Interface ### @define( 'MARKDOWN_PARSER_CLASS', 'MarkdownExtra_Parser' ); function Markdown($text) { # # Initialize the parser and return the result of its transform method. # # Setup static parser variable. static $parser; if (!isset($parser)) { $parser_class = MARKDOWN_PARSER_CLASS; $parser = new $parser_class; } # Transform text using parser. return $parser->transform($text); }
wordpress/wp-content/plugins/wp-editormd/Jetpack/lib/markdown/extra.php
### Standard Function Interface ### @define( 'MARKDOWN_PARSER_CLASS', 'MarkdownExtra_Parser_Editormd' ); function Markdown($text) { # # Initialize the parser and return the result of its transform method. # # Setup static parser variable. static $parser; if (!isset($parser)) { $parser_class = MARKDOWN_PARSER_CLASS; $parser = new $parser_class; } # Transform text using parser. return $parser->transform($text); }
JetPack 插件也打开md语法功能,造成冲突,关闭 JetPack md 语法功能,或者将两个文件中的文件名修改一个;作者在最新版本已经修复该问题,参见 commit
关闭 wordpress 调试模式
define('WP_DEBUG', false);