折腾:
期间,刚搬家后Wordpress网站,结果无法显示主页。去调查后发现是:
在打开了WordPress的debug:
<code>define('WP_DEBUG', true); </code>
后,看到:
<code>Notice: wp_deregister_script的调用方法不正确。脚本和样式应在wp_enqueue_scripts、admin_enqueue_scripts和login_enqueue_scripts钩子之后再加入加载队列(enqueue)或注册(register)。 请查阅调试WordPress来获取更多信息。 (这个消息是在3.3.0版本添加的。) in /xxx/wp-includes/functions.php on line 4204 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-banner.php on line 11 Notice: 在d_banner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-slidebanner.php on line 11 Notice: 在d_slidebanner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-readers.php on line 11 Notice: 在d_reader中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-postlist.php on line 11 Notice: 在d_postlist中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-comment.php on line 11 Notice: 在d_comment中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-tags.php on line 11 Notice: 在d_tag中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Notice: Undefined variable: control_ops in /xxx/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-textbanner.php on line 11 Notice: 在d_textbanner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用 __construct()。 in /xxx/wp-includes/functions.php on line 3959 Fatal error: Uncaught Error: Call to undefined function ereg_replace() in /xxx/wp-content/themes/daqianduan-d8-jquiss/header.php:71 Stack trace: #0 /xxx/wp-includes/template.php(688): require_once() #1 /xxx/wp-includes/template.php(647): load_template('/data/wwwroot/w...', true) #2 /xxx/wp-includes/general-template.php(41): locate_template(Array, true) #3 /xxx/wp-content/themes/daqianduan-d8-jquiss/index.php(1): get_header() #4 /xxx/wp-includes/template-loader.php(74): include('/data/wwwroot/w...') #5 /xxx/wp-blog-header.php(19): require_once('/data/wwwroot/w...') #6 /xxx/index.php(17): require('/data/wwwroot/w...') #7 {main} thrown in /xxx/wp-content/themes/daqianduan-d8-jquiss/header.php on line 71 </code>
WordPress Fatal error: Uncaught Error: Call to undefined function ereg_replace() in
Topic Tag: Call to undefined function ereg() | WordPress.org
php – WordPress wp-admin fatal error – Stack Overflow
Fix WordPress Fatal error: Call to undefined function – IsItWP
PHP 7.x preg_replace替换了ereg_replace,D8主题崩坏 – Slyar Home
结果此处没有搜到:
<code>[root@VM_0_11_centos www.crifan.com]# grep -nr "ereg_replace(\"<div\[^>\]\*><ul\[^>\]\*>\"" ./ ^C [root@VM_0_11_centos www.crifan.com]# ^C </code>
还是按照提示:
<code>../www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/header.php </code>
去直接修改文件算了。
想要去WordPress后台的主题中编辑对应文件的,结果:
无法正常显示了。
且同时看到了对应的其他文件的提示
所以只能暂时去关闭debug,再去修改文件
然后此处通过查询发现有7处用到了:
ereg_replace
貌似直接替换就可以了?
PHP: Differences from POSIX regex – Manual
“POSIX
PCRE
ereg_replace()
preg_replace()
ereg()
preg_match()
eregi_replace()
preg_replace()
eregi()
preg_match()
split()
preg_split()
spliti()
preg_split()
sql_regcase()
No equivalent”
去搜了另外几个,都没有用到,就ereg_replace这一个。
那直接去换吧
ereg_replace
preg_replace
然后上传到服务器上:
<code>[root@VM_0_11_centos daqianduan-d8-jquiss]# rm -f header.php [root@VM_0_11_centos daqianduan-d8-jquiss]# rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring header.php... 100% 5 KB 5 KB/sec 00:00:01 0 Errors [root@VM_0_11_centos daqianduan-d8-jquiss]# ll total 260 -rwxr-xr-x 1 www www 538 Jun 14 2017 404.php drwxr-xr-x 2 www www 4096 Jun 14 2017 admin drwxr-xr-x 2 www www 4096 Jun 14 2017 ajax -... -rwxr-xr-x 1 www www 281 Jun 14 2017 tag.php drwxr-xr-x 2 www www 4096 Jun 14 2017 widgets [root@VM_0_11_centos daqianduan-d8-jquiss]# chown www:www header.php [root@VM_0_11_centos daqianduan-d8-jquiss]# cd pages/ [root@VM_0_11_centos pages]# ll total 28 -rwxr-xr-x 1 www www 2625 Jun 14 2017 archives.php -rwxr-xr-x 1 www www 1908 Jun 14 2017 example.php -rwxr-xr-x 1 www www 1037 Jun 14 2017 links.php -rwxr-xr-x 1 www www 865 Jun 14 2017 page.php -rwxr-xr-x 1 www www 1849 Jun 14 2017 readers.php -rwxr-xr-x 1 www www 1334 Jun 14 2017 tags.php -rwxr-xr-x 1 www www 1701 Jun 14 2017 tougao.php [root@VM_0_11_centos pages]# rm -f archives.php links.php page.php readers.php tags.php tougao.php [root@VM_0_11_centos pages]# rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring archives.php... 100% 2 KB 2 KB/sec 00:00:01 0 Errors Transferring links.php... 100% 1 KB 1 KB/sec 00:00:01 0 Errors Transferring page.php... 100% 865 bytes 865 bytes/sec 00:00:01 0 Errors Transferring readers.php... 100% 1 KB 1 KB/sec 00:00:01 0 Errors Transferring tags.php... 100% 1 KB 1 KB/sec 00:00:01 0 Errors Transferring tougao.php... 100% 1 KB 1 KB/sec 00:00:01 0 Errors [root@VM_0_11_centos pages]# ll total 28 -rwxr-xr-x 1 root root 2625 Dec 30 14:52 archives.php -rwxr-xr-x 1 www www 1908 Jun 14 2017 example.php -rwxr-xr-x 1 root root 1037 Dec 30 14:52 links.php -rwxr-xr-x 1 root root 865 Dec 30 14:52 page.php -rwxr-xr-x 1 root root 1849 Dec 30 14:52 readers.php -rwxr-xr-x 1 root root 1334 Dec 30 14:52 tags.php -rwxr-xr-x 1 root root 1701 Dec 30 14:52 tougao.php [root@VM_0_11_centos pages]# chown www:www * [root@VM_0_11_centos pages]# ll total 28 -rwxr-xr-x 1 www www 2625 Dec 30 14:52 archives.php -rwxr-xr-x 1 www www 1908 Jun 14 2017 example.php -rwxr-xr-x 1 www www 1037 Dec 30 14:52 links.php -rwxr-xr-x 1 www www 865 Dec 30 14:52 page.php -rwxr-xr-x 1 www www 1849 Dec 30 14:52 readers.php -rwxr-xr-x 1 www www 1334 Dec 30 14:52 tags.php -rwxr-xr-x 1 www www 1701 Dec 30 14:52 tougao.php </code>
再重启一下php:
<code>[root@VM_0_11_centos pages]# service php-fpm restart Redirecting to /bin/systemctl restart php-fpm.service </code>
终于可以正常出主页的 部分内容了:
【总结】
WordPress的大前端的主题,对于PHP 7有些代码没有更新导致语法出错,页面无法显示。
解决办法是:
wp-content/themes/daqianduan-d8-jquiss/header.php
把:
<code>ereg_replace("<div[^>]*><ul[^>]*>" </code>
换成:
<code>preg_replace("/<div[^>]*><ul[^>]*>/" </code>
即可。
不过此处只是解决了单个文件的问题。
后续还有其他文件需要替换,详见:
转载请注明:在路上 » 【已解决】WordPress主题大前端PHP 7代码出错:Fatal error Uncaught Error Call to undefined function ereg_replace() in daqianduan-d8-jquiss header.php