IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    wordpress和php7的兼容性

    tiandi发表于 2017-05-22 10:51:21
    love 0

    今天抽空将虚拟主机的PHP环境升到了7.1,之前一直用的是5.4,虚拟主机。。。寒,没错,你没听错,本博客跑在了衡天主机的虚拟主机上,并且由于避免被封杀的风险,用的是香港主机,所以速度有些慢,这么慢也慢了N年了。

    环境升级没什么好说的,后台面板一件切换到7.1即可。然后顺便将wordpress3.74升级到4.74,是的,没看错,很久没升级wordpress了。再然后打开首页,500内部错误,修改wp-config.php,开启debug模式,

    define('WP_DEBUG', false); //这里改成true;
    

    然后悲催地显示了一地的错误信息。

    1.Notice: load_plugin_textdomain was called with an argument that is deprecated since version 2.7.0 with no alternative available.

    解决方案:发现wp-recentcomment的插件调用该函数时用了个过期的参数模型,将调用函数的参数改一下即可。

    将
    load_plugin_textdomain('wp-recentcomments','/wp-content/plugins/wp-recentcomments/languages/');
    改成
    load_plugin_textdomain('wp-recentcomments', '','/wp-content/plugins/wp-recentcomments/languages/');
    

    2.Notice: 自3.4.0版本起,已不建议使用get_current_theme,请换用wp_get_theme()。

    解决方案:修改主题下所有包含get_current_theme函数的文件,改成wp_get_theme()即可。

    3.Methods with the same name as their class will not be constructors in a future version of PHP

    解决方案:找到主题下报错的相关文件,将类里的构造方法改成__construct。

    4.Notice: register_sidebar的调用方法不正确。“Home Right”侧边栏的参数数组中未设置id,缺省为“sidebar-1”

    解决方案:找到主题下相关函数,修改一下。

    //边栏定义
    if (function_exists('register_sidebar'))
    {
        register_sidebar(array(
    	'name'			=> 'Home Right',
    	'id'			=> 'sidebar-1',  //添加这行
            'before_widget'	=> '<div class="sidebox">',
            'after_widget'	=> '</div><div class="clearfix"></div><hr>',
            'before_title'	=> '<h3>',
            'after_title'	=> '</h3>',
        ));		
    
    }
    

    5.Fatal error: Uncaught Error: Call to undefined function ereg()

    解决方案:主题下相关文件找到ereg,用preg_match替代。

    可以看出,以上几个问题项目都出在插件和主题身上,和wordpress 4.74版本本身无关,即可以认为wordpress的最新版本是100%兼容php7的。

    文章评分2次,平均分5.0:★★★★★


沪ICP备19023445号-2号
友情链接