用(shell)脚本替换php7中的一行代码


Replacing one line of code due to php 7 with a (shell) script

因此PHP 7.0出现了一些问题。最值得注意的是,w3totalcacheing现在导致了一个错误,该错误正在向我的httpd错误日志发送垃圾邮件。

Tue May 17 04:11:50.865647 2016] [proxy_fcgi:error] [pid 2554:tid 139695893694208] [client 195.154.181.168:59106] AH01071: Got error 'PHP message: PHP Warning:  Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /home/x/domains/x/public_html/wp-includes/functions.php on line 3464'n', referer: http://www.googlebot.com/bot.html

修复相当容易https://github.com/gadelkareem/wp-w3-total-cache/commit/e71030e89f4cd666742ae2ec39451782beb42f3a,但我必须为大约12个站点这样做。并且可能在插件更新时再次出现。

文件总是在这里(*是可变用户和域相关文件夹):

/home/*/domains/*/public_html/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php 

有没有一种方法可以让我安全地编写这个脚本?

在github上,用户pratham2003遇到了与您相同的问题,并提出了以下sed命令来应用补丁:

sed -i.bak 's/function ob_callback(&/function ob_callback(/g' /path/to/public_html/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php

可以跳过-i.bak选项以防止创建备份文件。

然后,您可以在本地应用补丁,并编写一个脚本来更新每个服务器上的文件,或者在每个服务器上更新ssh,并在每个服务器中应用sed命令。

你也可以维护一个分叉的插件并从这个插件安装。

但最好的办法是上游维护人员自己进行修改。