在wordpress中的Tools选项中安装wordpress导入器后,当我尝试激活它时,会出现致命错误。
相关php代码:
class WXR_Parser {
function parse( $file ) {
// Attempt to use proper XML parsers first
if ( extension_loaded( \'simplexml\' ) ) {
$parser = new WXR_Parser_SimpleXML;
$result = $parser->parse( $file );
// If SimpleXML succeeds or this is an invalid WXR file then return the results
if ( ! is_wp_error( $result ) || \'SimpleXML_parse_error\' != $result->get_error_code() )
return $result;
} else if ( extension_loaded( \'xml\' ) ) {
$parser = new WXR_Parser_XML;
$result = $parser->parse( $file );
// If XMLParser succeeds or this is an invalid WXR file then return the results
if ( ! is_wp_error( $result ) || \'XML_parse_error\' != $result->get_error_code() )
return $result;
}
// We have a malformed XML file, so display the error and fallthrough to regex
if ( isset($result) && defined(\'IMPORT_DEBUG\') && IMPORT_DEBUG ) {
echo \'<pre>\';
if ( \'SimpleXML_parse_error\' == $result->get_error_code() ) {
foreach ( $result->get_error_data() as $error )
echo $error->line . \':\' . $error->column . \' \' . esc_html( $error->message ) . "\\n";
} else if ( \'XML_parse_error\' == $result->get_error_code() ) {
$error = $result->get_error_data();
echo $error[0] . \':\' . $error[1] . \' \' . esc_html( $error[2] );
}
echo \'</pre>\';
echo \'<p><strong>\' . __( \'There was an error when reading this WXR file\', \'wordpress-importer\' ) . \'</strong><br />\';
echo __( \'Details are shown above. The importer will now try again with a different parser...\', \'wordpress-importer\' ) . \'</p>\';
}
// use regular expressions if nothing else available or this is bad XML
$parser = new WXR_Parser_Regex;
return $parser->parse( $file );
}
}
最合适的回答,由SO网友:Jami Gibbs 整理而成
这个错误表明WXR_Parser
类已“运行”或已声明。有可能是某个主题或其他插件已经合并了该类,并且在初始化之前没有检查该类是否已经存在。ie。if ( ! class_exists( \'WXR_Parser\' ) )
.
要找到冲突的来源,请逐个停用每个主题和插件。您应该只剩下一个默认主题处于活动状态(即,215)。