Baidu Sitemap Generator 插件报错,WordPress发现了您的插件造成的错误:Baidu Sitemap Generator

升级PHP7.3之后,发现WordPress的Baidu Sitemap Generator插件在生成百度 XMLSitemap 生成器插件出现如下错误

错误详情

============

错误类别E_ERROR发生在文件www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/sitemap-function.php的439行。错误信息:Uncaught Error: Call to undefined function split() in www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/sitemap-function.php:439

Stack trace:

#0 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(278): xml_annotate()

#1 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(264): build_baidu_sitemap_xml('https...', 1)

#2 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(110): build_baidu_sitemap(1)

......

......

因为这款插件一直没有更新,PHP7版本废弃了一些PHP函数,split这个函数在PHP7版本已经不支持了,因此必须替换成PHP7版本的preg_split函数。

修复Baidu Sitemap Generator 报错需要修改2个地方

1、修改Baidu Sitemap Generator插件目录下的sitemap-function.php文件的439行和baidu_sitemap.php文件的308行
修改成

list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime );

就是用preg_split替换掉split

2、修改Baidu Sitemap Generator插件目录下的baidu_sitemap.php

function baidu_sitemap_menu() {
/** Add a page to the options section of the website **/
if (current_user_can('manage_options'))
add_options_page("Baidu-Sitemap","Baidu-Sitemap", 8, __FILE__, 'baidu_sitemap_optionpage')
}

修改成

function baidu_sitemap_menu() {
/** Add a page to the options section of the website **/
if (current_user_can('manage_options'))
add_options_page("Baidu-Sitemap","Baidu-Sitemap", 'manage_options', __FILE__, 'baidu_sitemap_optionpage');
}

就是把8换成'manage_options'
修改完成后重启PHP,即可更新百度 XMLSitemap

阅读剩余
THE END