WordPress网站报错求助:__autoload()弃用及后续报错问题
初始错误
Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /home/storage/736/3736736/user/htdocs/wp-includes/compat.php on line 502
修改操作
参考其他工单后,我将wp-includes/compat.php第502行修改为:
function spl_autoload_register( $classname ) { ... }
修改后新错误
Warning: Private methods cannot be final as they are never overridden by other classes in /home/storage/736/3736736/user/htdocs/wp-includes/class-wp-session-tokens.php on line 71
Deprecated: Required parameter $tt_id follows optional parameter $object_id in /home/storage/736/3736736/user/htdocs/wp-includes/nav-menu.php on line 931
Deprecated: Required parameter $taxonomy follows optional parameter $object_id in /home/storage/736/3736736/user/htdocs/wp-includes/nav-menu.php on line 931
Fatal error: Uncaught Error: Call to undefined function create_function() in /home/storage/736/3736736/user/htdocs/wp-content/plugins/LayerSlider/layerslider.php:69 Stack trace: #0 /home/storage/736/3736736/user/htdocs/wp-settings.php(303): include_once() #1 /home/storage/736/3736736/user/htdocs/wp-config.php(81): require_once('/home/storage/7...') #2 /home/storage/736/3736736/user/htdocs/wp-load.php(37): require_once('/home/storage/7...') #3 /home/storage/736/3736736/user/htdocs/wp-blog-header.php(13): require_once('/home/storage/7...') #4 /home/storage/736/3736736/user/htdocs/index.php(17): require('/home/storage/7...') #5 {main} thrown in /home/storage/736/3736736/user/htdocs/wp-content/plugins/LayerSlider/layerslider.php on line 69
解决方案
- 撤销对
compat.php的修改:手动定义spl_autoload_register会和WordPress原生函数冲突,这是错误的修复方式,立即恢复该文件的原始内容。 - 核心原因:PHP版本与WordPress及插件版本不兼容:
初始的__autoload()错误,是因为你使用的PHP版本(7.2+)已废弃该函数,但你的WordPress版本过老,仍在调用它;后续的警告和错误,均因老版本WordPress、LayerSlider插件不支持高版本PHP的语法规范(比如create_function()在PHP7.2被废弃,PHP8.0被彻底移除)。 - 具体修复步骤:
- 升级WordPress核心:若能访问后台,直接在后台完成升级;无法访问则通过FTP,用最新稳定版WordPress的
wp-includes和wp-admin目录覆盖现有目录(注意保留wp-content目录和wp-config.php文件)。 - 升级LayerSlider插件:
create_function()的错误来自该插件,更新至最新版本即可解决——可在后台插件页更新,或手动下载最新版插件文件覆盖wp-content/plugins/LayerSlider目录。 - 调整PHP版本:确认服务器PHP版本在WordPress官方要求范围内(当前推荐7.4~8.2),若版本不符,联系主机商调整。
- 升级WordPress核心:若能访问后台,直接在后台完成升级;无法访问则通过FTP,用最新稳定版WordPress的
内容的提问来源于stack exchange,提问作者mharkin

